2016-03-27 36 views
2

我試圖添加一個不安全的控制器端點/foo/bar到我的應用程序,但每當我嘗試調用它時,我得到401 UnauthorizedHttpSecurity配置 - 允許所有仍然需要基本的身份驗證

這裏是我WebSecurityConfigurerAdapter

http 
    .authorizeRequests() 
     .antMatchers("/foo/**").permitAll() 
    .and() 
    .formLogin() 
     .loginPage("/login").permitAll() 
    .and() 
    .requestMatchers() 
     .antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access") 
    .and() 
    .authorizeRequests() 
     .anyRequest().authenticated(); 

會有人爲好心指出我錯過了什麼?

+0

/富/條,應允許GET或POST或兩者兼而有之? – Sanj

+0

@Sanj驗證機制不應該考慮,方法被RequestMapping過濾掉 – Benedictus

回答

2

連接多個antMatchers在一個authorizeRequests部分:

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
      .authorizeRequests() 
       .antMatchers("/foo/**").permitAll() 
       .anyRequest().authenticated() 
      .and() 
      .formLogin().loginPage("/login").permitAll(); 
} 
1

我不知道什麼在你的confighierarchy,但它看起來不正確。

嘗試:

http 
    .formLogin() 
     .loginPage("/login") 
     .and() 
    .authorizeRequests() 
     .antMatchers("/foo/**").permitAll() 
     .anyRequest().authenticated();