javascript
filter java oauth_java – 带有自定义安全过滤器的Spring Boot OAuth2
我有一個帶有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();
}
}
一些簡單的例子如何實現這一點將非常有幫助.謝謝!
總結
以上是生活随笔為你收集整理的filter java oauth_java – 带有自定义安全过滤器的Spring Boot OAuth2的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 此次边路调整系统推荐射手走哪路_王者荣耀
- 下一篇: 如何在Windows11和Windows