java – 带有自定义安全过滤器的Spring Boot OAuth2
发布时间:2020-12-15 02:17:18 所属栏目:Java 来源:网络整理
导读:我有一个带有OAuth2授权和资源服务器的 spring boot设置.用户可以通过向/ oauth / token发出POST请求来获取令牌.到现在为止还挺好. 但是,我不想通过BASIC auth保护/ oauth / token,而是通过自定义安全过滤器. 我尝试了以下内容,但从未调用过DemoAuthenticati
|
我有一个带有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();
}
}
一些简单的例子如何实现这一点将非常有帮助.谢谢! 解决方法@Configuration
@EnableAuthorizationServer
public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.allowFormAuthenticationForClients().addTokenEndpointAuthenticationFilter(new AligenieFilter());
}
//....
}
这个对我有用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- java web开发之购物车功能实现示例代码
- java – 将Enum成员传递给构造函数:“实际和形式参数列表的
- boto – 弹性地图减少:CANCEL_AND_WAIT和CONTINUE之间的区
- oauth – Socialauth,Scribe-Java和Spring Social之间的主要
- java – 如果Stream没有结果,则抛出异常
- java – 需要协助运行Map减少WordCount作业与存储在amazon
- 如何通过编程方式在电子邮件中发送lotusscript?
- java – Lombok:如何指定一个arg构造函数?
- 使用Java从串口读取文件
- 如何使用在mockito中调用之间更改状态的相同参数来验证相同
