title: Do we need to write CustomActiveDirectoryLdapAuthenticationProvider if we want to get user details from ActiveDirectory
body: <p>If we need to get User attributes from ActiveDirectory like name, sn etc. can't we configure using Specialized LDAP authentication provider which uses Active Directory configuration conventions like "springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider"  </p>
  
  <pre><code> @Override
      protected void configure(HttpSecurity http) throws Exception {
  
              http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                          .authorizeRequests().antMatchers("/", "logout").permitAll().and().httpBasic();
      }
  
  
       @Override
          protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
  
              auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
          }
  
       @Bean
          public AuthenticationManager authenticationManager() {
  
           return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider()));
          }
  
       @Bean
          public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
  
              ActiveDirectoryLdapAuthenticationProvider adProvider = new ActiveDirectoryLdapAuthenticationProvider(domain, url);
              adProvider.setConvertSubErrorCodesToExceptions(true);
              adProvider.setUseAuthenticationRequestCredentials(true);
  
              return adProvider;
          }
  </code></pre>
  
  <p>and then use AuthenticationManager like shown below. </p>
  
  <pre><code>Authentication auth = new UsernamePasswordAuthenticationToken(userName, password);
          Authentication a = authenticationManager.authenticate(auth);
  </code></pre>
  
  <p>But, I get a.isAuthenticated() as true for correct username and password, I also get a.getName() as my username. But, how to retrieve sn, dispalyname, name and other attributes. Do we need to write a CustomActiveDirectoryLdapAuthenticationProvider as mentioned here
  <a href="http://code-addict.pl/active-directory-spring-security/" rel="nofollow noreferrer">http://code-addict.pl/active-directory-spring-security/</a></p>