【发布时间】:2020-08-26 18:55:18
【问题描述】:
我正在尝试在 SpringBoot 中 OAuth2 登录后做一些事情。
所以我尝试在 OAuth2LoginAuthenticationFilter 之后添加过滤器。
@Configuration
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login", "/oauth2/**", "/")
.permitAll()
.anyRequest().authenticated()
.and()
.oauth2Login()
.and()
.addFilterAfter(new MyFilter(), OAuth2LoginAuthenticationFilter.class)
.logout();
}
这是我的代码。
Spring 安全配置类
@Configuration
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login", "/oauth2/**", "/")
.permitAll()
.anyRequest().authenticated()
.and()
.oauth2Login()
.and()
.addFilterAfter(new MyFilter(), OAuth2LoginAuthenticationFilter.class)
.logout();
}
}
MyFilter 类
public class MyFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("login success.");
chain.doFilter(request, response);
}
}
为什么要叫三遍?我该怎么办?
我只想被叫一次或获得任何其他好方法。
【问题讨论】:
标签: spring oauth spring-security-oauth2