spring-boot - 基于 url 的自定义多个身份验证提供程序始终仅调用一个提供程序
问题描述
我已经配置了多个自定义auth providers
,使用auth2
和spring boot
,但它总是执行CustomInternalAuthenticationProvider
唯一的。你能解释一下如何按顺序应用蚂蚁匹配器规则吗?我使用了两个WebSecurityConfigurerAdapter
类,一个是有序的,一个是默认的。指导我如何处理规则antmatcher
正确吗?
@EnableResourceServer
@EnableWebSecurity
public class WebSecurityConfig{
@Autowired
UserDetailsService userDetailsService;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}
@Configuration
@Order(1)
public static class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println("@order");
http.antMatcher("/../main/**")
.requestMatchers()
.antMatchers("/","/login*", "/oauth/authorize**","/exit","**/logout")
.and().authenticationProvider(daoInternalAuthenticationProvider())
.formLogin().loginPage("/login")
;
}
@Bean
public AuthenticationProvider daoInternalAuthenticationProvider() throws Exception {
return new CustomInternalAuthenticationProvider();
}
}
@Configuration
public static class ApiTokenSecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println("default");
http.antMatcher("/../user/**")
.requestMatchers()
.antMatchers("/","/login*", "/oauth/authorize**","/exit","**/logout")
.and() .authenticationProvider(daoExternalAuthenticationProvider())
.formLogin().loginPage("/login")
;
}
@Bean
public AuthenticationProvider daoExternalAuthenticationProvider() throws Exception {
return new CustomExternalAuthonticationProvider();
}
}
解决方案
推荐阅读
- c++ - 为什么 C++ 中的字符数组返回其项目而不是其地址?
- javascript - 通过服务器端呈现的 DataTable 排序
- javascript - 为什么 Javascript 在我的 Flask 应用程序中不起作用?
- javascript - 事务号只允许在支持文档级锁定的存储引擎上使用 - MongodbMemoryServer/Mochai/Chai/Supertest
- c# - 在.net中调用python函数
- php - 为什么三元运算返回错误结果?
- javafx - 在 javafx 中复制组件的视图
- c# - 如何在运行时生成的我的 asp.net web 表的每一行中动态添加删除和更新按钮
- python - 如何修复装饰器模拟
- python - 错误出现在这一行 os.path.exists()