Merge branch '3.0.x' into 3.1.x
This commit is contained in:
35
pom.xml
35
pom.xml
@@ -44,19 +44,6 @@
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<modules>
|
||||
<module>spring-cloud-sleuth-dependencies</module>
|
||||
<module>spring-cloud-sleuth-api</module>
|
||||
<module>spring-cloud-sleuth-instrumentation</module>
|
||||
<module>spring-cloud-sleuth-brave</module>
|
||||
<module>spring-cloud-sleuth-autoconfigure</module>
|
||||
<module>tests</module>
|
||||
<module>spring-cloud-sleuth-zipkin</module>
|
||||
<module>spring-cloud-starter-sleuth</module>
|
||||
<module>spring-cloud-sleuth-samples</module>
|
||||
<module>docs</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
@@ -75,9 +62,9 @@
|
||||
<spring-cloud-deployer.version>2.5.1</spring-cloud-deployer.version>
|
||||
<brave.version>5.13.9</brave.version>
|
||||
<opentracing.version>0.32.0</opentracing.version>
|
||||
<!-- Deprecated - reached EOL -->
|
||||
<spring-security-boot-autoconfigure.version>2.3.4.RELEASE</spring-security-boot-autoconfigure.version>
|
||||
<spring-security-oauth2.version>2.2.0.RELEASE</spring-security-oauth2.version>
|
||||
<spring-security-version>5.6.0</spring-security-version>
|
||||
<disable.nohttp.checks>false</disable.nohttp.checks>
|
||||
<okhttp.version>4.9.0</okhttp.version>
|
||||
<mockwebserver.version>4.8.0</mockwebserver.version>
|
||||
@@ -103,6 +90,19 @@
|
||||
<build-helper-maven-plugin.version>3.2.0</build-helper-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>spring-cloud-sleuth-dependencies</module>
|
||||
<module>spring-cloud-sleuth-api</module>
|
||||
<module>spring-cloud-sleuth-instrumentation</module>
|
||||
<module>spring-cloud-sleuth-brave</module>
|
||||
<module>spring-cloud-sleuth-autoconfigure</module>
|
||||
<module>tests</module>
|
||||
<module>spring-cloud-sleuth-zipkin</module>
|
||||
<module>spring-cloud-starter-sleuth</module>
|
||||
<module>spring-cloud-sleuth-samples</module>
|
||||
<module>docs</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
@@ -270,13 +270,6 @@
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-bom</artifactId>
|
||||
<version>${spring-security-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security.oauth.boot</groupId>
|
||||
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
|
||||
|
||||
@@ -192,6 +192,11 @@
|
||||
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-oauth2-client</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.vault</groupId>
|
||||
<artifactId>spring-vault-core</artifactId>
|
||||
|
||||
@@ -18,8 +18,10 @@ package org.springframework.cloud.sleuth.autoconfig.instrument.web.client;
|
||||
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
@@ -36,6 +38,7 @@ import org.springframework.cloud.sleuth.autoconfig.brave.BraveAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.http.HttpClientHandler;
|
||||
import org.springframework.cloud.sleuth.instrument.web.client.HttpClientBeanPostProcessor;
|
||||
import org.springframework.cloud.sleuth.instrument.web.client.LazyTraceClientHttpRequestInterceptor;
|
||||
import org.springframework.cloud.sleuth.instrument.web.client.TraceDefaultOAuth2UserServiceCustomizer;
|
||||
import org.springframework.cloud.sleuth.instrument.web.client.TraceRequestHttpHeadersFilter;
|
||||
import org.springframework.cloud.sleuth.instrument.web.client.TraceResponseHttpHeadersFilter;
|
||||
import org.springframework.cloud.sleuth.instrument.web.client.TraceRestTemplateBeanPostProcessor;
|
||||
@@ -51,6 +54,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
|
||||
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
@@ -167,6 +171,7 @@ class TraceWebClientAutoConfiguration {
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass({ UserInfoRestTemplateCustomizer.class, OAuth2RestTemplate.class })
|
||||
@Deprecated // Use Spring-Security OAuth2 support
|
||||
protected static class TraceOAuthConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -183,4 +188,24 @@ class TraceWebClientAutoConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(DefaultOAuth2UserService.class)
|
||||
protected static class TraceSpringSecurityOAuth2Configuration {
|
||||
|
||||
@Bean
|
||||
static BeanPostProcessor traceDefaultOAuth2UserServiceBeanPostProcessor(BeanFactory beanFactory) {
|
||||
return new BeanPostProcessor() {
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof DefaultOAuth2UserService) {
|
||||
new TraceDefaultOAuth2UserServiceCustomizer(beanFactory)
|
||||
.customize((DefaultOAuth2UserService) bean);
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<version>3.1.4-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
<properties>
|
||||
<!-- <kotlin.compiler.incremental>true</kotlin.compiler.incremental> -->
|
||||
</properties>
|
||||
@@ -220,6 +220,11 @@
|
||||
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-oauth2-client</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.session</groupId>
|
||||
<artifactId>spring-session-data-redis</artifactId>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2013-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.web.client;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.cloud.sleuth.instrument.web.mvc.TracingClientHttpRequestInterceptor;
|
||||
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.client.RestOperations;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* Customizes a {@link DefaultOAuth2UserService} by providing it with a trace interceptor.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 3.0.6
|
||||
*/
|
||||
public class TraceDefaultOAuth2UserServiceCustomizer {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TraceDefaultOAuth2UserServiceCustomizer.class);
|
||||
|
||||
private final BeanFactory beanFactory;
|
||||
|
||||
private static final Field REST_OPERATIONS = ReflectionUtils.findField(DefaultOAuth2UserService.class,
|
||||
"restOperations", RestOperations.class);
|
||||
|
||||
public TraceDefaultOAuth2UserServiceCustomizer(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
public void customize(DefaultOAuth2UserService service) {
|
||||
try {
|
||||
ReflectionUtils.makeAccessible(Objects.requireNonNull(REST_OPERATIONS,
|
||||
"restOperations field was not found in [DefaultOAuth2UserService] class"));
|
||||
RestOperations restOperations = (RestOperations) REST_OPERATIONS.get(service);
|
||||
if (!(restOperations instanceof RestTemplate)) {
|
||||
log.warn(
|
||||
"Won't instrument the restOperations field in [DefaultOAuth2UserService] class because it's not a RestTemplate object");
|
||||
return;
|
||||
}
|
||||
RestTemplate template = (RestTemplate) restOperations;
|
||||
final TracingClientHttpRequestInterceptor interceptor = this.beanFactory
|
||||
.getBean(TracingClientHttpRequestInterceptor.class);
|
||||
new RestTemplateInterceptorInjector(interceptor).inject(template);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("Can't access the restOperations field - won't instrument the [DefaultOAuth2UserService] class",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2013-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.web.client;
|
||||
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||
import org.springframework.cloud.sleuth.instrument.web.mvc.TracingClientHttpRequestInterceptor;
|
||||
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
class TraceDefaultOAuth2UserServiceCustomizerTests {
|
||||
|
||||
@Test
|
||||
void should_add_a_trace_interceptor_to_defaultoauth2userservice() {
|
||||
DefaultOAuth2UserService service = new DefaultOAuth2UserService();
|
||||
BeanFactory beanFactory = beanFactory();
|
||||
TraceDefaultOAuth2UserServiceCustomizer serviceCustomizer = new TraceDefaultOAuth2UserServiceCustomizer(
|
||||
beanFactory);
|
||||
|
||||
serviceCustomizer.customize(service);
|
||||
serviceCustomizer.customize(service);
|
||||
|
||||
Object operations = ReflectionUtils
|
||||
.getField(ReflectionUtils.findField(DefaultOAuth2UserService.class, "restOperations"), service);
|
||||
BDDAssertions.then(operations).isInstanceOf(RestTemplate.class);
|
||||
RestTemplate restTemplate = (RestTemplate) operations;
|
||||
BDDAssertions.then(restTemplate.getInterceptors()).hasSize(1)
|
||||
.hasOnlyElementsOfType(TracingClientHttpRequestInterceptor.class);
|
||||
}
|
||||
|
||||
private BeanFactory beanFactory() {
|
||||
StaticListableBeanFactory beanFactory = new StaticListableBeanFactory();
|
||||
beanFactory.addBean("TracingClientHttpRequestInterceptor",
|
||||
TracingClientHttpRequestInterceptor.create(null, null));
|
||||
return beanFactory;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user