文字通りエンドポイントにヒットすることができます:http://localhost:8080/oauth2-password/helloworldまだ文字列 "Hello World!"があります。下記の設定をチェックして、理由を教えてください。これは非常にイライラしています。SpringセキュリティOAuth2保護されたリソースは実際には保護されていません...フィルターが機能していませんか?
認証サーバ
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
AuthenticationManager authenticationManager;
@Primary
@Bean
InMemoryTokenStore tokenStore() {
return new InMemoryTokenStore();
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(this.authenticationManager).tokenStore(this.tokenStore());
}
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security.checkTokenAccess("isAuthenticated()");
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("client")
.resourceIds("app")
.authorizedGrantTypes("password")
.scopes("read", "write", "trust")
.refreshTokenValiditySeconds(20000)
.accessTokenValiditySeconds(600);
}
}
リソースサーバ
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
@Autowired
AuthenticationManager authManager;
@Autowired
TokenStore tokenStore;
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/").permitAll().antMatchers("/helloworld/**").authenticated();
}
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.resourceId("app").tokenStore(this.tokenStore).authenticationManager(this.authManager);
}
}
WebセキュリティCONFIG
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
似たような質問については、私の[回答](https://stackoverflow.com/a/39591417/5277820)を参照してください。 – dur
@durハハはあなたがもう一度それを捕まえなかったことに驚いた! DelegatingFilterProxyをXMLに登録しなければならないことは分かっていました。簡単です。私はこれがEnableResourceServerを実装するときに自動的に登録されていると思っていました。ただし、そのときに有効になる唯一のフィルタは、OAuth2AuthenticationProcessingFilterであり、全体的な親DelegatingFilterProxy - > FilterChainProxy委任スキームではありません。 –