2

次のように、別のポートで spring-boot-actuator を使用しました

server.port=8080
management.port=8989

アプリケーションでは、 を使用したいのですが、アクチュエータ ポートでenable-csrf=trueは使用したくありません。csrfjolokiaに一括POSTリクエストを使いたいからです。

除外するだけ/actuatorではスマートではありません。

http.csrf().ignoringAntMatchers("/actuator/**");

次のプロパティのように私にとっては良いです(btmanagement.security.enable-csrfは存在しません)。

security.enable-csrf=true
management.security.enable-csrf=false

良い解決策はありますか?

4

1 に答える 1

1

別の管理ポートがあるため、そのために CSRF を無効にするだけです。

@Configuration
public class MySecurityConfiguration extends WebSecurityConfigurerAdapter {

    private static RequestMatcher allOf(RequestMatcher... requestMatchers) {
        return new AndRequestMatcher(requestMatchers);
    }

    private static RequestMatcher not(RequestMatcher requestMatcher) {
        return new NegatedRequestMatcher(requestMatcher);
    }

    private final ManagementServerProperties managementServerProperties;

    public MySecurityConfiguration(ManagementServerProperties managementServerProperties) {
        this.managementServerProperties = Objects.requireNonNull(managementServerProperties);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().requireCsrfProtectionMatcher(
                allOf(CsrfFilter.DEFAULT_CSRF_MATCHER, not(accessingManagementPort())));
        // other configuration
    }

    private RequestMatcher accessingManagementPort() {
        return httpServletRequest -> httpServletRequest.getLocalPort() == managementServerProperties.getPort();
    }

}
于 2017-06-13T10:04:36.227 に答える