2016-09-23 3 views
0

Ich versuche, die LDAP-Authentifizierung mithilfe von benutzerdefinierten Login-Seite zu tun, aber es ist nicht unter Arbeit ist meine Sicherheit und LDAP-KonfigurationFrühling Boot Security LDAP-Authentifizierung

@Configuration 
@EnableWebSecurity 
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 

     http.httpBasic().and().authorizeRequests().antMatchers("/**").permitAll() 
      .anyRequest().authenticated() 
      .and().formLogin().loginPage("/login") 
      .usernameParameter("username") 
      .passwordParameter("password") 
      .failureUrl("/login?error"); 

    } 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
     auth 
      .ldapAuthentication() 
       .userDnPatterns("uid={0},ou=people") 
       .groupSearchBase("ou=groups") 
       .contextSource().ldif("classpath:test-server.ldif"); 
    } 
} 

Below Probe LDIF-Datei ist, die in Ressource-Ordner abgelegt wird

dn: uid = bob, ou = people, dc = spring, dc = org Objektklasse: top Objektklasse: Person Objektklasse: organizationalPerson Objektklasse: inetOrgPerson cn: Bob Hamilton sn : Hamilton uid: bob userPassword: bobspasswort

Ich suche nur gültige Benutzer können auf andere Seiten in der Anwendung zugreifen.

Ist irgendetwas mit der Konfiguration nicht in Ordnung und wird für Ihre Antworten dankbar sein.

Antwort

-1

Sie sollten Ihren Code wie folgt ändern:

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
    http.httpBasic().and().authorizeRequests() 
    .anyRequest().authenticated() 
    .and().formLogin().loginPage("/login") 
    .usernameParameter("username") 
    .passwordParameter("password") 
    .failureUrl("/login?error"); 

indem

.antMatchers("/**").permitAll() 

Sie erlaubt nur jeder Benutzer ohne Authentifizierung auf jeder Seite zuzugreifen.

Verwandte Themen