Spring Security LDAP绑定验证器只验证密码的前8个字符

Spring Security LDAP绑定验证器只验证密码的前8个字符,security,spring,ldap,bind,authenticator,Security,Spring,Ldap,Bind,Authenticator,我的web应用程序使用Spring Security进行身份验证和授权。 身份验证通过公司SSO进行预身份验证。但是,作为备用方案,应用程序使用基于表单的登录进行身份验证。这也是使用Spring安全性通过在部署描述符中配置身份验证提供者列表来实现的。考虑一个典型的场景,如序列描述如下: 如果公司SSO预认证失败,则会向用户显示登录页面 将提交输入的凭据,并且由于SSOPreAuthentication提供程序找不到主体(假设SSO失败),因此请求将转发到下一个身份验证提供程序,即LdapAuth

我的web应用程序使用Spring Security进行身份验证和授权。 身份验证通过公司SSO进行预身份验证。但是,作为备用方案,应用程序使用基于表单的登录进行身份验证。这也是使用Spring安全性通过在部署描述符中配置身份验证提供者列表来实现的。考虑一个典型的场景,如序列描述如下:

  • 如果公司SSO预认证失败,则会向用户显示登录页面
  • 将提交输入的凭据,并且由于SSOPreAuthentication提供程序找不到主体(假设SSO失败),因此请求将转发到下一个身份验证提供程序,即LdapAuthenticationProvider
  • 在这里,我偶然遇到的是,使用BindAuthenticator的LdapAuthenticationProvider将用户名绑定到LDAP,即使密码部分正确(仅匹配密码的前8个字符,其余字符将被忽略)

    以下是我的部署描述符中与讨论相关的配置

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- DO NOT EDIT FILE GENERATED BY BUILD SCRIPT (edit the config template version) -->
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:security="http://www.springframework.org/schema/security"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/security
            http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"><security:http auto-config="false" access-denied-page="/accessDenied.htm" access-decision-manager-ref="accessDecisionManager">
        <security:form-login login-page="/login.htm" authentication-failure-url="/login.htm?error=true" />
        <security:logout logout-success-url="/login.htm" />
        <security:intercept-url pattern="/**/*" access="ROLE_DENIED" />
    </security:http>
    
    <bean id="preauthSSOFilter" class="MySSOProcessingFilter">
        <security:custom-filter position="PRE_AUTH_FILTER" />
        <property name="principalRequestHeader" value="XX1" />
        <property name="credentialsRequestHeader" value="XX2" />
        <property name="ldapUserIdRequestHeader" value="XX3" />
        <property name="ldapDNRequestHeader" value="XX4" />
        <property name="ldapAuthenticator" ref="ldapBindAuthenticator" />
        <property name="anonymousUserIfPrincipalRequestHeaderMissing" value="[none]" />
        <property name="authenticationManager" ref="authenticationManager" />
    </bean>
    
    <bean id="ldapContextValidator" class="org.springframework.ldap.pool.validation.DefaultDirContextValidator" />
    
    <bean id="ldapContextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <constructor-arg value="ldap://myLDAP.com:983/o=something.com"/>
    </bean>
    
    <bean id="ldapAuthenticationProvider" class="org.springframework.security.providers.ldap.LdapAuthenticationProvider">
        <security:custom-authentication-provider />
        <constructor-arg ref="ldapBindAuthenticator" />
        <constructor-arg ref="ldapAuthoritiesPopulator" />
    </bean>
    
    <bean id="ldapBindAuthenticator" class="org.springframework.security.providers.ldap.authenticator.BindAuthenticator">
        <constructor-arg ref="ldapContextSource"/>
        <property name="userSearch" ref="ldapUserSearch" />
    </bean>
    
    
    <bean id="ldapUserSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
        <constructor-arg index="0" value=""/>
        <constructor-arg index="1" value="(uid={0})"/>
        <constructor-arg index="2" ref="ldapContextSource" />
    </bean>
    
    <bean id="ldapAuthoritiesPopulator" class="org.springframework.security.ldap.populator.UserDetailsServiceLdapAuthoritiesPopulator">
        <constructor-arg ref="userDetailsService" />
    </bean>
    
    
    
    下面是两个场景的日志跟踪:

  • 密码完全错误时(所有字符错误)
  • 18:34:13599调试[FilterChainProxy]/j_spring_安全检查 附加过滤器链中的位置4/8;点火过滤器: 'org.springframework.security.ui.webapp.AuthenticationProcessingFilter[ order=700;]'18:34:13599调试[AuthenticationProcessingFilter] 请求处理身份验证18:34:13599调试 [ProviderManager]身份验证尝试使用 org.springframework.security.providers.ldap.ldapaauthenticationprovider 18:34:13599调试[FilterbasedapUserSearch]搜索用户 “@username@”,带有用户搜索[searchFilter:”(uid={0}), searchBase:'',作用域:子树,searchTimeLimit:0,derefLinkFlag: false]18:34:13599调试[AbstractContextSource]主体:“” 18:34:13943调试[AbstractContextSource]在服务器上获取了Ldap上下文 'ldap://myLDAP.com:983/o=something.com'18:34:14130调试 [DefaultSpringSecurityContextSource]正在使用主体创建上下文: 'uid=@username@,ou=people,l=AP,o=somthing.com'18:34:14458 [BindAuthenticator]无法绑定为uid=@username@,ou=people,l=AP: org.springframework.ldap.AuthenticationException:[ldap:错误代码49 -无效凭证];嵌套异常为javax.naming.AuthenticationException:[LDAP:错误代码49-无效 全权证书]

  • 密码正确或部分正确(仅前8个字符匹配)时
  • 18:30:11849调试[FilterChainProxy]/j_spring_安全检查 附加过滤器链中的位置4/8;点火过滤器: 'org.springframework.security.ui.webapp.AuthenticationProcessingFilter[ order=700;]'18:30:11849调试[AuthenticationProcessingFilter] 请求处理身份验证18:30:11849调试 [ProviderManager]身份验证尝试使用 org.springframework.security.providers.ldap.ldapaauthenticationprovider 18:30:11849调试[FilterbasedapUserSearch]搜索用户 “@username@”,带有用户搜索[searchFilter:”(uid={0}), searchBase:'',作用域:子树,searchTimeLimit:0,derefLinkFlag: false]18:30:11849调试[AbstractContextSource]主体:“” 18:30:12193调试[AbstractContextSource]在服务器上获取Ldap上下文 'ldap://myLDAP.com:983/o=something.com'18:30:12365调试 [DefaultSpringSecurityContextSource]正在使用主体创建上下文: 'uid=@username@,ou=people,l=AP,o=something.com'18:30:12708调试 [AbstractContextSource]已在服务器上获取Ldap上下文 'ldap://myLDAP.com:983/o=something.com"


    有人能解释这个神秘的行为吗?

    假设LDAP是进行身份验证的人,而Spring Security只是一个passthrough,您是否确认LDAP会在前8个字符后拒绝不正确的密码?这是一个用于身份验证的公司级LDAP,在整个公司使用了我的大量应用程序。虽然我还没有明确确认它的行为(对于8个字符后的密码不正确),但我认为LDAP没有问题。