pull/8038/head
Phillip Webb 8 years ago
parent d1a8d136a7
commit 43d432a527

@ -244,7 +244,8 @@ public class HealthIndicatorAutoConfiguration {
private final Map<String, LdapOperations> ldapOperations; private final Map<String, LdapOperations> ldapOperations;
public LdapHealthIndicatorConfiguration(Map<String, LdapOperations> ldapOperations) { public LdapHealthIndicatorConfiguration(
Map<String, LdapOperations> ldapOperations) {
this.ldapOperations = ldapOperations; this.ldapOperations = ldapOperations;
} }

@ -57,6 +57,7 @@ public class LdapHealthIndicator extends AbstractHealthIndicator {
} }
return null; return null;
} }
} }
} }

@ -541,8 +541,8 @@ public class HealthIndicatorAutoConfigurationTests {
public void ldapHealthIndicator() throws Exception { public void ldapHealthIndicator() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false"); "management.health.diskspace.enabled:false");
this.context.register(LdapConfiguration.class, this.context.register(LdapConfiguration.class, ManagementServerProperties.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); HealthIndicatorAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
Map<String, HealthIndicator> beans = this.context Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class); .getBeansOfType(HealthIndicator.class);
@ -556,8 +556,8 @@ public class HealthIndicatorAutoConfigurationTests {
EnvironmentTestUtils.addEnvironment(this.context, EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false", "management.health.diskspace.enabled:false",
"management.health.ldap.enabled:false"); "management.health.ldap.enabled:false");
this.context.register(LdapConfiguration.class, this.context.register(LdapConfiguration.class, ManagementServerProperties.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); HealthIndicatorAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
Map<String, HealthIndicator> beans = this.context Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class); .getBeansOfType(HealthIndicator.class);

@ -62,31 +62,33 @@ public class LdapHealthIndicatorTests {
this.context.register(LdapAutoConfiguration.class, this.context.register(LdapAutoConfiguration.class,
LdapDataAutoConfiguration.class, LdapDataAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
EndpointAutoConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
HealthIndicatorAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
LdapTemplate ldapTemplate = this.context.getBean(LdapTemplate.class); LdapTemplate ldapTemplate = this.context.getBean(LdapTemplate.class);
assertThat(ldapTemplate).isNotNull(); assertThat(ldapTemplate).isNotNull();
LdapHealthIndicator healthIndicator = this.context.getBean( LdapHealthIndicator healthIndicator = this.context
LdapHealthIndicator.class); .getBean(LdapHealthIndicator.class);
assertThat(healthIndicator).isNotNull(); assertThat(healthIndicator).isNotNull();
} }
@Test @Test
@SuppressWarnings("unchecked")
public void ldapIsUp() { public void ldapIsUp() {
LdapTemplate ldapTemplate = mock(LdapTemplate.class); LdapTemplate ldapTemplate = mock(LdapTemplate.class);
given(ldapTemplate.executeReadOnly(any(ContextExecutor.class))).willReturn("3"); given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any()))
.willReturn("3");
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate); LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
Health health = healthIndicator.health(); Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("version")).isEqualTo("3"); assertThat(health.getDetails().get("version")).isEqualTo("3");
verify(ldapTemplate).executeReadOnly(any(ContextExecutor.class)); verify(ldapTemplate).executeReadOnly((ContextExecutor<String>) any());
} }
@Test @Test
@SuppressWarnings("unchecked")
public void ldapIsDown() { public void ldapIsDown() {
LdapTemplate ldapTemplate = mock(LdapTemplate.class); LdapTemplate ldapTemplate = mock(LdapTemplate.class);
given(ldapTemplate.executeReadOnly(any(ContextExecutor.class))) given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any()))
.willThrow(new CommunicationException( .willThrow(new CommunicationException(
new javax.naming.CommunicationException("Connection failed"))); new javax.naming.CommunicationException("Connection failed")));
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate); LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
@ -94,7 +96,7 @@ public class LdapHealthIndicatorTests {
assertThat(health.getStatus()).isEqualTo(Status.DOWN); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat((String) health.getDetails().get("error")) assertThat((String) health.getDetails().get("error"))
.contains("Connection failed"); .contains("Connection failed");
verify(ldapTemplate).executeReadOnly(any(ContextExecutor.class)); verify(ldapTemplate).executeReadOnly((ContextExecutor<String>) any());
} }
} }

@ -28,8 +28,7 @@ import org.springframework.data.ldap.repository.LdapRepository;
import org.springframework.data.ldap.repository.support.LdapRepositoryFactoryBean; import org.springframework.data.ldap.repository.support.LdapRepositoryFactoryBean;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's LDAP * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's LDAP Repositories.
* Repositories.
* *
* @author Eddú Meléndez * @author Eddú Meléndez
* @since 1.5.0 * @since 1.5.0

