问题
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:
- spring-boot: 1.3.5
- spring-cloud: Brixton.SR3
- spring-cloud-sleuth: 1.0.3
- spring-security-oauth2: 2.0.9
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;
}
回答1:
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.
来源:https://stackoverflow.com/questions/41807813/how-to-use-spring-cloud-sleuth-to-trace-spring-security-oauth-activities