private AuthenticatedUser getAuthenticatedUser(GuacamoleSession existingSession,
            Credentials credentials) throws GuacamoleAuthenticationProcessException {

        // Re-authenticate user if session exists
        if (existingSession != null) {
            AuthenticatedUser updatedUser = updateAuthenticatedUser(
                    existingSession.getAuthenticatedUser(), credentials);
            return updatedUser;
        }

        // Otherwise, attempt authentication as a new user
        AuthenticatedUser authenticatedUser = AuthenticationService.this.authenticateUser(credentials);
        return authenticatedUser;

    }
Returns the AuthenticatedUser associated with the given session and
credentials, performing a fresh authentication and creating a new
AuthenticatedUser if necessary.

@param existingSession
    The current GuacamoleSession, or null if no session exists yet.

@param credentials
    The Credentials to use to authenticate the user.

@return
    The AuthenticatedUser associated with the given session and
    credentials.

@throws GuacamoleAuthenticationProcessException
    If an error occurs while authenticating or re-authenticating the
    user.
guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java