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

时间:2015-09-08 15:54:47

标签: spring-mvc authentication spring-security active-directory wildfly-8

我在简单的Spring Web应用程序中遇到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不应该将用户发送到authentication-failure-url吗?我没有任何“经理”帐户用于ldap BIND,我相信ActiveDirectoryLdapAuthenticationProvider应该使用登录表单中的凭据进行绑定。 Spring文档没有关于绑定到AD的任何内容。

它可以使用自定义身份验证提供程序解决,但我希望有一个开箱即用的解决方案。有一些类似的问题,但没有一个非常精确或有任何有用的答案。

如何处理此错误?

有没有办法在XML中配置它?也许,告诉AD提供商将绑定错误视为失败的登录尝试?

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

弹簧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并将throw LdapUtils.convertLdapException(e);更改为throw badCredentials(e);

1 个答案:

答案 0 :(得分:1)

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

https://jira.spring.io/browse/SEC-2754

https://issues.jboss.org/browse/WFLY-4149