Commit 91a7bf92 authored by Phillip Webb's avatar Phillip Webb

Merge branch '1.5.x'

parents dcf7e11d fedd7b95
...@@ -38,7 +38,8 @@ class CloudFoundryHealthMvcEndpoint extends HealthMvcEndpoint { ...@@ -38,7 +38,8 @@ class CloudFoundryHealthMvcEndpoint extends HealthMvcEndpoint {
} }
@Override @Override
protected boolean exposeHealthDetails(HttpServletRequest request, Principal principal) { protected boolean exposeHealthDetails(HttpServletRequest request,
Principal principal) {
return true; return true;
} }
......
...@@ -183,7 +183,8 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint ...@@ -183,7 +183,8 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
return (accessTime - this.lastAccess) >= getDelegate().getTimeToLive(); return (accessTime - this.lastAccess) >= getDelegate().getTimeToLive();
} }
protected boolean exposeHealthDetails(HttpServletRequest request, Principal principal) { protected boolean exposeHealthDetails(HttpServletRequest request,
Principal principal) {
if (!this.secure) { if (!this.secure) {
return true; return true;
} }
...@@ -217,7 +218,7 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint ...@@ -217,7 +218,7 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
private boolean isSpringSecurityAuthentication(Principal principal) { private boolean isSpringSecurityAuthentication(Principal principal) {
return ClassUtils.isPresent("org.springframework.security.core.Authentication", return ClassUtils.isPresent("org.springframework.security.core.Authentication",
null) && (principal instanceof Authentication); null) && principal instanceof Authentication;
} }
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
...@@ -167,7 +167,8 @@ public class HealthMvcEndpointTests { ...@@ -167,7 +167,8 @@ public class HealthMvcEndpointTests {
public void rightAuthorityPresentShouldExposeDetails() throws Exception { public void rightAuthorityPresentShouldExposeDetails() throws Exception {
this.environment.getPropertySources().addLast(SECURITY_ROLES); this.environment.getPropertySources().addLast(SECURITY_ROLES);
Authentication principal = mock(Authentication.class); Authentication principal = mock(Authentication.class);
Set<SimpleGrantedAuthority> authorities = Collections.singleton(new SimpleGrantedAuthority("HERO")); Set<SimpleGrantedAuthority> authorities = Collections
.singleton(new SimpleGrantedAuthority("HERO"));
doReturn(authorities).when(principal).getAuthorities(); doReturn(authorities).when(principal).getAuthorities();
given(this.endpoint.invoke()) given(this.endpoint.invoke())
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
......
...@@ -67,13 +67,15 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests { ...@@ -67,13 +67,15 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
} }
@Test @Test
public void healthWhenRightRoleNotPresentShouldExposeHealthDetails() throws Exception { public void healthWhenRightRoleNotPresentShouldExposeHealthDetails()
throws Exception {
this.context = new AnnotationConfigWebApplicationContext(); this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext()); this.context.setServletContext(new MockServletContext());
this.context.register(TestConfiguration.class); this.context.register(TestConfiguration.class);
this.context.refresh(); this.context.refresh();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build(); MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
mockMvc.perform(get("/health").with(getRequestPostProcessor())).andExpect(status().isOk()) mockMvc.perform(get("/health").with(getRequestPostProcessor()))
.andExpect(status().isOk())
.andExpect(content().string(containsString("\"status\":\"UP\""))); .andExpect(content().string(containsString("\"status\":\"UP\"")));
} }
...@@ -93,12 +95,15 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests { ...@@ -93,12 +95,15 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
private RequestPostProcessor getRequestPostProcessor() { private RequestPostProcessor getRequestPostProcessor() {
return new RequestPostProcessor() { return new RequestPostProcessor() {
@Override @Override
public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { public MockHttpServletRequest postProcessRequest(
MockHttpServletRequest request) {
Principal principal = mock(Principal.class); Principal principal = mock(Principal.class);
request.setUserPrincipal(principal); request.setUserPrincipal(principal);
return request; return request;
} }
}; };
} }
...@@ -117,6 +122,7 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests { ...@@ -117,6 +122,7 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
public Health health() { public Health health() {
return Health.up().withDetail("hello", "world").build(); return Health.up().withDetail("hello", "world").build();
} }
}; };
} }
......
...@@ -40,6 +40,9 @@ public class MongoProperties { ...@@ -40,6 +40,9 @@ public class MongoProperties {
*/ */
public static final int DEFAULT_PORT = 27017; public static final int DEFAULT_PORT = 27017;
/**
* Default URI used when the configured URI is {@code null}.
*/
public static final String DEFAULT_URI = "mongodb://localhost/test"; public static final String DEFAULT_URI = "mongodb://localhost/test";
/** /**
......
...@@ -145,25 +145,21 @@ public class EmbeddedServletContainerAutoConfiguration { ...@@ -145,25 +145,21 @@ public class EmbeddedServletContainerAutoConfiguration {
if (this.beanFactory == null) { if (this.beanFactory == null) {
return; return;
} }
if (ObjectUtils.isEmpty(this.beanFactory.getBeanNamesForType( registerSyntheticBeanIfMissing(registry,
EmbeddedServletContainerCustomizerBeanPostProcessor.class, true,
false))) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
EmbeddedServletContainerCustomizerBeanPostProcessor.class);
beanDefinition.setSynthetic(true);
registry.registerBeanDefinition(
"embeddedServletContainerCustomizerBeanPostProcessor", "embeddedServletContainerCustomizerBeanPostProcessor",
beanDefinition); EmbeddedServletContainerCustomizerBeanPostProcessor.class);
registerSyntheticBeanIfMissing(registry,
} "errorPageRegistrarBeanPostProcessor",
if (ObjectUtils.isEmpty(this.beanFactory.getBeanNamesForType(
ErrorPageRegistrarBeanPostProcessor.class, true, false))) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
ErrorPageRegistrarBeanPostProcessor.class); ErrorPageRegistrarBeanPostProcessor.class);
beanDefinition.setSynthetic(true); }
registry.registerBeanDefinition("errorPageRegistrarBeanPostProcessor",
beanDefinition);
private void registerSyntheticBeanIfMissing(BeanDefinitionRegistry registry,
String name, Class<?> beanClass) {
if (ObjectUtils.isEmpty(
this.beanFactory.getBeanNamesForType(beanClass, true, false))) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
beanDefinition.setSynthetic(true);
registry.registerBeanDefinition(name, beanDefinition);
} }
} }
......
...@@ -27,6 +27,7 @@ import org.springframework.beans.factory.BeanFactoryAware; ...@@ -27,6 +27,7 @@ import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.util.Assert;
/** /**
* {@link BeanPostProcessor} that applies all {@link EmbeddedServletContainerCustomizer}s * {@link BeanPostProcessor} that applies all {@link EmbeddedServletContainerCustomizer}s
...@@ -45,6 +46,9 @@ public class EmbeddedServletContainerCustomizerBeanPostProcessor ...@@ -45,6 +46,9 @@ public class EmbeddedServletContainerCustomizerBeanPostProcessor
@Override @Override
public void setBeanFactory(BeanFactory beanFactory) { public void setBeanFactory(BeanFactory beanFactory) {
Assert.isInstanceOf(ListableBeanFactory.class, beanFactory,
"EmbeddedServletContainerCustomizerBeanPostProcessor can only be used "
+ "with a ListableBeanFactory");
this.beanFactory = (ListableBeanFactory) beanFactory; this.beanFactory = (ListableBeanFactory) beanFactory;
} }
......
...@@ -27,6 +27,7 @@ import org.springframework.beans.factory.BeanFactoryAware; ...@@ -27,6 +27,7 @@ import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.util.Assert;
/** /**
* {@link BeanPostProcessor} that applies all {@link ErrorPageRegistrar}s from the bean * {@link BeanPostProcessor} that applies all {@link ErrorPageRegistrar}s from the bean
...@@ -45,6 +46,9 @@ public class ErrorPageRegistrarBeanPostProcessor ...@@ -45,6 +46,9 @@ public class ErrorPageRegistrarBeanPostProcessor
@Override @Override
public void setBeanFactory(BeanFactory beanFactory) { public void setBeanFactory(BeanFactory beanFactory) {
Assert.isInstanceOf(ListableBeanFactory.class, beanFactory,
"ErrorPageRegistrarBeanPostProcessor can only be used "
+ "with a ListableBeanFactory");
this.beanFactory = (ListableBeanFactory) beanFactory; this.beanFactory = (ListableBeanFactory) beanFactory;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment