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

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

引用一句话:

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

java配置

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

  1. @Configuration
  2. @Order(1)
  3. public class RestSecurityConfig extends WebSecurityConfigurerAdapter {
  4. @Override
  5. protected void configure(HttpSecurity http) throws Exception {
  6. http
  7. .antMatcher("/rest/**")
  8. .addFilterAt(rsFilter(), BasicAuthenticationFilter.class)
  9. .exceptionHandling()
  10. .authenticationEntryPoint(digestEntryPoint())
  11. .and()
  12. .csrf().disable()
  13. .authorizeRequests()
  14. .antMatchers("/**")
  15. .hasRole("RSCLIENT")
  16. }
  17. }

原XML配置

参见14.6 Advanced Namespace Configuration,我这里类似

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

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值