2

我刚刚设法让我的 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 security可以做类似的事情。


编辑:

我刚刚意识到没有必要在此处输入 LDAP 管理器名称和密码,只需提供 uri 就足以让 spring security 工作:

<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 连接数据库一样,我们必须提供数据库用户名和密码。这不是真的,不需要管理员名称和密码。

4

1 回答 1

0

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

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

编辑: StackOverflow在 Spring 配置文件中加密密码链接到此:http ://www.jasypt.org/spring3.html

于 2015-11-27T07:42:54.810 回答