Merge branch '1.5.x'

This commit is contained in:
Phillip Webb
2017-03-06 12:04:55 -08:00
10 changed files with 43 additions and 27 deletions

View File

@@ -38,7 +38,8 @@ class CloudFoundryHealthMvcEndpoint extends HealthMvcEndpoint {
}
@Override
protected boolean exposeHealthDetails(HttpServletRequest request, Principal principal) {
protected boolean exposeHealthDetails(HttpServletRequest request,
Principal principal) {
return true;
}

View File

@@ -183,7 +183,8 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
return (accessTime - this.lastAccess) >= getDelegate().getTimeToLive();
}
protected boolean exposeHealthDetails(HttpServletRequest request, Principal principal) {
protected boolean exposeHealthDetails(HttpServletRequest request,
Principal principal) {
if (!this.secure) {
return true;
}
@@ -192,7 +193,7 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
if (request.isUserInRole(role)) {
return true;
}
if (isSpringSecurityAuthentication(principal)) {
if (isSpringSecurityAuthentication(principal)) {
Authentication authentication = (Authentication) principal;
for (GrantedAuthority authority : authentication.getAuthorities()) {
String name = authority.getAuthority();
@@ -217,7 +218,7 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
private boolean isSpringSecurityAuthentication(Principal principal) {
return ClassUtils.isPresent("org.springframework.security.core.Authentication",
null) && (principal instanceof Authentication);
null) && principal instanceof Authentication;
}
}

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

@@ -167,7 +167,8 @@ public class HealthMvcEndpointTests {
public void rightAuthorityPresentShouldExposeDetails() throws Exception {
this.environment.getPropertySources().addLast(SECURITY_ROLES);
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();
given(this.endpoint.invoke())
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build());

View File

@@ -67,13 +67,15 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
}
@Test
public void healthWhenRightRoleNotPresentShouldExposeHealthDetails() throws Exception {
public void healthWhenRightRoleNotPresentShouldExposeHealthDetails()
throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(TestConfiguration.class);
this.context.refresh();
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\"")));
}
@@ -93,12 +95,15 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
private RequestPostProcessor getRequestPostProcessor() {
return new RequestPostProcessor() {
@Override
public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
public MockHttpServletRequest postProcessRequest(
MockHttpServletRequest request) {
Principal principal = mock(Principal.class);
request.setUserPrincipal(principal);
return request;
}
};
}
@@ -117,6 +122,7 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
public Health health() {
return Health.up().withDetail("hello", "world").build();
}
};
}