parent
b2250f4ad8
commit
8bef0a1e60
|
@ -27,10 +27,13 @@ import org.springframework.util.Assert;
|
||||||
* {@link HealthIndicator} for configured LDAP server(s).
|
* {@link HealthIndicator} for configured LDAP server(s).
|
||||||
*
|
*
|
||||||
* @author Eddú Meléndez
|
* @author Eddú Meléndez
|
||||||
|
* @author Stephane Nicoll
|
||||||
* @version 1.5.0
|
* @version 1.5.0
|
||||||
*/
|
*/
|
||||||
public class LdapHealthIndicator extends AbstractHealthIndicator {
|
public class LdapHealthIndicator extends AbstractHealthIndicator {
|
||||||
|
|
||||||
|
private static final ContextExecutor<String> versionContextExecutor = new VersionContextExecutor();
|
||||||
|
|
||||||
private final LdapOperations ldapOperations;
|
private final LdapOperations ldapOperations;
|
||||||
|
|
||||||
public LdapHealthIndicator(LdapOperations ldapOperations) {
|
public LdapHealthIndicator(LdapOperations ldapOperations) {
|
||||||
|
@ -40,13 +43,20 @@ public class LdapHealthIndicator extends AbstractHealthIndicator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||||
String version = (String) this.ldapOperations.executeReadOnly(new ContextExecutor<Object>() {
|
String version = this.ldapOperations.executeReadOnly(versionContextExecutor);
|
||||||
@Override
|
|
||||||
public Object executeWithContext(DirContext ctx) throws NamingException {
|
|
||||||
return ctx.getEnvironment().get("java.naming.ldap.version");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.up().withDetail("version", version);
|
builder.up().withDetail("version", version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class VersionContextExecutor implements ContextExecutor<String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String executeWithContext(DirContext ctx) throws NamingException {
|
||||||
|
Object version = ctx.getEnvironment().get("java.naming.ldap.version");
|
||||||
|
if (version != null) {
|
||||||
|
return (String) version;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -641,8 +641,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public LdapOperations ldapOperations() {
|
public LdapOperations ldapOperations() {
|
||||||
LdapOperations operations = mock(LdapOperations.class);
|
return mock(LdapOperations.class);
|
||||||
return operations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,13 +59,16 @@ public class LdapHealthIndicatorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void indicatorExist() {
|
public void indicatorExist() {
|
||||||
this.context.register(LdapAutoConfiguration.class, LdapDataAutoConfiguration.class,
|
this.context.register(LdapAutoConfiguration.class,
|
||||||
PropertyPlaceholderAutoConfiguration.class, EndpointAutoConfiguration.class,
|
LdapDataAutoConfiguration.class,
|
||||||
|
PropertyPlaceholderAutoConfiguration.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.class);
|
LdapHealthIndicator healthIndicator = this.context.getBean(
|
||||||
|
LdapHealthIndicator.class);
|
||||||
assertThat(healthIndicator).isNotNull();
|
assertThat(healthIndicator).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +87,8 @@ public class LdapHealthIndicatorTests {
|
||||||
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(any(ContextExecutor.class)))
|
||||||
.willThrow(new CommunicationException(new javax.naming.CommunicationException("Connection failed")));
|
.willThrow(new CommunicationException(
|
||||||
|
new javax.naming.CommunicationException("Connection failed")));
|
||||||
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
|
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
|
||||||
Health health = healthIndicator.health();
|
Health health = healthIndicator.health();
|
||||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||||
|
|
|
@ -1114,6 +1114,7 @@ content into your application; rather pick only the properties that you need.
|
||||||
management.health.elasticsearch.indices= # Comma-separated index names.
|
management.health.elasticsearch.indices= # Comma-separated index names.
|
||||||
management.health.elasticsearch.response-timeout=100 # The time, in milliseconds, to wait for a response from the cluster.
|
management.health.elasticsearch.response-timeout=100 # The time, in milliseconds, to wait for a response from the cluster.
|
||||||
management.health.jms.enabled=true # Enable JMS health check.
|
management.health.jms.enabled=true # Enable JMS health check.
|
||||||
|
management.health.ldap.enabled=true # Enable LDAP health check.
|
||||||
management.health.mail.enabled=true # Enable Mail health check.
|
management.health.mail.enabled=true # Enable Mail health check.
|
||||||
management.health.mongo.enabled=true # Enable MongoDB health check.
|
management.health.mongo.enabled=true # Enable MongoDB health check.
|
||||||
management.health.rabbit.enabled=true # Enable RabbitMQ health check.
|
management.health.rabbit.enabled=true # Enable RabbitMQ health check.
|
||||||
|
|
Loading…
Reference in New Issue