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;
public LdapHealthIndicatorConfiguration(Map<String, LdapOperations> ldapOperations) {
public LdapHealthIndicatorConfiguration(
Map<String, LdapOperations> ldapOperations) {
this.ldapOperations = ldapOperations;
}

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

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

@ -62,31 +62,33 @@ public class LdapHealthIndicatorTests {
this.context.register(LdapAutoConfiguration.class,
LdapDataAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
EndpointAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class);
EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
LdapTemplate ldapTemplate = this.context.getBean(LdapTemplate.class);
assertThat(ldapTemplate).isNotNull();
LdapHealthIndicator healthIndicator = this.context.getBean(
LdapHealthIndicator.class);
LdapHealthIndicator healthIndicator = this.context
.getBean(LdapHealthIndicator.class);
assertThat(healthIndicator).isNotNull();
}
@Test
@SuppressWarnings("unchecked")
public void ldapIsUp() {
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);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("version")).isEqualTo("3");
verify(ldapTemplate).executeReadOnly(any(ContextExecutor.class));
verify(ldapTemplate).executeReadOnly((ContextExecutor<String>) any());
}
@Test
@SuppressWarnings("unchecked")
public void ldapIsDown() {
LdapTemplate ldapTemplate = mock(LdapTemplate.class);
given(ldapTemplate.executeReadOnly(any(ContextExecutor.class)))
given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any()))
.willThrow(new CommunicationException(
new javax.naming.CommunicationException("Connection failed")));
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
@ -94,7 +96,7 @@ public class LdapHealthIndicatorTests {
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat((String) health.getDetails().get("error"))
.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;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's LDAP
* Repositories.
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's LDAP Repositories.
*
* @author Eddú Meléndez
* @since 1.5.0

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

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

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

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

@ -220,7 +220,7 @@ public class ResourceServerTokenServicesConfigurationTests {
"security.oauth2.resource.userInfoUri:http://example.com");
this.context = new SpringApplicationBuilder(
CustomUserInfoRestTemplateFactory.class, ResourceConfiguration.class)
.environment(this.environment).web(false).run();
.environment(this.environment).web(false).run();
assertThat(this.context.getBeansOfType(UserInfoRestTemplateFactory.class))
.hasSize(1);
assertThat(this.context.getBean(UserInfoRestTemplateFactory.class))
@ -331,8 +331,8 @@ public class ResourceServerTokenServicesConfigurationTests {
protected static class CustomUserInfoRestTemplateFactory
implements UserInfoRestTemplateFactory {
private final OAuth2RestTemplate restTemplate =
new OAuth2RestTemplate(new AuthorizationCodeResourceDetails());
private final OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(
new AuthorizationCodeResourceDetails());
@Override
public OAuth2RestTemplate getUserInfoRestTemplate() {

Loading…
Cancel
Save