2015-08-19 6 views
1

Я пытаюсь настроить аутентификацию ldap через java config. Код auth.getObject внутри метода init возвращает значение null и не может установить диспетчер проверки подлинности, а также исключение не видно. Что-то не так в конфиге? Как я могу получить объект диспетчера проверки подлинности?Spring boot - security java config - LDAP

@Configuration 
    public class LdapAuthenticationConfig extends GlobalAuthenticationConfigurerAdapter { 

     /** The environment. */ 
     private Environment environment; 

     @Bean(name="ldapAuthManager") 
     public AuthenticationManager getAuthManager(){ 
      return authenticationManager; 
     } 

     private AuthenticationManager authenticationManager; 


     @Override 
     public void init(AuthenticationManagerBuilder auth) throws Exception { 
      auth.ldapAuthentication() 
        .userSearchFilter(
          "(&(sAMAccountName={0})(objectclass=organizationalPerson))") 
        .userSearchBase("OU="+environment.getProperty("ldap.user-search-base.name")) 
        .groupSearchFilter("(member={0})") 
        .groupSearchBase("OU=Global-Groups").groupRoleAttribute("cn") 
        .contextSource().url(environment.getProperty("ldap.url")) 
        .managerDn(environment.getProperty("ldap.conn.user")) 
        .managerPassword(environment.getProperty("ldap.conn.pwd")); 

      setAuthenticationManager(auth.getObject()); 

     } 

     public AuthenticationManager getAuthenticationManager() { 
      return authenticationManager; 
     } 

     public void setAuthenticationManager(
       AuthenticationManager authenticationManager) { 
      this.authenticationManager = authenticationManager; 
     } 

     @Autowired 
     public void setEnvironment(Environment environment) { 

      this.environment = environment; 
     } 
    } 

ответ

0

Попробуйте добавить полный URL к серверу LDAP для "ldap.url" с портом и SearchBase, например: ldap://**server name**:**port**/**o=userSearchBase**

Он работал для меня. Для некоторых реакторов .port() и .userSearchBase() не удалось создать правильный URL-адрес.

Надеюсь, это поможет.

Смежные вопросы