사용자가 로그인해야하는 웹 응용 프로그램을 작성하고 있습니다. 우리 회사에는이 용도로 사용할 Active Directory 서버가 있습니다. 그러나 사용자 자격 증명을 인증하는 데 Spring을 사용하는 데 문제가 있습니다.Spring Security 3.2, Spring Ldap 2.0 및 JavaConfig를 사용하는 Active Directory 인증
저는 Spring Security 3.2.2, Spring Ldap 2.0.1 및 Java 1.7을 사용하고 있습니다.
웹 응용 프로그램이 잘 시작되고 InMemory-Authentication에 대한 인증도 잘 작동하므로 나머지 응용 프로그램이 올바르게 구성되어있는 것처럼 보입니다.
14:59:00,508 DEBUG UsernamePasswordAuthenticationFilter:205 - Request is to process authentication
14:59:00,509 DEBUG ProviderManager:152 - Authentication attempt using org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider
14:59:00,509 DEBUG ActiveDirectoryLdapAuthenticationProvider:65 - Processing authentication request for user: USERNAME
14:59:00,563 ERROR ActiveDirectoryLdapAuthenticationProvider:133 - Failed to locate directory entry for authenticated user: USERNAME
javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-0310020A, problem 2001 (NO_OBJECT), data 0, best match of:
'OU=A_GROUP,DC=domain,DC=tld'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.searchAux(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_search(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
at javax.naming.directory.InitialDirContext.search(Unknown Source)
at org.springframework.security.ldap.SpringSecurityLdapTemplate.searchForSingleEntryInternal(SpringSecurityLdapTemplate.java:208)
at org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider.searchForUser(ActiveDirectoryLdapAuthenticationProvider.java:285)
at org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider.doAuthentication(ActiveDirectoryLdapAuthenticationProvider.java:130)
at org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider.authenticate(AbstractLdapAuthenticationProvider.java:80)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:177)
at org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:94)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:211)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
... a few more
14:59:00,597 WARN LoggerListener:60 - Authentication event AuthenticationFailureBadCredentialsEvent: USERNAME; details: org.sprin[email protected]0: RemoteIpAddUSERNAME: 0:0:0:0:0:0:0:1; SessionId: 1E9401031886F0155F0ACE881CC50A4B; exception: Bad credentials
14:59:00,597 DEBUG UsernamePasswordAuthenticationFilter:348 - Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials
14:59:00,597 DEBUG UsernamePasswordAuthenticationFilter:349 - Updated SecurityContextHolder to contain null Authentication
14:59:00,597 DEBUG UsernamePasswordAuthenticationFilter:350 - Delegating to authentication failure handler org.springframework.se[email protected]3d876453
나는를 사용하여 AD를 탐색 할 때 : 나는이 Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials
전체 스택 트레이스 얻을 MY_USERNAME 및 my_password 관련을 사용하여 로그인 할 때
@Configuration
@EnableWebSecurity
public class LdapConfig extends WebSecurityConfigurerAdapter {
@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
val provider = new ActiveDirectoryLdapAuthenticationProvider("my.domain", "ldap://LDAP_ID:389/OU=A_GROUP,DC=domain,DC=tld");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
@Bean
public LoggerListener loggerListener() {
return new LoggerListener();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// Configuration for Redirects, Login-Page and stuff
}
}
: 여기
내 구성이다 Ldap-Explorer에서 ActiveDirectoryLdapAuthenticationProvider : searchForUser (...)에서 Spring이 수행하는(&(objectClass=user)(userPrincipalName=MY_USERNAME))
을 검색하면 올바른 사용자.
잘못된 암호를 입력하면 Spring은 ActiveDirectoryLdapAuthenticationProvider:200 - Active Directory authentication failed: Supplied password was invalid
을 반환합니다. 이것은 괜찮은 것 같습니다.
구성에 해당하지 않는 부분이 있습니까?
JavaConfig를 사용하여 AD 용 Spring Ldap을 구성하는 방법에 대한 작동 예제가 있습니까? 그냥 업데이트를 다음 내 AuthenticationProvider에이 : 그것은 잘 작동
@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
val provider = new ActiveDirectoryLdapAuthenticationProvider("company.tld", "ldap://LDAP_URL:389");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
provider.setAuthoritiesMapper(myAuthoritiesMapper()); // see http://comdynamics.net/blog/544/spring-security-3-integration-with-active-directory-ldap/
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
, 덕분에 귀도 공식 봄 가이드는 단지 XML-방법을 http://docs.spring.io/spring-security/site/docs/3.1.5.RELEASE/reference/ldap.html#ldap-active-directory
업데이트를 설명합니다!
주 : Spring은 PartialResultException이 무시된다는 것을 나타냅니다. 문서 설명
일부 Active Directory (AD) 서버는 조회를 자동으로 수행 할 수 없으므로 종종 검색에서 PartialResultException이 발생합니다. ignorePartialResultException 특성을 true로 설정하여 PartialResultException을 무시하도록 지정할 수 있습니다.
JavaConfig와이 속성을 설정하는 방법이있을 수 있습니다. 나는 그것을 무시했다.
당신은'OU = A_GROUP, DC = 도메인, DC = 당신의 연결 URL에서 tld' 기반을 제거하려고 할 수 있습니까? 그것은 광고 스프링 공급자가 내부적으로 관리하는 것 같습니다 –
그냥이 부분을 제거하려고 노력하고 그것은 다소 작동합니다. 콘솔에 'PartialResultException 무시'및 HTTP 403 오류가 기록됩니다. – user3572914
login-name은'sAMAccountName'의 값입니다.이것도 문제가 될 수 있습니까? – user3572914