0

Spring Boot Actuator によって提供される管理エンドポイントに、URI マッチャーを使用して Grails 3.0.12 インターセプターを適用しようとしています。アクチュエーターのmanagement.context_pathプロパティを/adminに設定しています。

UrlMappings.groovy にマップされたすべてのエンドポイントは傍受されていますが、Spring Boot Actuator によって管理されているエンドポイントは傍受されていません。代わりに、インターセプターがバイパスされていることを示す次のログが表示されます。

DEBUG: org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Looking up handler method for path /admin/metrics
DEBUG: org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Returning handler method [public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()]

これが私のインターセプターです:

class LoginInterceptor {

    def securityService

    int order = HIGHEST_PRECEDENCE

    LoginInterceptor() {
        match(uri: "/**")
    }

    boolean before() {
        if (!request.exception) {
            securityService.authenticateUser()
        }
        true
    }

    boolean after() { true }

    void afterView() { /* no-op */ }
}

application.yml の管理構成は次のとおりです。

management:
  context_path: /admin

アクチュエーターが提供するエンドポイントが確実に傍受されるようにするにはどうすればよいですか?

4

1 に答える 1

0

GrailsInterceptorHandlerInterceptorAdapter がインターセプターとして設定されている EndpointHandlerMappingCustomizer Customize() メソッドを実装することで、これを行う 1 つの方法を見つけました。

import org.grails.plugins.web.interceptors.GrailsInterceptorHandlerInterceptorAdapter
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMappingCustomizer

class ActuatorInterceptor implements EndpointHandlerMappingCustomizer {
    GrailsInterceptorHandlerInterceptorAdapter interceptorAdapter

    @Override
    public void customize(EndpointHandlerMapping mapping) {
        Object[] interceptors = [ interceptorAdapter ]
        mapping.setInterceptors(interceptors)
    }
}

resources.groovy:

beans = {
    actuatorInterceptor(ActuatorInterceptor) {
        interceptorAdapter = ref('grailsInterceptorHandlerInterceptorAdapter')
    }
}

これは Spring Boot Actuator に固有であり、たとえば Spring Cloud Config エンドポイントでは機能しないため、理想的とは言えません。Grails インターセプターを使用してすべての URI マッピングをインターセプトする、より一般化された方法を見たいと思います。

于 2016-02-02T05:17:45.470 に答える