Search in sources :

Example 1 with InitializableWebObject

use of org.pac4j.core.util.InitializableWebObject in project cas by apereo.

the class AbstractWrapperAuthenticationHandler method doAuthentication.

@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    CommonHelper.assertNotNull("profileCreator", this.profileCreator);
    final C credentials = convertToPac4jCredentials((I) credential);
    LOGGER.debug("credentials: [{}]", credentials);
    try {
        final Authenticator authenticator = getAuthenticator(credential);
        if (authenticator instanceof InitializableObject) {
            ((InitializableObject) authenticator).init();
        }
        if (authenticator instanceof InitializableWebObject) {
            ((InitializableWebObject) authenticator).init(getWebContext());
        }
        CommonHelper.assertNotNull("authenticator", authenticator);
        authenticator.validate(credentials, getWebContext());
        final UserProfile profile = this.profileCreator.create(credentials, getWebContext());
        LOGGER.debug("profile: [{}]", profile);
        return createResult(new ClientCredential(credentials), profile);
    } catch (final Exception e) {
        LOGGER.error("Failed to validate credentials", e);
        throw new FailedLoginException("Failed to validate credentials: " + e.getMessage());
    }
}
Also used : ClientCredential(org.apereo.cas.authentication.principal.ClientCredential) FailedLoginException(javax.security.auth.login.FailedLoginException) UserProfile(org.pac4j.core.profile.UserProfile) InitializableObject(org.pac4j.core.util.InitializableObject) Authenticator(org.pac4j.core.credentials.authenticator.Authenticator) InitializableWebObject(org.pac4j.core.util.InitializableWebObject) GeneralSecurityException(java.security.GeneralSecurityException) FailedLoginException(javax.security.auth.login.FailedLoginException) PreventedException(org.apereo.cas.authentication.PreventedException)

Aggregations

GeneralSecurityException (java.security.GeneralSecurityException)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 PreventedException (org.apereo.cas.authentication.PreventedException)1 ClientCredential (org.apereo.cas.authentication.principal.ClientCredential)1 Authenticator (org.pac4j.core.credentials.authenticator.Authenticator)1 UserProfile (org.pac4j.core.profile.UserProfile)1 InitializableObject (org.pac4j.core.util.InitializableObject)1 InitializableWebObject (org.pac4j.core.util.InitializableWebObject)1