栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring Security多个URL规则集无法一起使用

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Security多个URL规则集无法一起使用

您将覆盖以前的匹配器,请参阅HttpSecurity.html#antMatcher:

调用

antMatcher(String)
将覆盖以前调用
mvcMatcher(String)}
requestMatchers()
antMatcher(String)
regexMatcher(String)
,和
requestMatcher(RequestMatcher)

和HttpSecurity.html#regexMatcher:

调用

regexMatcher(String)
将覆盖以前调用
mvcMatcher(String)}
requestMatchers()
antMatcher(String)
regexMatcher(String)
,和
requestMatcher(RequestMatcher)

如果您需要多个配置

HttpSecurity
,请参阅Spring
Security Reference

我们可以配置多个HttpSecurity实例,就像我们可以具有多个

<http>
块一样。关键是要扩展
WebSecurityConfigurationAdapter
多次。例如,以下是对以开头的URL具有不同配置的示例
/api/

>     @EnableWebSecurity>     public class MultiHttpSecurityConfig {>       @Autowired>       public void configureGlobal(AuthenticationManagerBuilder auth) { 1>auth>    .inMemoryAuthentication()>        .withUser("user").password("password").roles("USER").and()>        .withUser("admin").password("password").roles("USER",> "ADMIN");>       }>  >       @Configuration>       @Order(1) 2>       public static class ApiWebSecurityConfigurationAdapter extends> WebSecurityConfigurerAdapter {>protected void configure(HttpSecurity http) throws Exception {>    http>        .antMatcher("/api/**")         3>        .authorizeRequests()> .anyRequest().hasRole("ADMIN")> .and()>        .httpBasic();>}>       }>  >       @Configuration       4>       public static class FormLoginWebSecurityConfigurerAdapter extends> WebSecurityConfigurerAdapter {>  >@Override>protected void configure(HttpSecurity http) throws Exception {>    http>        .authorizeRequests()> .anyRequest().authenticated()> .and()>        .formLogin();>}>       }>     }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/483331.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号