【发布时间】:2015-12-01 16:44:36
【问题描述】:
我正在编写带有基本身份验证的其余应用程序。它工作正常,但每次重新启动后都会生成新的用户密码。 我的 Security-context.xml 是
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<security:http auto-config='true'>
<security:intercept-url pattern="/api/**" access="ROLE_USER"/>
<security:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<security:http-basic />
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="user" password="password1" authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
</beans>
为什么不用password="password1"?
【问题讨论】:
-
您能解释一下“它会生成新的用户密码”是什么意思吗?你在哪里看到这个?另外,请在提交身份验证请求时发布调试日志。
-
在控制台中,当我的应用启动类似“使用默认安全密码:c80fe464-e7e8-4t1e-8cea-123f26d702c3”时
-
如果您搜索“使用默认安全密码”这个短语,它似乎是某种创建默认“用户”的 Sprint Boot 功能。与它相关的各种问题on github。确保您使用的是最新版本的所有内容,并尝试使用不会与默认用户名冲突的其他用户名。
-
@LukeTaylor 检查并尝试过,没有任何帮助(((((
-
Spring Boot 默认使用生成的密码创建默认用户。基本上你的 xml 什么都不做,可以(或应该)被删除。如果您想自己指定用户,请按照 Spring Boot 参考指南中的说明配置 Spring Security。
标签: java spring spring-security spring-boot