如何在spring security中避免使用纯文本LDAP密码?

时间:2015-11-27 07:27:07

标签: spring-security ldap spring-security-ldap

我刚刚设法得到我的OpenLDAP + Spring Security工作,一切正常,除了一个小问题,在spring security xml中,我必须在那里输入纯文本密码:

<beans:bean id="ldapContextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <beans:constructor-arg value="ldap://153.65.x.y:389/dc=example,dc=com" />
    <beans:property name="userDn" value="cn=Manager,dc=example,dc=com" />
    <beans:property name="password" value="secret" />
</beans:bean> 

有什么方法可以避免这种情况吗?

当我设置OpenLDAP时,我实际上可以在 slapd.conf 中添加摘要而不是纯文本密码:

rootpw {SSHA}ZMFfVNPAazmLcif1xC2l9y9SFdKd+x4

所以我希望Spring安全可以做类似的事情。

修改

我刚才意识到在这里放置LDAP管理员名称和密码是不必要的,只需提供uri就可以了,春天的安全性就足够了:

<beans:bean id="ldapContextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <beans:constructor-arg value="ldap://153.65.x.y:389/dc=example,dc=com" />
</beans:bean> 

我在这里有一些误解。 当我尝试编写这个示例时,我从google获得的一些示例将管理器名称和密码放在spring security xml中。 所以我曾经认为这就像通过JDBC连接到数据库,我们必须提供数据库用户名和密码。事实并非如此,不需要管理员名称和密码。

1 个答案:

答案 0 :(得分:0)

您能够将rootpw作为SSHA存储在LDAP服务器上的原因是因为它不需要知道您的原始密码以进行验证 - 摘要(在这种情况下为SSHA - 盐渍安全散列)就足够了。但是,客户端需要发送原始密码,以便服务器可以计算哈希并将其与存储的哈希进行比较。

充其量,spring可以为客户端上的密码存储提供某种加密,但我对此并不熟悉。

编辑:StackOverflow Encrypting a password within a Spring configuration file指向此链接:http://www.jasypt.org/spring3.html

相关问题