com.yammer.dropwizard.authenticator.ResourceAuthenticator 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;
import io.dropwizard.auth.AuthenticationException;
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.basic.BasicCredentials;
import java.util.Collections;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
public class ResourceAuthenticator implements Authenticator {
private final LdapAuthenticator ldapAuthenticator;
public ResourceAuthenticator(LdapAuthenticator ldapAuthenticator) {
this.ldapAuthenticator = checkNotNull(ldapAuthenticator);
}
@Override
public Optional authenticate(BasicCredentials credentials) throws AuthenticationException {
if (ldapAuthenticator.authenticate(credentials)) {
return Optional.of(new User(credentials.getUsername(), Collections.emptySet()));
} else {
return Optional.empty();
}
}
}