2013-07-26 90 views
2

我希望每個不在路徑/cobrands/fdt之間的網址都可以申請密碼。如果我要求例如/fdt/name我不應該被要求進行http認證。HttpSecurity有了Spring,區分網址的權限

public class SecurityConfiguration extends WebSecurityConfigurerAdapter { 
/** code **/ 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.exceptionHandling().authenticationEntryPoint(entryPoint()).and() 
       .authorizeUrls() 
       .antMatchers("/**").hasAnyAuthority("wf_cobrand_lettura", "wf_cobrand_fdt") 
       .antMatchers("/cobrands/*").permitAll() 
       .antMatchers("/fdt/*").permitAll() 
       .and() 
       .httpBasic(); 

    } 

} 

回答

2

匹配器按順序處理,所以你的

.antMatchers("/**") 

捕獲所有請求和剩下的兩個匹配器從不評估。

把它掛在這樣:

http.exceptionHandling().authenticationEntryPoint(entryPoint()).and() 
      .authorizeUrls() 
      .antMatchers("/cobrands/*").permitAll() 
      .antMatchers("/fdt/*").permitAll() 
      .antMatchers("/**").hasAnyAuthority("wf_cobrand_lettura", "wf_cobrand_fdt") 
      .and() 
      .httpBasic();