private AuthenticatedUser authenticateUser(Credentials credentials)
        throws GuacamoleAuthenticationProcessException {

        AuthenticationProvider failedAuthProvider = null;
        GuacamoleCredentialsException authFailure = null;

        // Attempt authentication against each AuthenticationProvider
        for (AuthenticationProvider authProvider : authProviders) {

            // Attempt authentication
            try {
                AuthenticatedUser authenticatedUser = authProvider.authenticateUser(credentials);
                if (authenticatedUser != null)
                    return authenticatedUser;
            }

            // Insufficient credentials should take precedence
            catch (GuacamoleInsufficientCredentialsException e) {
                if (authFailure == null || authFailure instanceof GuacamoleInvalidCredentialsException) {
                    failedAuthProvider = authProvider;
                    authFailure = e;
                }
            }

            // Catch other credentials exceptions and assign the first one
            catch (GuacamoleCredentialsException e) {
                if (authFailure == null) {
                    failedAuthProvider = authProvider;
                    authFailure = e;
                }
            }

            catch (GuacamoleException | RuntimeException | Error e) {
                throw new GuacamoleAuthenticationProcessException("User "
                        + "authentication was aborted.", authProvider, e);
            }

        }

        throw new GuacamoleAuthenticationProcessException("User authentication "
                + "failed.", failedAuthProvider, authFailure);

    }
Attempts authentication against all AuthenticationProviders, in order,
using the provided credentials. The first authentication failure takes
priority, but remaining AuthenticationProviders are attempted. If any
AuthenticationProvider succeeds, the resulting AuthenticatedUser is
returned, and no further AuthenticationProviders are tried.

@param credentials
    The credentials to use for authentication.

@return
    The AuthenticatedUser given by the highest-priority
    AuthenticationProvider for which the given credentials are valid.

@throws GuacamoleAuthenticationProcessException
    If the given credentials are not valid for any
    AuthenticationProvider, or if an error occurs while authenticating
    the user.
guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java