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

此生再无相见时 提交于 2021-01-27 18:31:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!