Spring Security 配置多个<http>标签与HttpSecurity对应关系

在把以前的xml配置改到java配置,找了半天没找到…于是试出来以后才在官方文档搜索到

引用一句话:

        http拥有一个匹配URL的pattern(对应.antMatcher()),未指定时表示匹配所有的请求,其下的子元素intercept-url也有一个匹配URL的pattern(对应.antMatchers()),该pattern是在http元素对应pattern基础上的,也就是说一个请求必须先满足http对应的pattern才有可能满足其下intercept-url对应的pattern

java配置

参见spring官方文档 Multiple HttpSecurity,我这里大概类似于这样

@Configuration
@Order(1)                                                        
public class RestSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .antMatcher("/rest/**")
            .addFilterAt(rsFilter(), BasicAuthenticationFilter.class)
            .exceptionHandling()
            .authenticationEntryPoint(digestEntryPoint())
            .and()
            .csrf().disable()
            .authorizeRequests()
            .antMatchers("/**")
            .hasRole("RSCLIENT")
    }
}

原XML配置

参见 Advanced Namespace Configuration,我这里类似

<http pattern="/rest/**" entry-point-ref="digestEntryPoint">
    <intercept-url pattern='/**' access="hasRole('RSCLIENT')" />
    <custom-filter ref="digestFilter" position="BASIC_AUTH_FILTER" />
    <csrf disable="true" />
</http>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值