2012-09-19 79 views
0

我试图将一个web项目转换为Spring。 我已经合并了Spring Security,但是旧项目使用SHA-1转换为十六进制字符串来加密用户密码。如何为Spring Security添加自定义密码编码器?

我想知道如何才能制作自定义密码编码器,这将允许我指定我想要如何密码加密。

回答

1

当然,你也许并不需要一个自定义的编码器,因为它使用安全的命名空间配置<password-encoder>是很容易的:

<password-encoder hash="sha" base64="true" /> 

把这一行到您的安全context.xml中,它会使用ShaPasswordEncoder与启用了SHA-1算法和BASE64编码。

+0

谢谢。在我的authentication-manager标签中,我有''。我有bean '。但我不断收到一个错误,说它找不到'org.springframework.security.encoding.ShaPasswordEncoder' – Takkun

+1

你使用的是什么版本的Spring Security? – Xaerxess

+0

spring-security-3.1 – Takkun

2

你可以直接使用这个。 构造函数的参数是SHA的强度编码器

<beans:bean id="passwordEncoder" 
    class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"> 
    <beans:constructor-arg index="0" value="1" /> 
</beans:bean> 
相关问题