我正在使用Spring Boot,我希望我的應用程序能夠託管Oauth2資源服務器以訪問同一服務器上的api端點。我還需要通過表單登錄與安全頁面建立一個Web界面。Spring Boot安全表單登錄和Oauth2資源服務器
例如我有api endpoints/api/v1/**,其中請求只能通過從我的oauth2資源服務器獲取令牌來完成。
此外還有像/ account/**這樣的端點,用戶需要通過表單登錄。
現在所有這些都需要在一個Spring Boot實例中。
我WebSecurityConfig文件:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/account/**").authenticated()
.and()
.httpBasic();
}
}
在我Oauth2SecurityConfig我:
@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends
ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/api/v1/me/**").authenticated();
}
}
的問題是,的oauth2配置似乎推翻第一配置和我所有的網頁資源,而不問暴露表單登錄中的用戶名密碼。如果我嘗試訪問我的API端點,我會得到預期的oauth錯誤響應。
我是否需要在一種重寫方法中使用它們?我需要有2個HttpSecurity實例嗎?我該如何解決這個問題?
爲什麼我用春天開機'/ API/V1/ME/**'可以通過訪問每個身體? –