@ -48,8 +48,8 @@ public class SecurityProperties implements SecurityPrerequisite {
/** /**
* Order applied to the WebSecurityConfigurerAdapter that is used to configure basic * Order applied to the WebSecurityConfigurerAdapter that is used to configure basic
* authentication for application endpoints. If you want to add your own * authentication for application endpoints. If you want to add your own
* authentication for all or some of those endpoints the best thing to do is to add your * authentication for all or some of those endpoints the best thing to do is to add
* own WebSecurityConfigurerAdapter with lower order. * your own WebSecurityConfigurerAdapter with lower order.
*/ */
public static final int BASIC_AUTH_ORDER = Ordered.LOWEST_PRECEDENCE - 5; public static final int BASIC_AUTH_ORDER = Ordered.LOWEST_PRECEDENCE - 5;

@ -66,11 +66,13 @@ public class DefaultUserInfoRestTemplateFactory implements UserInfoRestTemplateF
this.oauth2ClientContext = oauth2ClientContext.getIfAvailable(); this.oauth2ClientContext = oauth2ClientContext.getIfAvailable();
} }
@Override
public OAuth2RestTemplate getUserInfoRestTemplate() { public OAuth2RestTemplate getUserInfoRestTemplate() {
if (this.oauth2RestTemplate == null) { if (this.oauth2RestTemplate == null) {
this.oauth2RestTemplate = createOAuth2RestTemplate( this.oauth2RestTemplate = createOAuth2RestTemplate(
this.details == null ? DEFAULT_RESOURCE_DETAILS : this.details); this.details == null ? DEFAULT_RESOURCE_DETAILS : this.details);
this.oauth2RestTemplate.getInterceptors().add(new AcceptJsonRequestInterceptor()); this.oauth2RestTemplate.getInterceptors()
.add(new AcceptJsonRequestInterceptor());
AuthorizationCodeAccessTokenProvider accessTokenProvider = new AuthorizationCodeAccessTokenProvider(); AuthorizationCodeAccessTokenProvider accessTokenProvider = new AuthorizationCodeAccessTokenProvider();
accessTokenProvider.setTokenRequestEnhancer(new AcceptJsonRequestEnhancer()); accessTokenProvider.setTokenRequestEnhancer(new AcceptJsonRequestEnhancer());
this.oauth2RestTemplate.setAccessTokenProvider(accessTokenProvider); this.oauth2RestTemplate.setAccessTokenProvider(accessTokenProvider);

@ -88,7 +88,8 @@ public class ResourceServerTokenServicesConfiguration {
ObjectProvider<List<UserInfoRestTemplateCustomizer>> customizers, ObjectProvider<List<UserInfoRestTemplateCustomizer>> customizers,
ObjectProvider<OAuth2ProtectedResourceDetails> details, ObjectProvider<OAuth2ProtectedResourceDetails> details,
ObjectProvider<OAuth2ClientContext> oauth2ClientContext) { ObjectProvider<OAuth2ClientContext> oauth2ClientContext) {
return new DefaultUserInfoRestTemplateFactory(customizers, details, oauth2ClientContext); return new DefaultUserInfoRestTemplateFactory(customizers, details,
oauth2ClientContext);
} }
@Configuration @Configuration

@ -222,13 +222,16 @@ public class RepositoryRestMvcAutoConfigurationTests {
} }
static class TestRepositoryRestConfigurer extends RepositoryRestConfigurerAdapter { static class TestRepositoryRestConfigurer extends RepositoryRestConfigurerAdapter {
@Override @Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { public void configureRepositoryRestConfiguration(
RepositoryRestConfiguration config) {
config.setRepositoryDetectionStrategy(RepositoryDetectionStrategies.ALL); config.setRepositoryDetectionStrategy(RepositoryDetectionStrategies.ALL);
config.setDefaultMediaType(MediaType.parseMediaType( config.setDefaultMediaType(
"application/my-custom-json")); MediaType.parseMediaType("application/my-custom-json"));
config.setMaxPageSize(78); config.setMaxPageSize(78);
} }
} }
} }

@ -331,8 +331,8 @@ public class ResourceServerTokenServicesConfigurationTests {
protected static class CustomUserInfoRestTemplateFactory protected static class CustomUserInfoRestTemplateFactory
implements UserInfoRestTemplateFactory { implements UserInfoRestTemplateFactory {
private final OAuth2RestTemplate restTemplate = private final OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(
new OAuth2RestTemplate(new AuthorizationCodeResourceDetails()); new AuthorizationCodeResourceDetails());
@Override @Override
public OAuth2RestTemplate getUserInfoRestTemplate() { public OAuth2RestTemplate getUserInfoRestTemplate() {

Loading…
Cancel
Save