Merge branch 'master' into 2.0.x
This commit is contained in:
@@ -70,6 +70,11 @@
|
||||
<artifactId>spring-integration-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security.oauth</groupId>
|
||||
<artifactId>spring-security-oauth2</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
|
||||
@@ -21,12 +21,15 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoRestTemplateCustomizer;
|
||||
import org.springframework.cloud.sleuth.ErrorParser;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.web.HttpSpanInjector;
|
||||
@@ -35,6 +38,7 @@ import org.springframework.cloud.sleuth.instrument.web.TraceWebServletAutoConfig
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
@@ -94,4 +98,62 @@ public class TraceWebClientAutoConfiguration {
|
||||
return new TraceWebClientBeanPostProcessor(beanFactory);
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(UserInfoRestTemplateCustomizer.class)
|
||||
protected static class TraceOAuthConfiguration {
|
||||
|
||||
@Autowired BeanFactory beanFactory;
|
||||
|
||||
@Bean UserInfoRestTemplateCustomizerBPP userInfoRestTemplateCustomizerBeanPostProcessor() {
|
||||
return new UserInfoRestTemplateCustomizerBPP(this.beanFactory);
|
||||
}
|
||||
|
||||
class UserInfoRestTemplateCustomizerBPP implements BeanPostProcessor {
|
||||
|
||||
private final BeanFactory beanFactory;
|
||||
|
||||
UserInfoRestTemplateCustomizerBPP(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean,
|
||||
String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(final Object bean,
|
||||
String beanName) throws BeansException {
|
||||
final BeanFactory beanFactory = this.beanFactory;
|
||||
if (bean instanceof UserInfoRestTemplateCustomizer) {
|
||||
return new UserInfoRestTemplateCustomizer() {
|
||||
@Override public void customize(OAuth2RestTemplate template) {
|
||||
final TraceRestTemplateInterceptor interceptor =
|
||||
beanFactory.getBean(TraceRestTemplateInterceptor.class);
|
||||
new RestTemplateInterceptorInjector(interceptor).inject(template);
|
||||
((UserInfoRestTemplateCustomizer) bean).customize(template);
|
||||
}
|
||||
};
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RestTemplateInterceptorInjector {
|
||||
private final TraceRestTemplateInterceptor interceptor;
|
||||
|
||||
RestTemplateInterceptorInjector(TraceRestTemplateInterceptor interceptor) {
|
||||
this.interceptor = interceptor;
|
||||
}
|
||||
|
||||
void inject(RestTemplate restTemplate) {
|
||||
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>(
|
||||
restTemplate.getInterceptors());
|
||||
interceptors.add(this.interceptor);
|
||||
restTemplate.setInterceptors(interceptors);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.springframework.cloud.sleuth.instrument.web.client;
|
||||
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoRestTemplateCustomizer;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.instrument.web.TraceHttpAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.instrument.web.TraceWebAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.log.SleuthLogAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
|
||||
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TraceWebClientAutoConfigurationTests.Config.class)
|
||||
public class TraceWebClientAutoConfigurationTests {
|
||||
|
||||
@Autowired Config config;
|
||||
@Autowired UserInfoRestTemplateCustomizer customizer;
|
||||
@Autowired TraceRestTemplateInterceptor interceptor;
|
||||
|
||||
@Test
|
||||
public void should_wrap_UserInfoRestTemplateCustomizer_in_a_trace_representation() {
|
||||
OAuth2ProtectedResourceDetails details = Mockito.mock(OAuth2ProtectedResourceDetails.class);
|
||||
OAuth2RestTemplate template = new OAuth2RestTemplate(details);
|
||||
|
||||
this.customizer.customize(template);
|
||||
|
||||
then(this.config.executed).isTrue();
|
||||
then(template.getInterceptors()).contains(this.interceptor);
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@ImportAutoConfiguration(classes = {
|
||||
TraceWebClientAutoConfiguration.class, SleuthLogAutoConfiguration.class,
|
||||
TraceHttpAutoConfiguration.class, TraceWebAutoConfiguration.class, TraceAutoConfiguration.class })
|
||||
static class Config {
|
||||
|
||||
boolean executed = false;
|
||||
|
||||
@Bean UserInfoRestTemplateCustomizer customizer() {
|
||||
return new UserInfoRestTemplateCustomizer() {
|
||||
@Override public void customize(OAuth2RestTemplate template) {
|
||||
Config.this.executed = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,5 @@ ribbon.eureka.enabled: false
|
||||
|
||||
spring.sleuth.scheduled.skipPattern: "^org.*TestBeanWithScheduledMethodToBeIgnored$"
|
||||
# comma separated list of matchers
|
||||
spring.sleuth.rxjava.schedulers.ignoredthreads: HystixMetricPoller,^MyCustomThread.*$,^RxComputation.*$
|
||||
spring.sleuth.rxjava.schedulers.ignoredthreads: HystixMetricPoller,^MyCustomThread.*$,^RxComputation.*$
|
||||
security.ignored: /**
|
||||
Reference in New Issue
Block a user