春ブーツ2における役割とアクチュエータのエンドポイントを保護する方法?

デニスStephanov:

あなたは春ブーツ2で安全なアクチュエータのエンドポイントに助けることができますか?私は、移行ガイドをチェックし、それは私を助けていません。

ここに私のセキュリティ設定は次のとおりです。

@Configuration
@EnableWebSecurity
public class SecConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ADMIN")    
                .anyRequest().authenticated();
    }

}

しかし、私はに行くときhttp://localhost:8080/actuator/healthも、ログインせずにロードします。接頭辞を持つ他のエンドポイントは、/actuator同様にログインを必要としません。私は間違って何をしましたか?

私はまた、この構成ではOAuthを追加します。

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
    @Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients
            .inMemory()
                .withClient("client-id")
                    .scopes("read", "write")
                    .authorizedGrantTypes("password")
                    .secret("xxxxxx")
                    .accessTokenValiditySeconds(6000);
}
}

@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
       http
            .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
            .authorizeRequests()
                .antMatchers("/ajax/**").authenticated()
                .and()
            .csrf()
                .disable();
    }
}
サンフランシスコRecio:

アプリケーションがリソースサーバーである場合は、SecConfigクラスは必要ありません。

あなたはそれを削除するのであれば、あなたの中にResourceServerConfigクラスあなたは、アクチュエータを確保することができ、ちょうどを通じて管理をしてみましょう:

@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
       http
            .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
            .authorizeRequests()
                .antMatchers("/ajax/**").authenticated()           
                .antMatchers("/actuator/**").hasRole("ADMIN")  
                .anyRequest().authenticated()  
                .and()
            .csrf()
                .disable();
    }
}

私は、追加.anyRequest().authenticated()のアプリケーション・エンドポイントの残りの部分を確保します。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=189084&siteId=1