Java 如何在调用LDAP之前设置Spring Security MD5密码
我正在从事一个使用Spring和Spring Security与LDAP的项目。在我们MD5用户密码之前,我让我的项目很好地使用LDAP。既然我们MD5了用户密码,我正试图在SpringXML中找到一种方法,在检查LDAP之前将密码告诉Spring到MD5 下面是我的XMLJava 如何在调用LDAP之前设置Spring Security MD5密码,java,spring,ldap,spring-security,md5,Java,Spring,Ldap,Spring Security,Md5,我正在从事一个使用Spring和Spring Security与LDAP的项目。在我们MD5用户密码之前,我让我的项目很好地使用LDAP。既然我们MD5了用户密码,我正试图在SpringXML中找到一种方法,在检查LDAP之前将密码告诉Spring到MD5 下面是我的XML <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/secur
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<http auto-config="true" use-expressions='true'>
<intercept-url pattern="/friends/**" access="isAuthenticated()" />
<intercept-url pattern="/articles/**" access="isAuthenticated()" />
</http>
<authentication-manager>
<ldap-authentication-provider
user-search-filter="(uid={0})" user-search-base="ou=sampleusers" />
</authentication-manager>
<beans:bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg value="ldap://localhost:389/dc=xxxwf,dc=org" />
<beans:property name="userDn" value="cn=admin,dc=xxxwf,dc=org" />
<beans:property name="password" value="sabrina123" />
</beans:bean>
<beans:bean id="ldapAuthProvider"
class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
<beans:constructor-arg>
<beans:bean
class="org.springframework.security.ldap.authentication.BindAuthenticator">
<beans:constructor-arg ref="contextSource" />
<beans:property name="userDnPatterns">
<beans:list>
<beans:value>uid={0},ou=sampleusers</beans:value>
</beans:list>
</beans:property>
</beans:constructor-arg>
</beans:bean>
<ldap-server url="ldap://127.0.0.1:389/dc=xxxwf,dc=org" />
<beans:bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="location" value="classpath:jdbc.properties" />
</beans:bean>
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<beans:property name="driverClassName" value="${database.driver}" />
<beans:property name="url" value="${database.url}" />
<beans:property name="username" value="${database.user}" />
<beans:property name="password" value="${database.password}" />
<beans:property name="initialSize" value="5" />
<beans:property name="maxActive" value="10" />
</beans:bean>
</beans:beans>
uid={0},ou=sampleusers
试试这个:
<security:authentication-manager>
<security:ldap-authentication-provider>
<security:password-compare>
<security:password-encoder ref="passwordEncoder">
</security:password-encoder>
</security:password-compare>
</security:ldap-authentication-provider>
</security:authentication-manager>
<bean id="passwordEncoder"
class="org.springframework.security.authentication.encoding.Md5PasswordEncoder">
</bean>
我没有尝试过LDAP。但它对“普通”(而非LDAP)身份验证提供程序起到了防御作用。尝试以下方法:
<security:authentication-manager>
<security:ldap-authentication-provider>
<security:password-compare>
<security:password-encoder ref="passwordEncoder">
</security:password-encoder>
</security:password-compare>
</security:ldap-authentication-provider>
</security:authentication-manager>
<bean id="passwordEncoder"
class="org.springframework.security.authentication.encoding.Md5PasswordEncoder">
</bean>
我没有尝试过LDAP。但它对“普通”(而非LDAP)身份验证提供程序有效。密码应通过安全连接以明文形式发送,不应使用摘要进行预编码或以任何方式进行预编码-预编码的密码会阻止目录服务器执行密码质量检查。目录服务器加密或散列明文密码,并将密码与目标条目中加密/散列的密码进行比较,并在绑定响应中返回成功或失败。应通过安全连接以明文形式发送密码,它们不应使用摘要预编码或以任何方式预编码-预编码密码会阻止目录服务器执行密码质量检查。目录服务器加密或散列明文密码,并将密码与目标条目中加密/散列的密码进行比较,并在绑定响应中返回成功或失败。Terry的答案是正确的,如果您使用的是绑定身份验证,Spr Sec LDAP客户端正试图使用提供的用户名和明文密码绑定到LDAP(顺便说一句,这就是为什么在使用绑定身份验证时总是建议使用SLDAP) 如果使用密码比较身份验证,则必须对用于比较的密码进行哈希或编码,以便与LDAP存储库中存储的密码完全匹配 因为看起来您使用的是绑定身份验证,所以您应该可以按照当前的情况进行操作
这些概念在。Terry的回答是正确的,如果您使用绑定身份验证,Spr Sec LDAP客户端将尝试使用提供的用户名和明文密码绑定到LDAP(顺便说一句,这就是为什么在使用绑定身份验证时总是建议使用SLDAP) 如果使用密码比较身份验证,则必须对用于比较的密码进行哈希或编码,以便与LDAP存储库中存储的密码完全匹配 因为看起来您使用的是绑定身份验证,所以您应该可以按照当前的情况进行操作 这些概念在本手册中有很好的介绍