Magnus Larsson
Magnus Larsson

Reputation: 612

How to use spring-cloud-sleuth to trace spring-security-oauth activities?

I'm trying to use spring-cloud-sleuth to trace https requests initiated by spring-security-oauth.

But I'm stuck on that the spring-security-oauth filter OAuth2AuthenticationProcessingFilter is executed before the spring-cloud-sleuth filter TraceFilter.

Can this be changed so that the spring-cloud-sleuth filter is processed before the spring-security-oauth filter?

Version info:

Update: Based on the suggestion below I could solve the problem by defining my own FilterRegistrationBean as:

@Inject
TraceFilter traceFilter;

@Bean
public FilterRegistrationBean myTraceFilter() {
    LOG.info("Register a TraceFilter with HIGHEST_PRECEDENCE");
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(traceFilter, new ServletRegistrationBean[0]);
    filterRegistrationBean.setDispatcherTypes(ASYNC, new DispatcherType[]{ERROR, FORWARD, INCLUDE, REQUEST});
    filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return filterRegistrationBean;
}

Upvotes: 2

Views: 1102

Answers (1)

Marcin Grzejszczak
Marcin Grzejszczak

Reputation: 11169

You can register the TraceFilter yourself and manually provide the order. Just try to put it before the spring security filter. If that works fine you can file a PR / issue describing the whole flow so that we continue the discussion there.

Upvotes: 1

Related Questions