我正在使用
Spring Boot
并且正在使用 spring-data-rest-hal-browser
,一切似乎都很好,除了当我尝试点击 URL 时: http://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>
这是登录屏幕:
运行应用程序后查看控制台输出。如果没有运行时异常,那么您应该可以轻松找到凭据。默认情况下,用户名是
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>
默认用户名是
user
运行应用程序时可以在控制台中找到密码。
示例:
Using generated security password: 18ea5687-bc63-4663-9377-e2817c9d2568
如果您想自己设置它们,您可以通过覆盖
application.properties
中的默认值来实现:
spring.security.user.name=stack
spring.security.user.password=overflow