【问题标题】:What are Spring Security default credentials for Spring Boot?Spring Boot 的 Spring Security 默认凭据是什么?
【发布时间】:2020-02-01 05:47:20
【问题描述】:

我正在使用 Spring Boot,并且正在使用 spring-data-rest-hal-browser,一切似乎都很好,除非我尝试点击 URL:localhost:8080 我被重定向到 http://localhost:8080/login 使用HAL 浏览器导航我的端点,然后我得到一个屏幕,要求输入我没有的用户和密码。

登录 Spring Security 的默认凭据是什么?如何更改它们或禁用登录选项?

这是我正在使用的依赖项:

<dependency>
 <groupId>org.springframework.data</groupId>
 <artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>

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

这是登录屏幕:

【问题讨论】:

    标签: java spring spring-boot hateoas


    【解决方案1】:

    运行应用程序后查看控制台输出。如果您没有运行时异常,那么您应该很容易找到凭据。默认情况下,用户名是“user”,密码总是不同的,因此是系统生成的。

    为了更清楚,登录页面带有这个依赖:

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

    另外,如果您想为凭据设置一些值,请转到 application.properties 文件并添加这两行:

    spring.security.user.name= your_username
    spring.security.user.password= your_password
    

    【讨论】:

    • 这解决了我的问题。感谢您澄清登录页面带有 spring 安全依赖项这一事实,并指出设置我自己的凭据的方法,以避免每次我重新启动我的项目时都有新的凭据。非常感谢。
    猜你喜欢
    • 2016-08-14
    • 1970-01-01
    • 2015-12-27
    • 2016-06-06
    • 2020-10-16
    • 1970-01-01
    • 2020-04-14
    • 2016-05-13
    • 2018-09-21
    相关资源
    最近更新 更多