Spring Security 启用后,访问所有页面显示 Please sign in

文章目录

    在新建 Spring Boot 项目时,好奇地勾选了 Spring-Security。
    然后导致访问所有页面都显示一个登陆界面 “Please sign in”。

    查了一下 spring 的文档,确实如此:

    If Spring Security is on the classpath, Spring Boot automatically secures all HTTP endpoints with“basic” authentication.

    默认所有页面都需要授权。

    默认的用户名密码是什么

    默认用户名是:user

    密码是 spring 自动生成的,在 console 输出中可以找到:

    Using generated security password: 110117de-0497-44a3-beed-fb80fc562564

    每次重启 Spring Boot 服务,这个密码都会变化。

    设置指定的用户名和密码

    见参考链接。

    去掉登陆页面的方法

    删除 pom.xml 中的 Spring-Security 设置:

    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    

    是否能设置指定页面需要登陆后才能查看

    我的真实需求是部分页面需要登陆查看,其他页面不需要登陆。

    如何配置呢?

    参考:https://spring.io/guides/gs/securing-web/

    参考

    https://spring.io/guides/gs/securing-web/

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式