我在簡單的Spring Web應用程序中的Active Directory身份驗證有問題。我使用的是ActiveDirectoryLdapAuthenticationProvider
,它似乎適用於空登錄字段和正確的憑據。問題是憑證無效(錯誤的登錄/密碼或兩者)。該應用程序將引發異常(錯誤500)到瀏覽器:春季安全Active Directory錯誤憑據處理(錯誤49)
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]
如果憑據是不正確的,應該不是春發送用戶認證故障 - 網址是什麼?我沒有任何「經理」帳戶用於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>
EDIT:一張難看的修復是重寫ActiveDirectoryLdapAuthenticationProvider
和更改throw LdapUtils.convertLdapException(e);
到throw badCredentials(e);
。
你可以嘗試在給定的示例代碼url https://jira.spring.io/browse/SEC-2754來解決這個問題 – Sampathkumar