2016-09-23 227 views
0

我試圖使用自定義登錄頁面,但做LDAP認證提供了不低於工作是我的安全和LDAP配置春季啓動安全LDAP認證

@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"); 
    } 
} 

下面是一個被放置在資源文件夾樣LDIF文件中

DN:UID =鮑勃,OU =人,DC = springframework的,DC =組織 對象類:頂 對象類:人 對象類:organizationalPerson 對象類:爲inetOrgPerson CN:鮑勃·漢密爾頓 SN :Hamilton uid:bob userPassword:bobspassword

我在尋找只有有效的用戶才能訪問應用程序中的其他頁面。

配置是否有任何問題,並會感謝您的答案。

回答

-1

您應該更改您的代碼如下:通過將

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

你只要讓每一位用戶無需任何身份驗證,訪問的每個頁面

@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");