private static UserContext decorate(AuthenticationProvider authProvider,
            UserContext userContext, AuthenticatedUser authenticatedUser,
            Credentials credentials) throws GuacamoleAuthenticationProcessException {

        // Skip the AuthenticationProvider which produced the UserContext
        // being decorated
        if (authProvider != userContext.getAuthenticationProvider()) {

            // Apply layer of wrapping around UserContext
            UserContext decorated;
            try {
                decorated = authProvider.decorate(userContext,
                        authenticatedUser, credentials);
            }
            catch (GuacamoleException | RuntimeException | Error e) {
                throw new GuacamoleAuthenticationProcessException("User "
                        + "authentication aborted by decorating UserContext.",
                        authProvider, e);
            }

            // Do not allow misbehaving extensions to wipe out the
            // UserContext entirely
            if (decorated != null)
                return decorated;

        }

        return userContext;

    }
Decorates a newly-created UserContext (as would be returned by
getUserContext()), invoking the decorate() function of the given
AuthenticationProvider to apply an additional layer of decoration. If the
AuthenticationProvider originated the given UserContext, this function
has no effect.

@param authProvider
    The AuthenticationProvider which should be used to decorate the
    given UserContext.

@param userContext
    The UserContext to decorate.

@param authenticatedUser
    The AuthenticatedUser identifying the user associated with the given
    UserContext.

@param credentials
    The credentials associated with the request which produced the given
    UserContext.

@return
    A UserContext instance which has been decorated (wrapped) by the
    given AuthenticationProvider, or the original UserContext if the
    given AuthenticationProvider originated the UserContext.

@throws GuacamoleAuthenticationProcessException
    If the given AuthenticationProvider fails while decorating the
    UserContext.
guacamole/src/main/java/org/apache/guacamole/rest/auth/DecoratedUserContext.java