2014-04-25 7 views
16

का उपयोग कर सक्रिय निर्देशिका प्रमाणीकरण मैं एक वेब एप्लिकेशन लिख रहा हूं जिसके लिए उपयोगकर्ताओं को लॉगिन करने की आवश्यकता है। मेरी कंपनी के पास एक सक्रिय निर्देशिका सर्वर है जिसे मैं इस उद्देश्य के लिए उपयोग करना चाहता हूं। हालांकि, मुझे उपयोगकर्ताओं के प्रमाण-पत्र प्रमाणित करने के लिए वसंत का उपयोग करने में समस्या हो रही है।स्प्रिंग सुरक्षा 3.2, स्प्रिंग Ldap 2.0 और JavaConfig

मैं वसंत सुरक्षा 3.2.2, स्प्रिंग एलडीएपी 2.0.1 और जावा 1.7 का उपयोग कर रहा हूं।

वेब एप्लिकेशन अच्छी तरह से शुरू होता है, इनमेमरी-प्रमाणीकरण के खिलाफ प्रमाणीकरण अच्छी तरह से काम करता है, इसलिए मेरा शेष एप्लिकेशन सही तरीके से कॉन्फ़िगर किया गया प्रतीत होता है।

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 

जब मैं ई एक का उपयोग कर ब्राउज़: जब मैं MY_USERNAME और MY_PASSWORD का उपयोग कर लॉगिन करने के लिए मैं एक Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials

पूर्ण स्टैकट्रेस पाने की कोशिश

@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 और (&(objectClass=user)(userPrincipalName=MY_USERNAME)) के लिए खोजें, जो स्प्रिंग ActiveDirectoryLdapAuthenticationProvider में करता है: searchForUser (...), यह सही देता है उपयोगकर्ता।

एक अवैध पासवर्ड दर्ज करते समय, वसंत ActiveDirectoryLdapAuthenticationProvider:200 - Active Directory authentication failed: Supplied password was invalid देता है। यह ठीक लगता है।

कॉन्फ़िगरेशन के लिए कोई हिस्सा अनुपलब्ध है?

जावाकॉन्फिग का उपयोग कर एडी के लिए स्प्रिंग एलडीएपी को कॉन्फ़िगर करने के तरीके के कोई कामकाजी उदाहरण हैं? आधिकारिक स्प्रिंग गाइड सिर्फ एक्सएमएल-वे का वर्णन करता है http://docs.spring.io/spring-security/site/docs/3.1.5.RELEASE/reference/ldap.html#ldap-active-directory

अद्यतन: बस अद्यतन निम्नलिखित के लिए मेरे 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; 
} 

यह ठीक काम करता है, धन्यवाद गुइडो!

नोट: वसंत राज्यों, कि एक PartialResultException अनदेखा किया जाता है। डॉक्स कहते हैं

कुछ सक्रिय निर्देशिका (एडी) सर्वर स्वचालित रूप से रेफ़रल का पालन करने में असमर्थ हैं, जो अक्सर खोज में फेंकने वाले आंशिक रेसल्ट अपवाद की ओर जाता है। आप निर्दिष्ट कर सकते हैं कि UndialPartialResultException गुण को सत्य पर सेट करके PartialResultException को अनदेखा किया जाना है।

शायद इस संपत्ति को JavaConfig को सेट करने का एक तरीका भी है। मैंने बस इसे नजरअंदाज कर दिया।

+2

आप 'OU = A_GROUP, डीसी = डोमेन, डीसी = अपने कनेक्शन यूआरएल से tld' आधार निकालने का प्रयास कर सकते हैं? ऐसा लगता है कि एडी वसंत प्रदाता का प्रबंधन आंतरिक रूप से –

+0

ने इस भाग को हटाने की कोशिश की और यह थोड़े काम करता है। कंसोल एक 'अनदेखा PartialResultException' और HTTP 403 त्रुटि लॉग करता है। – user3572914

+0

लॉगिन-नाम 'sAMAccountName' का मान है।क्या यह भी एक समस्या हो सकती है? – user3572914

उत्तर

1
  1. PartialResultException के लिए आपको पैरामीटर रेफ़रल को अपने संदर्भ स्रोत पर "अनुसरण करें" पर सेट करना चाहिए।

उदाहरण के लिए: https://stackoverflow.com/a/26872236/2718510

संबंधित मुद्दे