javascript
filter java oauth_java – 带有自定义安全过滤器的Spring Boot OAuth2
我有一個(gè)帶有OAuth2授權(quán)和資源服務(wù)器的
spring boot設(shè)置.用戶可以通過向/ oauth / token發(fā)出POST請(qǐng)求來獲取令牌.到現(xiàn)在為止還挺好.
但是,我不想通過BASIC auth保護(hù)/ oauth / token,而是通過自定義安全過濾器.
我嘗試了以下內(nèi)容,但從未調(diào)用過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對(duì)請(qǐng)求進(jìn)行身份驗(yàn)證后才會(huì)調(diào)用過濾器:
@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();
}
}
一些簡(jiǎn)單的例子如何實(shí)現(xiàn)這一點(diǎn)將非常有幫助.謝謝!
總結(jié)
以上是生活随笔為你收集整理的filter java oauth_java – 带有自定义安全过滤器的Spring Boot OAuth2的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 此次边路调整系统推荐射手走哪路_王者荣耀
- 下一篇: $ajax不能识别,JQuery/JS