com.yammer.dropwizard.authenticator.healthchecks.LdapHealthCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-auth-ldap Show documentation
Show all versions of dropwizard-auth-ldap Show documentation
Dropwizard Authentication Module for LDAP using JNDI
package com.yammer.dropwizard.authenticator.healthchecks;
import com.codahale.metrics.health.HealthCheck;
import io.dropwizard.auth.AuthenticationException;
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.basic.BasicCredentials;
import java.security.Principal;
import static com.google.common.base.Preconditions.checkNotNull;
public class LdapHealthCheck extends HealthCheck {
private final Authenticator ldapAuthenticator;
public LdapHealthCheck(Authenticator ldapAuthenticator) {
this.ldapAuthenticator = checkNotNull(ldapAuthenticator, "ldapAuthenticator cannot be null");
}
@Override
public Result check() throws AuthenticationException {
if (ldapAuthenticator.authenticate(new BasicCredentials("", "")).isPresent()) {
return Result.healthy();
} else {
return Result.unhealthy("Cannot contact authentication service");
}
}
}