filter java oauth_java – 带有自定义安全过滤器的Spring Boot OAuth2

论坛 期权论坛 脚本     
已经匿名di用户   2022-3-21 23:59   2142   0

我有一个带有OAuth2授权和资源服务器的

spring boot设置.用户可以通过向/ oauth / token发出POST请求来获取令牌.到现在为止还挺好.

但是,我不想通过BASIC auth保护/ oauth / token,而是通过自定义安全过滤器.

我尝试了以下内容,但从未调用过DemoAuthenticationFilter:

@Configuration

@EnableResourceServer

protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

// ...

@Override

public void configure(HttpSecurity http) throws Exception {

// ...

http.addFilterBefore(new DemoAuthenticationFilter(), BasicAuthenticationFilter.class);

http.authorizeRequests().antMatchers("/oauth/token").authenticated();

}

}

此外,如果我尝试将其添加到WebSecurityConfigurerAdapter,则只有在通过OAuth2对请求进行身份验证后才会调用过滤器:

@Configuration

@EnableWebSecurity

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

// ...

@Override

protected void configure(HttpSecurity http) throws Exception {

// ...

http.addFilterBefore(new DemoAuthenticationFilter(), BasicAuthenticationFilter.class);

http.authorizeRequests().antMatchers("/oauth/token").authenticated();

}

}

一些简单的例子如何实现这一点将非常有帮助.谢谢!

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP