Created
May 26, 2017 16:33
-
-
Save dfish3r/66bd81ed1294780e00b0a9177fa97ec9 to your computer and use it in GitHub Desktop.
Ldaptive AuthenticationHandler for Active Directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.ldaptive.LdapException; | |
import org.ldaptive.auth.AuthenticationCriteria; | |
import org.ldaptive.auth.AuthenticationHandler; | |
import org.ldaptive.auth.AuthenticationHandlerResponse; | |
/** | |
* Provides an LDAP authentication implementation that wraps the invocation of another handler and then inspects the | |
* response. If the response result is false and it contains the {@link ActiveDirectoryAccountState.Error#ACCOUNT_EXPIRED} | |
* error, then the response result is changed from false to true. | |
* | |
* @author Middleware Services | |
*/ | |
public class ActiveDirectoryAuthenticationHandler implements AuthenticationHandler | |
{ | |
/** Authentication handler to invoke. */ | |
private final AuthenticationHandler authHandler; | |
/** | |
* Creates a new active directory authentication handler. | |
* | |
* @param ah authentication handler | |
*/ | |
public ActiveDirectoryAuthenticationHandler(final AuthenticationHandler ah) | |
{ | |
authHandler = ah; | |
} | |
@Override | |
public AuthenticationHandlerResponse authenticate(final AuthenticationCriteria criteria) | |
throws LdapException | |
{ | |
AuthenticationHandlerResponse response = authHandler.authenticate(criteria); | |
if (response != null && !response.getResult() && response.getMessage() != null) { | |
final ActiveDirectoryAccountState.Error adError = ActiveDirectoryAccountState.Error.parse(response.getMessage()); | |
if (ActiveDirectoryAccountState.Error.ACCOUNT_EXPIRED.equals(adError)) { | |
response = new AuthenticationHandlerResponse( | |
true, | |
response.getResultCode(), | |
response.getConnection(), | |
response.getMessage(), | |
response.getControls(), | |
response.getMessageId()); | |
} | |
} | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment