HttpSecurity使用Spring,区分URL权限

时间:2013-07-26 09:14:46

标签: spring-security basic-authentication

我希望对于不在路径/cobrands/fdt下的每个网址提供密码请求。如果我要求/fdt/name的例子,我不应该被要求进行http身份验证。

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();

    }

}

1 个答案:

答案 0 :(得分:2)

按顺序处理匹配器,所以

.antMatchers("/**")

捕获所有请求,其余两个匹配器永远不会被评估。

这样说:

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