All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yammer.dropwizard.authenticator.healthchecks.LdapHealthCheck Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
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");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy