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