Merge branch '1.5.x'

This commit is contained in:
Phillip Webb 2017-04-04 10:07:38 -07:00
commit 2de7e9c310
17 changed files with 115 additions and 94 deletions

View File

@ -169,7 +169,8 @@ public class ManagementServerProperties implements SecurityPrerequisite {
/**
* Comma-separated list of roles that can access the management endpoint.
*/
private List<String> roles = new ArrayList<String>(Collections.singletonList("ACTUATOR"));
private List<String> roles = new ArrayList<String>(
Collections.singletonList("ACTUATOR"));
/**
* Session creating policy for security use (always, never, if_required,

View File

@ -61,7 +61,8 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
Map<String, Object> result = new LinkedHashMap<>();
result.put("profiles", getEnvironment().getActiveProfiles());
PropertyResolver resolver = getResolver();
for (Entry<String, PropertySource<?>> entry : getPropertySourcesAsMap().entrySet()) {
for (Entry<String, PropertySource<?>> entry : getPropertySourcesAsMap()
.entrySet()) {
PropertySource<?> source = entry.getValue();
String sourceName = entry.getKey();
if (source instanceof EnumerablePropertySource) {
@ -88,8 +89,7 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
private Map<String, PropertySource<?>> getPropertySourcesAsMap() {
Map<String, PropertySource<?>> map = new LinkedHashMap<String, PropertySource<?>>();
MutablePropertySources sources = getPropertySources();
for (PropertySource<?> source : sources) {
for (PropertySource<?> source : getPropertySources()) {
extract("", map, source);
}
return map;
@ -138,12 +138,11 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
}
/**
* {@link PropertySourcesPropertyResolver} that sanitizes sensitive placeholders
* if present.
*
* @author Madhura Bhave
* {@link PropertySourcesPropertyResolver} that sanitizes sensitive placeholders if
* present.
*/
private class PlaceholderSanitizingPropertyResolver extends PropertySourcesPropertyResolver {
private class PlaceholderSanitizingPropertyResolver
extends PropertySourcesPropertyResolver {
private final Sanitizer sanitizer;
@ -152,8 +151,8 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
* @param propertySources the set of {@link PropertySource} objects to use
* @param sanitizer the sanitizer used to sanitize sensitive values
*/
PlaceholderSanitizingPropertyResolver(PropertySources
propertySources, Sanitizer sanitizer) {
PlaceholderSanitizingPropertyResolver(PropertySources propertySources,
Sanitizer sanitizer) {
super(propertySources);
this.sanitizer = sanitizer;
}
@ -163,6 +162,7 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
String value = super.getPropertyAsRawString(key);
return (String) this.sanitizer.sanitize(key, value);
}
}
}

View File

@ -25,6 +25,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@ -97,13 +98,11 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
this.order = order;
}
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
long startTime = System.currentTimeMillis();
long startTime = System.nanoTime();
Map<String, Object> trace = getTrace(request);
logTrace(request, trace);
int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
@ -112,8 +111,7 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
status = response.getStatus();
}
finally {
long endTime = System.currentTimeMillis();
addTimeTaken(startTime, endTime, trace);
addTimeTaken(trace, startTime);
enhanceTrace(trace, status == response.getStatus() ? response
: new CustomStatusResponseWrapper(response, status));
this.repository.add(trace);
@ -200,9 +198,10 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
protected void postProcessRequestHeaders(Map<String, Object> headers) {
}
private void addTimeTaken(long startTime, long endTime, Map<String, Object> trace) {
long timeTaken = endTime - startTime;
add(trace, Include.TIME_TAKEN, "timeTaken", String.valueOf(timeTaken));
private void addTimeTaken(Map<String, Object> trace, long startTime) {
long timeTaken = System.nanoTime() - startTime;
add(trace, Include.TIME_TAKEN, "timeTaken",
"" + TimeUnit.NANOSECONDS.toMillis(timeTaken));
}
@SuppressWarnings("unchecked")

View File

@ -138,7 +138,8 @@ public class EnvironmentMvcEndpointTests {
}
@Test
public void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() throws Exception {
public void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty()
throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("my.foo", "${my.bar}");
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()

View File

@ -250,8 +250,8 @@ public class WebRequestTraceFilterTests {
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain chain = new MockFilterChain();
this.filter.doFilter(request, response, chain);
String timeTaken = (String) this.repository.findAll()
.iterator().next().getInfo().get("timeTaken");
String timeTaken = (String) this.repository.findAll().iterator().next().getInfo()
.get("timeTaken");
assertThat(timeTaken).isNotNull();
}

View File

@ -40,8 +40,7 @@ class HazelcastJCacheCustomizationConfiguration {
@Bean
public HazelcastPropertiesCustomizer hazelcastPropertiesCustomizer(
ObjectProvider<HazelcastInstance> hazelcastInstance) {
return new HazelcastPropertiesCustomizer(
hazelcastInstance.getIfUnique());
return new HazelcastPropertiesCustomizer(hazelcastInstance.getIfUnique());
}
private static class HazelcastPropertiesCustomizer
@ -72,8 +71,8 @@ class HazelcastJCacheCustomizationConfiguration {
return config.getURI();
}
catch (IOException ex) {
throw new IllegalArgumentException(
"Could not get URI from " + config, ex);
throw new IllegalArgumentException("Could not get URI from " + config,
ex);
}
}

View File

@ -499,7 +499,8 @@ public class CacheAutoConfigurationTests {
load(DefaultCacheConfiguration.class, "spring.cache.type=jcache",
"spring.cache.jcache.provider=" + cachingProviderFqn,
"spring.cache.jcache.config=" + configLocation);
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
JCacheCacheManager cacheManager = validateCacheManager(
JCacheCacheManager.class);
Resource configResource = new ClassPathResource(configLocation);
assertThat(cacheManager.getCacheManager().getURI())
@ -515,14 +516,15 @@ public class CacheAutoConfigurationTests {
public void hazelcastAsJCacheWithExistingHazelcastInstance() throws IOException {
String cachingProviderFqn = HazelcastCachingProvider.class.getName();
load(new Class[] { HazelcastAutoConfiguration.class,
DefaultCacheConfiguration.class }, "spring.cache.type=jcache",
DefaultCacheConfiguration.class }, "spring.cache.type=jcache",
"spring.cache.jcache.provider=" + cachingProviderFqn);
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
javax.cache.CacheManager jCacheManager = cacheManager.getCacheManager();
assertThat(jCacheManager).isInstanceOf(
com.hazelcast.cache.HazelcastCacheManager.class);
assertThat(jCacheManager)
.isInstanceOf(com.hazelcast.cache.HazelcastCacheManager.class);
assertThat(this.context.getBeansOfType(HazelcastInstance.class)).hasSize(1);
HazelcastInstance hazelcastInstance = this.context.getBean(HazelcastInstance.class);
HazelcastInstance hazelcastInstance = this.context
.getBean(HazelcastInstance.class);
assertThat(((com.hazelcast.cache.HazelcastCacheManager) jCacheManager)
.getHazelcastInstance()).isSameAs(hazelcastInstance);
assertThat(hazelcastInstance.getName()).isEqualTo("default-instance");
@ -596,7 +598,8 @@ public class CacheAutoConfigurationTests {
load(JCacheWithCustomizerConfiguration.class, "spring.cache.type=jcache",
"spring.cache.jcache.provider=" + cachingProviderFqn,
"spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar");
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
JCacheCacheManager cacheManager = validateCacheManager(
JCacheCacheManager.class);
// see customizer
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "custom1");
}

View File

@ -104,40 +104,43 @@ public class TransactionAutoConfigurationTests {
assertThat(field).hasSize(1).first().isInstanceOf(TransactionProperties.class);
}
@Test
public void transactionNotManagedWithNoTransactionManager() {
load(BaseConfiguration.class);
assertThat(this.context.getBean(TransactionalService.class)
.isTransactionActive()).isFalse();
assertThat(this.context.getBean(TransactionalService.class).isTransactionActive())
.isFalse();
}
@Test
public void transactionManagerUsesCglibByDefault() {
load(TransactionManagersConfiguration.class);
assertThat(this.context.getBean(AnotherServiceImpl.class)
.isTransactionActive()).isTrue();
assertThat(this.context.getBeansOfType(TransactionalServiceImpl.class)).hasSize(1);
assertThat(this.context.getBean(AnotherServiceImpl.class).isTransactionActive())
.isTrue();
assertThat(this.context.getBeansOfType(TransactionalServiceImpl.class))
.hasSize(1);
}
@Test
public void transactionManagerCanBeConfiguredToJdkProxy() {
load(TransactionManagersConfiguration.class, "spring.aop.proxy-target-class=false");
assertThat(this.context.getBean(AnotherService.class)
.isTransactionActive()).isTrue();
load(TransactionManagersConfiguration.class,
"spring.aop.proxy-target-class=false");
assertThat(this.context.getBean(AnotherService.class).isTransactionActive())
.isTrue();
assertThat(this.context.getBeansOfType(AnotherServiceImpl.class)).hasSize(0);
assertThat(this.context.getBeansOfType(TransactionalServiceImpl.class)).hasSize(0);
assertThat(this.context.getBeansOfType(TransactionalServiceImpl.class))
.hasSize(0);
}
@Test
public void customEnableTransactionManagementTakesPrecedence() {
load(new Class<?>[] { CustomTransactionManagementConfiguration.class,
TransactionManagersConfiguration.class },
TransactionManagersConfiguration.class },
"spring.aop.proxy-target-class=true");
assertThat(this.context.getBean(AnotherService.class)
.isTransactionActive()).isTrue();
assertThat(this.context.getBean(AnotherService.class).isTransactionActive())
.isTrue();
assertThat(this.context.getBeansOfType(AnotherServiceImpl.class)).hasSize(0);
assertThat(this.context.getBeansOfType(TransactionalServiceImpl.class)).hasSize(0);
assertThat(this.context.getBeansOfType(TransactionalServiceImpl.class))
.hasSize(0);
}
private void load(Class<?> config, String... environment) {
@ -235,11 +238,11 @@ public class TransactionAutoConfigurationTests {
static class TransactionalServiceImpl implements TransactionalService {
@Override
public boolean isTransactionActive() {
return TransactionSynchronizationManager.isActualTransactionActive();
}
}
interface AnotherService {
@ -250,12 +253,12 @@ public class TransactionAutoConfigurationTests {
static class AnotherServiceImpl implements AnotherService {
@Override
@Transactional
public boolean isTransactionActive() {
return TransactionSynchronizationManager.isActualTransactionActive();
}
}
}

View File

@ -1,17 +1,12 @@
<hazelcast
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.7.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.7.xsd"
xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<instance-name>default-instance</instance-name>
<map name="defaultCache" />
<network>
<join>
<tcp-ip enabled="false"/>
<multicast enabled="false"/>
<tcp-ip enabled="false" />
<multicast enabled="false" />
</join>
</network>
</hazelcast>

View File

@ -602,7 +602,8 @@ those values (so you can use anything that is legal in a URL path). For example,
the location of the `/health` endpoint to `/ping/me` you can set
`endpoints.health.path=/ping/me`.
NOTE: Even if an endpoint path is configured separately, it is still relative to the `management.context-path`.
NOTE: Even if an endpoint path is configured separately, it is still relative to the
`management.context-path`.
TIP: If you provide a custom `MvcEndpoint` remember to include a settable `path` property,
and default it to `/{id}` if you want your code to behave like the standard MVC endpoints.

View File

@ -46,6 +46,7 @@ public class UnauthenticatedAccessExample {
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**").authorizeRequests().anyRequest().authenticated();
}
}
// end::configuration[]

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -260,7 +260,7 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
return new ShutdownHandler();
}
ch.qos.logback.classic.Logger getLogger(String name) {
private ch.qos.logback.classic.Logger getLogger(String name) {
LoggerContext factory = getLoggerContext();
if (StringUtils.isEmpty(name) || ROOT_LOGGER_NAME.equals(name)) {
name = Logger.ROOT_LOGGER_NAME;

View File

@ -315,18 +315,20 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
keyPassword = ssl.getKeyStorePassword().toCharArray();
}
keyManagerFactory.init(keyStore, keyPassword);
return getConfigurableAliasKeyManagers(ssl, keyManagerFactory.getKeyManagers());
return getConfigurableAliasKeyManagers(ssl,
keyManagerFactory.getKeyManagers());
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
private KeyManager[] getConfigurableAliasKeyManagers(Ssl ssl, KeyManager[] keyManagers) {
private KeyManager[] getConfigurableAliasKeyManagers(Ssl ssl,
KeyManager[] keyManagers) {
for (int i = 0; i < keyManagers.length; i++) {
if (keyManagers[i] instanceof X509ExtendedKeyManager) {
keyManagers[i] = new ConfigurableAliasKeyManager((X509ExtendedKeyManager) keyManagers[i],
ssl.getKeyAlias());
keyManagers[i] = new ConfigurableAliasKeyManager(
(X509ExtendedKeyManager) keyManagers[i], ssl.getKeyAlias());
}
}
return keyManagers;
@ -709,54 +711,66 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
}
}
/**
* {@link X509ExtendedKeyManager} that supports custom alias configuration.
*/
private static class ConfigurableAliasKeyManager extends X509ExtendedKeyManager {
private final X509ExtendedKeyManager sourceKeyManager;
private final X509ExtendedKeyManager keyManager;
private final String alias;
ConfigurableAliasKeyManager(X509ExtendedKeyManager keyManager, String alias) {
this.sourceKeyManager = keyManager;
this.keyManager = keyManager;
this.alias = alias;
}
@Override
public String chooseEngineClientAlias(String[] strings, Principal[] principals, SSLEngine sslEngine) {
return this.sourceKeyManager.chooseEngineClientAlias(strings, principals, sslEngine);
public String chooseEngineClientAlias(String[] strings, Principal[] principals,
SSLEngine sslEngine) {
return this.keyManager.chooseEngineClientAlias(strings, principals,
sslEngine);
}
@Override
public String chooseEngineServerAlias(String s, Principal[] principals, SSLEngine sslEngine) {
public String chooseEngineServerAlias(String s, Principal[] principals,
SSLEngine sslEngine) {
if (this.alias == null) {
return this.sourceKeyManager.chooseEngineServerAlias(s, principals, sslEngine);
return this.keyManager.chooseEngineServerAlias(s, principals, sslEngine);
}
return this.alias;
}
@Override
public String chooseClientAlias(String[] keyType, Principal[] issuers,
Socket socket) {
return this.sourceKeyManager.chooseClientAlias(keyType, issuers, socket);
return this.keyManager.chooseClientAlias(keyType, issuers, socket);
}
@Override
public String chooseServerAlias(String keyType, Principal[] issuers,
Socket socket) {
return this.sourceKeyManager.chooseServerAlias(keyType, issuers, socket);
return this.keyManager.chooseServerAlias(keyType, issuers, socket);
}
@Override
public X509Certificate[] getCertificateChain(String alias) {
return this.sourceKeyManager.getCertificateChain(alias);
return this.keyManager.getCertificateChain(alias);
}
@Override
public String[] getClientAliases(String keyType, Principal[] issuers) {
return this.sourceKeyManager.getClientAliases(keyType, issuers);
return this.keyManager.getClientAliases(keyType, issuers);
}
@Override
public PrivateKey getPrivateKey(String alias) {
return this.sourceKeyManager.getPrivateKey(alias);
return this.keyManager.getPrivateKey(alias);
}
@Override
public String[] getServerAliases(String keyType, Principal[] issuers) {
return this.sourceKeyManager.getServerAliases(keyType, issuers);
return this.keyManager.getServerAliases(keyType, issuers);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.
@ -211,7 +211,8 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
public void getLoggingConfigurationForALL() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(this.initializationContext, null, null);
Logger logger = this.loggingSystem.getLogger(getClass().getName());
Logger logger = (Logger) StaticLoggerBinder.getSingleton().getLoggerFactory()
.getLogger(getClass().getName());
logger.setLevel(Level.ALL);
LoggerConfiguration configuration = this.loggingSystem
.getLoggerConfiguration(getClass().getName());
@ -224,7 +225,8 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(this.initializationContext, null, null);
this.loggingSystem.setLogLevel(getClass().getName(), LogLevel.TRACE);
Logger logger = this.loggingSystem.getLogger(getClass().getName());
Logger logger = (Logger) StaticLoggerBinder.getSingleton().getLoggerFactory()
.getLogger(getClass().getName());
assertThat(logger.getLevel()).isEqualTo(Level.TRACE);
}

View File

@ -49,6 +49,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.zip.GZIPInputStream;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.servlet.GenericServlet;
import javax.servlet.ServletContext;
@ -68,6 +69,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HttpContext;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
import org.apache.jasper.EmbeddedServletOptions;
import org.apache.jasper.servlet.JspServlet;
import org.junit.After;
@ -436,21 +438,21 @@ public abstract class AbstractServletWebServerFactoryTests {
@Test
public void sslKeyAlias() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.setSsl(
getSsl(null, "password", "test-alias", "src/test/resources/test.jks"));
this.webServer = factory.getWebServer(
new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
Ssl ssl = getSsl(null, "password", "test-alias", "src/test/resources/test.jks");
factory.setSsl(ssl);
ServletRegistrationBean<ExampleServlet> registration = new ServletRegistrationBean<>(
new ExampleServlet(true, false), "/hello");
this.webServer = factory.getWebServer(registration);
this.webServer.start();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder().loadTrustMaterial(null,
new SerialNumberValidatingTrustSelfSignedStrategy("77e7c302"))
.build());
HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
httpClient);
assertThat(getResponse(getLocalUrl("https", "/hello"), requestFactory))
.contains("scheme=https");
TrustStrategy trustStrategy = new SerialNumberValidatingTrustSelfSignedStrategy(
"77e7c302");
SSLContext sslContext = new SSLContextBuilder()
.loadTrustMaterial(null, trustStrategy).build();
HttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext)).build();
String response = getResponse(getLocalUrl("https", "/hello"),
new HttpComponentsClientHttpRequestFactory(httpClient));
assertThat(response).contains("scheme=https");
}
@Test