Search in sources :

Example 1 with PwmHttpFilterAuthenticationProvider

use of password.pwm.PwmHttpFilterAuthenticationProvider in project pwm by pwm-project.

the class AuthenticationFilter method attemptAuthenticationMethods.

private static ProcessStatus attemptAuthenticationMethods(final PwmRequest pwmRequest) throws IOException, ServletException {
    if (pwmRequest.isAuthenticated()) {
        return ProcessStatus.Continue;
    }
    for (final AuthenticationMethod authenticationMethod : AuthenticationMethod.values()) {
        if (!IGNORED_AUTH_METHODS.contains(authenticationMethod)) {
            PwmHttpFilterAuthenticationProvider filterAuthenticationProvider = null;
            try {
                final String className = authenticationMethod.getClassName();
                final Class clazz = Class.forName(className);
                final Object newInstance = clazz.newInstance();
                filterAuthenticationProvider = (PwmHttpFilterAuthenticationProvider) newInstance;
            } catch (Exception e) {
                LOGGER.trace("could not load authentication class '" + authenticationMethod + "', will ignore");
                IGNORED_AUTH_METHODS.add(authenticationMethod);
            }
            if (filterAuthenticationProvider != null) {
                try {
                    filterAuthenticationProvider.attemptAuthentication(pwmRequest);
                    if (pwmRequest.isAuthenticated()) {
                        LOGGER.trace(pwmRequest, "authentication provided by method " + authenticationMethod.name());
                    }
                    if (filterAuthenticationProvider.hasRedirectedResponse()) {
                        LOGGER.trace(pwmRequest, "authentication provider " + authenticationMethod.name() + " has issued a redirect, halting authentication process");
                        return ProcessStatus.Halt;
                    }
                } catch (Exception e) {
                    final ErrorInformation errorInformation;
                    if (e instanceof PwmException) {
                        final String errorMsg = "error during " + authenticationMethod + " authentication attempt: " + e.getMessage();
                        errorInformation = new ErrorInformation(((PwmException) e).getError(), errorMsg);
                    } else {
                        errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
                    }
                    LOGGER.error(pwmRequest, errorInformation);
                    pwmRequest.respondWithError(errorInformation);
                    return ProcessStatus.Halt;
                }
            }
        }
    }
    return ProcessStatus.Continue;
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) PwmHttpFilterAuthenticationProvider(password.pwm.PwmHttpFilterAuthenticationProvider) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) PwmOperationalException(password.pwm.error.PwmOperationalException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 PwmHttpFilterAuthenticationProvider (password.pwm.PwmHttpFilterAuthenticationProvider)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmException (password.pwm.error.PwmException)1 PwmOperationalException (password.pwm.error.PwmOperationalException)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1