我是 Spring Security 的新手,并且有一个已部署在 Tomcat 服务器中的第三方 War 文件。对应用程序的访问由 spring-security.xml 控制。
<beans:beans profile="some.profile">
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="admin" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
我想更改我在上述设置中所做的默认密码。但我还想加密这个 xml 中的密码,这样它就不会以纯文本形式存储。我用谷歌搜索了这个问题,但没有得到任何与这个问题匹配的答案。而且我不想坚持在数据库中,因为这只是一次。
最佳答案
可以通过添加额外参数“password-encoder”来使用密码哈希。有一些在线密码哈希计算器,可用于检索哈希字符串(md5、bcrypt 或不同的编码方法)md5 加密的配置示例:
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="b91cd1a54781790beaa2baf741fa6789" authorities="ROLE_USER" />
</user-service>
<password-encoder ref="passwordEncoder" />
</authentication-provider>
</authentication-manager>
<beans:bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/>
关于java - spring-security.xml 中的密码更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45816441/