private List<DecoratedUserContext> getUserContexts(GuacamoleSession existingSession,
            AuthenticatedUser authenticatedUser, Credentials credentials)
            throws GuacamoleAuthenticationProcessException {

        List<DecoratedUserContext> userContexts = new ArrayList<>(authProviders.size());

        // If UserContexts already exist, update them and add to the list
        if (existingSession != null) {

            // Update all old user contexts
            List<DecoratedUserContext> oldUserContexts = existingSession.getUserContexts();
            for (DecoratedUserContext userContext : oldUserContexts) {

                UserContext oldUserContext = userContext.getUndecoratedUserContext();

                // Update existing UserContext
                AuthenticationProvider authProvider = oldUserContext.getAuthenticationProvider();
                UserContext updatedUserContext;
                try {
                    updatedUserContext = authProvider.updateUserContext(oldUserContext, authenticatedUser, credentials);
                }
                catch (GuacamoleException | RuntimeException | Error e) {
                    throw new GuacamoleAuthenticationProcessException("User "
                            + "authentication aborted during UserContext update.",
                            authProvider, e);
                }

                // Add to available data, if successful
                if (updatedUserContext != null)
                    userContexts.add(decorationService.redecorate(userContext,
                            updatedUserContext, authenticatedUser, credentials));

                // If unsuccessful, log that this happened, as it may be a bug
                else
                    logger.debug("AuthenticationProvider \"{}\" retroactively destroyed its UserContext.",
                            authProvider.getClass().getName());

            }

        }

        // Otherwise, create new UserContexts from available AuthenticationProviders
        else {

            // Get UserContexts from each available AuthenticationProvider
            for (AuthenticationProvider authProvider : authProviders) {

                // Generate new UserContext
                UserContext userContext;
                try {
                    userContext = authProvider.getUserContext(authenticatedUser);
                }
                catch (GuacamoleException | RuntimeException | Error e) {
                    throw new GuacamoleAuthenticationProcessException("User "
                            + "authentication aborted during initial "
                            + "UserContext creation.", authProvider, e);
                }

                // Add to available data, if successful
                if (userContext != null)
                    userContexts.add(decorationService.decorate(userContext,
                            authenticatedUser, credentials));

            }

        }

        return userContexts;

    }
Returns all UserContexts associated with the given AuthenticatedUser,
updating existing UserContexts, if any. If no UserContexts are yet
associated with the given AuthenticatedUser, new UserContexts are
generated by polling each available AuthenticationProvider.

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

@param authenticatedUser
    The AuthenticatedUser that has successfully authenticated or re-
    authenticated.

@param credentials
    The Credentials provided by the user in the most recent
    authentication attempt.

@return
    A List of all UserContexts associated with the given
    AuthenticatedUser.

@throws GuacamoleAuthenticationProcessException
    If an error occurs while creating or updating any UserContext.
guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java