Spring mvc Spring Security Active Directory错误凭据处理(错误49)

Spring mvc Spring Security Active Directory错误凭据处理(错误49),spring-mvc,authentication,spring-security,active-directory,wildfly-8,Spring Mvc,Authentication,Spring Security,Active Directory,Wildfly 8,我在简单的SpringWeb应用程序中遇到了Active Directory身份验证问题。我使用的是ActiveDirectoryLdapAuthenticationProvider,对于空的登录字段和正确的凭据,它似乎可以正常工作。问题在于凭据无效(错误登录/通过或两者都有)。应用程序向浏览器抛出异常(错误500): Error processing request Context Path: /MYAPPNAME Servlet Path: /login_check Path Info: n

我在简单的SpringWeb应用程序中遇到了Active Directory身份验证问题。我使用的是
ActiveDirectoryLdapAuthenticationProvider
,对于空的登录字段和正确的凭据,它似乎可以正常工作。问题在于凭据无效(错误登录/通过或两者都有)。应用程序向浏览器抛出异常(错误500):

Error processing request
Context Path: /MYAPPNAME
Servlet Path: /login_check
Path Info: null
Query String: null
Stack Trace:
org.springframework.ldap.UncategorizedLdapException: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory com.sun.jndi.ldap.LdapCtxFactory from classloader ModuleClassLoader for Module "deployment.MYAPPNAME.war:main" from Service Module Loader [Root exception is javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece]] (...)
控制台根错误为:

javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308:
LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece]
如果凭据不正确,Spring不应该将用户发送到身份验证失败url吗?我没有任何用于ldap绑定的“manager”帐户,我相信
ActiveDirectoryLdapAuthenticationProvider
应该使用登录表单中的凭据进行绑定。Spring文档没有任何关于绑定到AD的内容

也许可以使用自定义身份验证提供程序来解决这个问题,但我希望有一个现成的解决方案。有一些类似的问题,但没有一个非常精确,也没有任何有用的答案

如何处理这个错误

有没有办法用XML来配置它?也许,要告诉广告提供商将绑定错误处理为失败的登录尝试

自定义身份验证提供程序是唯一的解决方案吗


spring security.xml

<bean id="roleVoter" class="org.springframework.security.access.vote.RoleVoter">
    <property name="rolePrefix" value="" />
</bean> 
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
    <constructor-arg name="decisionVoters" ref="roleVoter" />
</bean>
<s:http authentication-manager-ref="ldap-auth" access-decision-manager-ref="accessDecisionManager" use-expressions="false">
    <s:intercept-url pattern="/list**" access="ADGROUP-XYZ" />
    <s:form-login 
        login-page="/login"             
        login-processing-url="/login_check"
        username-parameter="username" 
        password-parameter="password"     
        default-target-url="/list"
        authentication-failure-url="/login?fail" />
    <s:logout 
        invalidate-session="true" 
        logout-success-url="/login?logout" 
        logout-url="/logout"
        delete-cookies="JSESSIONID" />
    <s:csrf />
</s:http>    

<s:authentication-manager id="ldap-auth">
    <s:authentication-provider ref="adAuthenticationProvider" />
</s:authentication-manager> 

<bean id="adAuthenticationProvider" class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
    <constructor-arg value="company.local" />
    <constructor-arg value="ldap://server.company.local:389/" />
    <property name="useAuthenticationRequestCredentials" value="true"/>
    <property name="convertSubErrorCodesToExceptions" value="true"/>
</bean>



编辑:一个丑陋的修复方法是覆盖
ActiveDirectoryLdapAuthenticationProvider
并更改
抛出LdapUtils.convertLdapException(e)
抛出错误凭证(e)

JBoss EAP初始上下文存在问题。这已在最新的wildfly版本中修复。请查看以下链接


您可以尝试url中给出的示例代码来解决此问题