You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/01/30 19:32:12 UTC

[1/9] guacamole-client git commit: GUACAMOLE-96: Add API support for augmenting functionality of other extensions.

Repository: guacamole-client
Updated Branches:
  refs/heads/master 9d587496b -> eaeaeb10c


GUACAMOLE-96: Add API support for augmenting functionality of other extensions.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/ffad1898
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/ffad1898
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/ffad1898

Branch: refs/heads/master
Commit: ffad1898b64411afcf1484de4419c0cc47758c25
Parents: 00d464b
Author: Michael Jumper <mj...@apache.org>
Authored: Fri Oct 27 11:07:35 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jan 13 17:22:48 2018 -0800

----------------------------------------------------------------------
 .../auth/cas/CASAuthenticationProvider.java     |  7 ++++
 .../auth/duo/DuoAuthenticationProvider.java     |  7 ++++
 .../HTTPHeaderAuthenticationProvider.java       |  7 ++++
 .../jdbc/InjectedAuthenticationProvider.java    |  7 ++++
 .../auth/ldap/LDAPAuthenticationProvider.java   |  7 ++++
 .../openid/OpenIDAuthenticationProvider.java    |  7 ++++
 .../net/auth/AuthenticationProvider.java        | 34 ++++++++++++++++++++
 .../simple/SimpleAuthenticationProvider.java    | 10 ++++++
 .../extension/AuthenticationProviderFacade.java | 14 ++++++++
 9 files changed, 100 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/ffad1898/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/CASAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/CASAuthenticationProvider.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/CASAuthenticationProvider.java
index 28122f9..a96154a 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/CASAuthenticationProvider.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/CASAuthenticationProvider.java
@@ -108,6 +108,13 @@ public class CASAuthenticationProvider implements AuthenticationProvider {
     }
 
     @Override
+    public UserContext decorate(UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/ffad1898/extensions/guacamole-auth-duo/src/main/java/org/apache/guacamole/auth/duo/DuoAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-duo/src/main/java/org/apache/guacamole/auth/duo/DuoAuthenticationProvider.java b/extensions/guacamole-auth-duo/src/main/java/org/apache/guacamole/auth/duo/DuoAuthenticationProvider.java
index 1c84046..aadc231 100644
--- a/extensions/guacamole-auth-duo/src/main/java/org/apache/guacamole/auth/duo/DuoAuthenticationProvider.java
+++ b/extensions/guacamole-auth-duo/src/main/java/org/apache/guacamole/auth/duo/DuoAuthenticationProvider.java
@@ -103,6 +103,13 @@ public class DuoAuthenticationProvider implements AuthenticationProvider {
     }
 
     @Override
+    public UserContext decorate(UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/ffad1898/extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderAuthenticationProvider.java b/extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderAuthenticationProvider.java
index b3385b1..d68c2ee 100644
--- a/extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderAuthenticationProvider.java
+++ b/extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderAuthenticationProvider.java
@@ -108,6 +108,13 @@ public class HTTPHeaderAuthenticationProvider implements AuthenticationProvider
     }
 
     @Override
+    public UserContext decorate(UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/ffad1898/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
index e73b3df..9113834 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
@@ -105,6 +105,13 @@ public abstract class InjectedAuthenticationProvider implements AuthenticationPr
     }
 
     @Override
+    public UserContext decorate(UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/ffad1898/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPAuthenticationProvider.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPAuthenticationProvider.java
index f9c4a7d..e7a990e 100644
--- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPAuthenticationProvider.java
+++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPAuthenticationProvider.java
@@ -104,6 +104,13 @@ public class LDAPAuthenticationProvider implements AuthenticationProvider {
     }
 
     @Override
+    public UserContext decorate(UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/ffad1898/extensions/guacamole-auth-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProvider.java b/extensions/guacamole-auth-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProvider.java
index 57b4831..d58e7dc 100644
--- a/extensions/guacamole-auth-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProvider.java
+++ b/extensions/guacamole-auth-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProvider.java
@@ -108,6 +108,13 @@ public class OpenIDAuthenticationProvider implements AuthenticationProvider {
     }
 
     @Override
+    public UserContext decorate(UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/ffad1898/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AuthenticationProvider.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AuthenticationProvider.java
index 448f495..7c7f12e 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AuthenticationProvider.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AuthenticationProvider.java
@@ -169,6 +169,40 @@ public interface AuthenticationProvider {
             Credentials credentials) throws GuacamoleException;
 
     /**
+     * Given a UserContext which originates from a different
+     * AuthenticationProvider, returns a UserContext instance which decorates
+     * (wraps) that UserContext, delegating and overriding implemented
+     * functions as necessary. Each UserContext created via getUserContext()
+     * or updateUserContext() will be passed to the decorate() functions of all
+     * other AuthenticationProviders, allowing those AuthenticationProviders
+     * to augment (or perhaps even limit) the functionality or data provided.
+     *
+     * @param context
+     *     An existing UserContext generated by a different
+     *     AuthenticationProvider.
+     *
+     * @param authenticatedUser
+     *     The AuthenticatedUser object representing the user associated with
+     *     the given UserContext.
+     *
+     * @param credentials
+     *     The credentials which were most recently submitted for the given
+     *     AuthenticatedUser. These are not guaranteed to be the same as the
+     *     credentials associated with the AuthenticatedUser object, which are
+     *     the credentials provided when the user originally authenticated.
+     *
+     * @return
+     *     A decorated (wrapped) UserContext object, or the original,
+     *     undecorated UserContext.
+     *
+     * @throws GuacamoleException
+     *     If the UserContext cannot be decorated due to an error.
+     */
+    UserContext decorate(UserContext context,
+            AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException;
+
+    /**
      * Frees all resources associated with this AuthenticationProvider. This
      * function will be automatically invoked when the Guacamole server is
      * shutting down.

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/ffad1898/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleAuthenticationProvider.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleAuthenticationProvider.java
index 83ac794..fcacc3c 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleAuthenticationProvider.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleAuthenticationProvider.java
@@ -261,6 +261,16 @@ public abstract class SimpleAuthenticationProvider
     }
 
     @Override
+    public UserContext decorate(UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+
+        // Simply return the given context, decorating nothing
+        return context;
+
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/ffad1898/guacamole/src/main/java/org/apache/guacamole/extension/AuthenticationProviderFacade.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/extension/AuthenticationProviderFacade.java b/guacamole/src/main/java/org/apache/guacamole/extension/AuthenticationProviderFacade.java
index 8dfbe7f..b3169de 100644
--- a/guacamole/src/main/java/org/apache/guacamole/extension/AuthenticationProviderFacade.java
+++ b/guacamole/src/main/java/org/apache/guacamole/extension/AuthenticationProviderFacade.java
@@ -159,6 +159,20 @@ public class AuthenticationProviderFacade implements AuthenticationProvider {
     }
 
     @Override
+    public UserContext decorate(UserContext context,
+            AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
+
+        // Do nothing if underlying auth provider could not be loaded
+        if (authProvider == null)
+            return context;
+
+        // Delegate to underlying auth provider
+        return authProvider.decorate(context, authenticatedUser, credentials);
+
+    }
+
+    @Override
     public void shutdown() {
         if (authProvider != null)
             authProvider.shutdown();


[4/9] guacamole-client git commit: GUACAMOLE-96: Add redecorate() function with semantics analogous to updateUserContext().

Posted by vn...@apache.org.
GUACAMOLE-96: Add redecorate() function with semantics analogous to updateUserContext().


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/7357e51b
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/7357e51b
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/7357e51b

Branch: refs/heads/master
Commit: 7357e51b589f94d85d52b2e336812033f61d1767
Parents: a745569
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Oct 28 19:12:05 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jan 13 17:23:11 2018 -0800

----------------------------------------------------------------------
 .../auth/cas/CASAuthenticationProvider.java     |   7 +
 .../auth/duo/DuoAuthenticationProvider.java     |   7 +
 .../HTTPHeaderAuthenticationProvider.java       |   7 +
 .../jdbc/InjectedAuthenticationProvider.java    |   7 +
 .../auth/ldap/LDAPAuthenticationProvider.java   |   7 +
 .../openid/OpenIDAuthenticationProvider.java    |   7 +
 .../net/auth/AuthenticationProvider.java        |  49 ++-
 .../simple/SimpleAuthenticationProvider.java    |   7 +
 .../extension/AuthenticationProviderFacade.java |  15 +
 .../guacamole/rest/RESTServiceModule.java       |   2 +
 .../rest/auth/AuthenticationService.java        |  16 +-
 .../rest/auth/DecoratedUserContext.java         | 316 ++++++++++++++++---
 .../guacamole/rest/auth/DecorationService.java  | 145 +++++++++
 13 files changed, 531 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/CASAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/CASAuthenticationProvider.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/CASAuthenticationProvider.java
index a96154a..5c80bca 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/CASAuthenticationProvider.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/CASAuthenticationProvider.java
@@ -115,6 +115,13 @@ public class CASAuthenticationProvider implements AuthenticationProvider {
     }
 
     @Override
+    public UserContext redecorate(UserContext decorated, UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/extensions/guacamole-auth-duo/src/main/java/org/apache/guacamole/auth/duo/DuoAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-duo/src/main/java/org/apache/guacamole/auth/duo/DuoAuthenticationProvider.java b/extensions/guacamole-auth-duo/src/main/java/org/apache/guacamole/auth/duo/DuoAuthenticationProvider.java
index aadc231..7d27a75 100644
--- a/extensions/guacamole-auth-duo/src/main/java/org/apache/guacamole/auth/duo/DuoAuthenticationProvider.java
+++ b/extensions/guacamole-auth-duo/src/main/java/org/apache/guacamole/auth/duo/DuoAuthenticationProvider.java
@@ -110,6 +110,13 @@ public class DuoAuthenticationProvider implements AuthenticationProvider {
     }
 
     @Override
+    public UserContext redecorate(UserContext decorated, UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderAuthenticationProvider.java b/extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderAuthenticationProvider.java
index d68c2ee..ca19b39 100644
--- a/extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderAuthenticationProvider.java
+++ b/extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderAuthenticationProvider.java
@@ -115,6 +115,13 @@ public class HTTPHeaderAuthenticationProvider implements AuthenticationProvider
     }
 
     @Override
+    public UserContext redecorate(UserContext decorated, UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
index 9113834..0e3e84b 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
@@ -112,6 +112,13 @@ public abstract class InjectedAuthenticationProvider implements AuthenticationPr
     }
 
     @Override
+    public UserContext redecorate(UserContext decorated, UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPAuthenticationProvider.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPAuthenticationProvider.java
index e7a990e..2d8dfd7 100644
--- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPAuthenticationProvider.java
+++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPAuthenticationProvider.java
@@ -111,6 +111,13 @@ public class LDAPAuthenticationProvider implements AuthenticationProvider {
     }
 
     @Override
+    public UserContext redecorate(UserContext decorated, UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/extensions/guacamole-auth-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProvider.java b/extensions/guacamole-auth-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProvider.java
index d58e7dc..cf0b96e 100644
--- a/extensions/guacamole-auth-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProvider.java
+++ b/extensions/guacamole-auth-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProvider.java
@@ -115,6 +115,13 @@ public class OpenIDAuthenticationProvider implements AuthenticationProvider {
     }
 
     @Override
+    public UserContext redecorate(UserContext decorated, UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return context;
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AuthenticationProvider.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AuthenticationProvider.java
index 7c7f12e..fd7d844 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AuthenticationProvider.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AuthenticationProvider.java
@@ -169,16 +169,16 @@ public interface AuthenticationProvider {
             Credentials credentials) throws GuacamoleException;
 
     /**
-     * Given a UserContext which originates from a different
+     * Given a UserContext returned from getUserContext() of a different
      * AuthenticationProvider, returns a UserContext instance which decorates
      * (wraps) that UserContext, delegating and overriding implemented
      * functions as necessary. Each UserContext created via getUserContext()
-     * or updateUserContext() will be passed to the decorate() functions of all
-     * other AuthenticationProviders, allowing those AuthenticationProviders
-     * to augment (or perhaps even limit) the functionality or data provided.
+     * will be passed to the decorate() functions of all other
+     * AuthenticationProviders, allowing those AuthenticationProviders to
+     * augment (or perhaps even limit) the functionality or data provided.
      *
      * @param context
-     *     An existing UserContext generated by a different
+     *     An existing UserContext generated by getUserContext() of a different
      *     AuthenticationProvider.
      *
      * @param authenticatedUser
@@ -203,6 +203,45 @@ public interface AuthenticationProvider {
             Credentials credentials) throws GuacamoleException;
 
     /**
+     * Given a UserContext returned by updateUserContext() of a different
+     * AuthenticationProvider, returns a UserContext instance which decorates
+     * (wraps) that UserContext, delegating and overriding implemented
+     * functions as necessary. Each UserContext created via updateUserContext()
+     * will be passed to the decorate() functions of all other
+     * AuthenticationProviders, allowing those AuthenticationProviders to
+     * augment (or perhaps even limit) the functionality or data provided.
+     *
+     * @param decorated
+     *     The UserContext returned when decorate() was invoked on this
+     *     AuthenticationProvider for the UserContext which was just updated
+     *     via a call to updateUserContext().
+     *
+     * @param context
+     *     An existing UserContext generated by updateUserContext() of a
+     *     different AuthenticationProvider.
+     *
+     * @param authenticatedUser
+     *     The AuthenticatedUser object representing the user associated with
+     *     the given UserContext.
+     *
+     * @param credentials
+     *     The credentials which were most recently submitted for the given
+     *     AuthenticatedUser. These are not guaranteed to be the same as the
+     *     credentials associated with the AuthenticatedUser object, which are
+     *     the credentials provided when the user originally authenticated.
+     *
+     * @return
+     *     A decorated (wrapped) UserContext object, or the original,
+     *     undecorated UserContext.
+     *
+     * @throws GuacamoleException
+     *     If the UserContext cannot be decorated due to an error.
+     */
+    UserContext redecorate(UserContext decorated, UserContext context,
+            AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException;
+
+    /**
      * Frees all resources associated with this AuthenticationProvider. This
      * function will be automatically invoked when the Guacamole server is
      * shutting down.

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleAuthenticationProvider.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleAuthenticationProvider.java
index fcacc3c..b29c2d7 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleAuthenticationProvider.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleAuthenticationProvider.java
@@ -271,6 +271,13 @@ public abstract class SimpleAuthenticationProvider
     }
 
     @Override
+    public UserContext redecorate(UserContext decorated, UserContext context,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+        return decorate(context, authenticatedUser, credentials);
+    }
+
+    @Override
     public void shutdown() {
         // Do nothing
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/guacamole/src/main/java/org/apache/guacamole/extension/AuthenticationProviderFacade.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/extension/AuthenticationProviderFacade.java b/guacamole/src/main/java/org/apache/guacamole/extension/AuthenticationProviderFacade.java
index b3169de..a868931 100644
--- a/guacamole/src/main/java/org/apache/guacamole/extension/AuthenticationProviderFacade.java
+++ b/guacamole/src/main/java/org/apache/guacamole/extension/AuthenticationProviderFacade.java
@@ -173,6 +173,21 @@ public class AuthenticationProviderFacade implements AuthenticationProvider {
     }
 
     @Override
+    public UserContext redecorate(UserContext decorated, UserContext context,
+            AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
+
+        // Do nothing if underlying auth provider could not be loaded
+        if (authProvider == null)
+            return context;
+
+        // Delegate to underlying auth provider
+        return authProvider.redecorate(decorated, context,
+                authenticatedUser, credentials);
+
+    }
+
+    @Override
     public void shutdown() {
         if (authProvider != null)
             authProvider.shutdown();

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java b/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
index 587d833..98c5c7a 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
@@ -33,6 +33,7 @@ import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
 import org.apache.guacamole.rest.auth.TokenRESTService;
 import org.apache.guacamole.rest.auth.AuthTokenGenerator;
 import org.apache.guacamole.rest.auth.AuthenticationService;
+import org.apache.guacamole.rest.auth.DecorationService;
 import org.apache.guacamole.rest.auth.SecureRandomAuthTokenGenerator;
 import org.apache.guacamole.rest.auth.TokenSessionMap;
 import org.apache.guacamole.rest.connection.ConnectionModule;
@@ -80,6 +81,7 @@ public class RESTServiceModule extends ServletModule {
         bind(ListenerService.class);
         bind(AuthenticationService.class);
         bind(AuthTokenGenerator.class).to(SecureRandomAuthTokenGenerator.class);
+        bind(DecorationService.class);
 
         // Automatically translate GuacamoleExceptions for REST methods
         MethodInterceptor interceptor = new RESTExceptionWrapper();

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java b/guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java
index b6572f8..7f38857 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java
@@ -79,6 +79,12 @@ public class AuthenticationService {
     private AuthTokenGenerator authTokenGenerator;
 
     /**
+     * Service for applying or reapplying layers of decoration.
+     */
+    @Inject
+    private DecorationService decorationService;
+
+    /**
      * The service to use to notify registered authentication listeners.
      */
     @Inject
@@ -357,7 +363,7 @@ public class AuthenticationService {
             List<DecoratedUserContext> oldUserContexts = existingSession.getUserContexts();
             for (DecoratedUserContext userContext : oldUserContexts) {
 
-                UserContext oldUserContext = userContext.getOriginal();
+                UserContext oldUserContext = userContext.getUndecoratedUserContext();
 
                 // Update existing UserContext
                 AuthenticationProvider authProvider = oldUserContext.getAuthenticationProvider();
@@ -365,8 +371,8 @@ public class AuthenticationService {
 
                 // Add to available data, if successful
                 if (updatedUserContext != null)
-                    userContexts.add(new DecoratedUserContext(updatedUserContext,
-                            authenticatedUser, credentials, authProviders));
+                    userContexts.add(decorationService.redecorate(userContext,
+                            updatedUserContext, authenticatedUser, credentials));
 
                 // If unsuccessful, log that this happened, as it may be a bug
                 else
@@ -388,8 +394,8 @@ public class AuthenticationService {
 
                 // Add to available data, if successful
                 if (userContext != null)
-                    userContexts.add(new DecoratedUserContext(userContext,
-                            authenticatedUser, credentials, authProviders));
+                    userContexts.add(decorationService.decorate(userContext,
+                            authenticatedUser, credentials));
 
             }
 

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecoratedUserContext.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecoratedUserContext.java b/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecoratedUserContext.java
index 69b6846..24ad8b3 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecoratedUserContext.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecoratedUserContext.java
@@ -19,7 +19,6 @@
 
 package org.apache.guacamole.rest.auth;
 
-import java.util.List;
 import org.apache.guacamole.GuacamoleException;
 import org.apache.guacamole.net.auth.AuthenticatedUser;
 import org.apache.guacamole.net.auth.AuthenticationProvider;
@@ -28,21 +27,38 @@ import org.apache.guacamole.net.auth.DelegatingUserContext;
 import org.apache.guacamole.net.auth.UserContext;
 
 /**
- * A UserContext which has been decorated by all applicable
- * AuthenticationProviders.
+ * A UserContext which has been decorated by an AuthenticationProvider through
+ * invoking decorate() or redecorate().
  */
 public class DecoratedUserContext extends DelegatingUserContext {
 
     /**
      * The original, undecorated UserContext.
      */
-    private final UserContext original;
+    private final UserContext undecoratedUserContext;
 
     /**
-     * Repeatedly decorates the given UserContext, invoking the decorate()
-     * function of each given AuthenticationProvider, wrapping the UserContext
-     * within successive layers of decoration. The AuthenticationProvider which
-     * originated the given UserContext will be ignored.
+     * The AuthenticationProvider which applied this layer of decoration.
+     */
+    private final AuthenticationProvider decoratingAuthenticationProvider;
+
+    /**
+     * The DecoratedUserContext which applies the layer of decoration
+     * immediately beneath this DecoratedUserContext. If no further decoration
+     * has been applied, this will be null.
+     */
+    private final DecoratedUserContext decoratedUserContext;
+
+    /**
+     * 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.
@@ -55,42 +71,87 @@ public class DecoratedUserContext extends DelegatingUserContext {
      *     The credentials associated with the request which produced the given
      *     UserContext.
      *
-     * @param authProviders
-     *     The AuthenticationProviders which should be used to decorate the
-     *     given UserContext. The order of this list dictates the order in
-     *     which each AuthenticationProvider's decorate() function will be
-     *     invoked.
-     *
      * @return
-     *     A UserContext instance which has been decorated (wrapped) by all
-     *     applicable AuthenticationProviders.
+     *     A UserContext instance which has been decorated (wrapped) by the
+     *     given AuthenticationProvider, or the original UserContext if the
+     *     given AuthenticationProvider originated the UserContext.
      *
      * @throws GuacamoleException
-     *     If any of the given AuthenticationProviders fails while decorating
-     *     the UserContext.
+     *     If the given AuthenticationProvider fails while decorating the
+     *     UserContext.
      */
-    private static UserContext decorate(UserContext userContext,
-            AuthenticatedUser authenticatedUser, Credentials credentials,
-            List<AuthenticationProvider> authProviders) throws GuacamoleException {
-
-        AuthenticationProvider owner = userContext.getAuthenticationProvider();
-
-        // Poll each AuthenticationProvider to decorate the given UserContext
-        for (AuthenticationProvider authProvider : authProviders) {
+    private static UserContext decorate(AuthenticationProvider authProvider,
+            UserContext userContext, AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
 
-            // Skip the AuthenticationProvider which produced the UserContext
-            // being decorated
-            if (authProvider == owner)
-                continue;
+        // Skip the AuthenticationProvider which produced the UserContext
+        // being decorated
+        if (authProvider != userContext.getAuthenticationProvider()) {
 
-            // Apply next layer of wrapping around UserContext
+            // Apply layer of wrapping around UserContext
             UserContext decorated = authProvider.decorate(userContext,
                     authenticatedUser, credentials);
 
             // Do not allow misbehaving extensions to wipe out the
             // UserContext entirely
             if (decorated != null)
-                userContext = decorated;
+                return decorated;
+
+        }
+
+        return userContext;
+
+    }
+
+    /**
+     * Redecorates an updated UserContext (as would be returned by
+     * updateUserContext()), invoking the redecorate() 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 decorated
+     *     The DecoratedUserContext associated with an older version of the
+     *     given UserContext.
+     *
+     * @param userContext
+     *     The new version of the UserContext which should be decorated.
+     *
+     * @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 GuacamoleException
+     *     If the given AuthenticationProvider fails while decorating the
+     *     UserContext.
+     */
+    private static UserContext redecorate(DecoratedUserContext decorated,
+            UserContext userContext, AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
+
+        AuthenticationProvider authProvider = decorated.getDecoratingAuthenticationProvider();
+
+        // Skip the AuthenticationProvider which produced the UserContext
+        // being decorated
+        if (authProvider != userContext.getAuthenticationProvider()) {
+
+            // Apply next layer of wrapping around UserContext
+            UserContext redecorated = authProvider.redecorate(decorated,
+                    userContext, authenticatedUser, credentials);
+
+            // Do not allow misbehaving extensions to wipe out the
+            // UserContext entirely
+            if (redecorated != null)
+                return redecorated;
 
         }
 
@@ -100,13 +161,17 @@ public class DecoratedUserContext extends DelegatingUserContext {
 
     /**
      * Creates a new DecoratedUserContext, invoking the the decorate() function
-     * of the given AuthenticationProviders to decorate the provided
-     * UserContext. Decoration by each AuthenticationProvider will occur in the
-     * order given. Only AuthenticationProviders which did not originate the
-     * given UserContext will be used.
+     * of the given AuthenticationProvider to decorate the provided, undecorated
+     * UserContext. If the AuthenticationProvider originated the given
+     * UserContext, then the given UserContext is wrapped without any
+     * decoration.
+     *
+     * @param authProvider
+     *     The AuthenticationProvider which should be used to decorate the
+     *     given UserContext.
      *
      * @param userContext
-     *     The UserContext to decorate.
+     *     The undecorated UserContext to decorate.
      *
      * @param authenticatedUser
      *     The AuthenticatedUser identifying the user associated with the given
@@ -116,32 +181,181 @@ public class DecoratedUserContext extends DelegatingUserContext {
      *     The credentials associated with the request which produced the given
      *     UserContext.
      *
-     * @param authProviders
-     *     The AuthenticationProviders which should be used to decorate the
-     *     given UserContext. The order of this list dictates the order in
-     *     which each AuthenticationProvider's decorate() function will be
-     *     invoked.
+     * @throws GuacamoleException
+     *     If any of the given AuthenticationProviders fails while decorating
+     *     the UserContext.
+     */
+    public DecoratedUserContext(AuthenticationProvider authProvider,
+            UserContext userContext, AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
+
+        // Wrap the result of invoking decorate() on the given AuthenticationProvider
+        super(decorate(authProvider, userContext, authenticatedUser, credentials));
+        this.decoratingAuthenticationProvider = authProvider;
+
+        // The wrapped UserContext is undecorated
+        this.undecoratedUserContext = userContext;
+        this.decoratedUserContext = null;
+
+    }
+
+    /**
+     * Creates a new DecoratedUserContext, invoking the the decorate() function
+     * of the given AuthenticationProvider to apply an additional layer of
+     * decoration to a DecoratedUserContext. If the AuthenticationProvider
+     * originated the given UserContext, then the given UserContext is wrapped
+     * without any decoration.
+     *
+     * @param authProvider
+     *     The AuthenticationProvider which should be used to decorate the
+     *     given UserContext.
+     *
+     * @param userContext
+     *     The DecoratedUserContext 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.
+     *
+     * @throws GuacamoleException
+     *     If any of the given AuthenticationProviders fails while decorating
+     *     the UserContext.
+     */
+    public DecoratedUserContext(AuthenticationProvider authProvider,
+            DecoratedUserContext userContext, AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
+
+        // Wrap the result of invoking decorate() on the given AuthenticationProvider
+        super(decorate(authProvider, userContext, authenticatedUser, credentials));
+        this.decoratingAuthenticationProvider = authProvider;
+
+        // The wrapped UserContext has at least one layer of decoration
+        this.undecoratedUserContext = userContext.getUndecoratedUserContext();
+        this.decoratedUserContext = userContext;
+
+    }
+
+    /**
+     * Creates a new DecoratedUserContext, invoking the the redecorate()
+     * function of the given AuthenticationProvider to reapply decoration to the
+     * provided, undecorated UserContext, which has been updated relative to a
+     * past version which was decorated. If the AuthenticationProvider
+     * originated the given UserContext, then the given UserContext is wrapped
+     * without any decoration.
+     *
+     * @param decorated
+     *     The DecoratedUserContext associated with the older version of the
+     *     given UserContext.
+     *
+     * @param userContext
+     *     The undecorated 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.
+     *
+     * @throws GuacamoleException
+     *     If any of the given AuthenticationProviders fails while decorating
+     *     the UserContext.
+     */
+    public DecoratedUserContext(DecoratedUserContext decorated,
+            UserContext userContext, AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
+
+        // Wrap the result of invoking redecorate() on the given AuthenticationProvider
+        super(redecorate(decorated, userContext, authenticatedUser, credentials));
+        this.decoratingAuthenticationProvider = decorated.getDecoratingAuthenticationProvider();
+
+        // The wrapped UserContext is undecorated
+        this.undecoratedUserContext = userContext;
+        this.decoratedUserContext = null;
+
+    }
+
+    /**
+     * Creates a new DecoratedUserContext, invoking the the redecorate()
+     * function of the given AuthenticationProvider to reapply decoration to a
+     * DecoratedUserContext which already has at least one layer of decoration
+     * applied, and which is associated with a UserContext which was updated
+     * relative to a past version which was decorated. If the
+     * AuthenticationProvider originated the given UserContext, then the given
+     * UserContext is wrapped without any decoration.
+     *
+     * @param decorated
+     *     The DecoratedUserContext associated with the older version of the
+     *     UserContext wrapped within one or more layers of decoration.
+     *
+     * @param userContext
+     *     The DecoratedUserContext 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.
      *
      * @throws GuacamoleException
      *     If any of the given AuthenticationProviders fails while decorating
      *     the UserContext.
      */
-    public DecoratedUserContext(UserContext userContext,
-            AuthenticatedUser authenticatedUser, Credentials credentials,
-            List<AuthenticationProvider> authProviders) throws GuacamoleException {
-        super(decorate(userContext, authenticatedUser, credentials, authProviders));
-        this.original = userContext;
+    public DecoratedUserContext(DecoratedUserContext decorated,
+            DecoratedUserContext userContext, AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
+
+        // Wrap the result of invoking redecorate() on the given AuthenticationProvider
+        super(redecorate(decorated, userContext, authenticatedUser, credentials));
+        this.decoratingAuthenticationProvider = decorated.getDecoratingAuthenticationProvider();
+
+        // The wrapped UserContext has at least one layer of decoration
+        this.undecoratedUserContext = userContext.getUndecoratedUserContext();
+        this.decoratedUserContext = userContext;
+
     }
 
     /**
-     * Returns the original, undecorated UserContext, as provided to the
-     * constructor of this DecoratedUserContext.
+     * Returns the original UserContext with absolutely no layers of decoration
+     * applied.
      *
      * @return
      *     The original, undecorated UserContext.
      */
-    public UserContext getOriginal() {
-        return original;
+    public UserContext getUndecoratedUserContext() {
+        return undecoratedUserContext;
+    }
+
+    /**
+     * Returns the AuthenticationProvider which applied the layer of decoration
+     * represented by this DecoratedUserContext.
+     *
+     * @return
+     *     The AuthenticationProvider which applied this layer of decoration.
+     */
+    public AuthenticationProvider getDecoratingAuthenticationProvider() {
+        return decoratingAuthenticationProvider;
+    }
+
+    /**
+     * Returns the DecoratedUserContext representing the next layer of
+     * decoration, itself decorated by this DecoratedUserContext. If no further
+     * layers of decoration exist, this will be null.
+     *
+     * @return
+     *     The DecoratedUserContext which applies the layer of decoration
+     *     immediately beneath this DecoratedUserContext, or null if no further
+     *     decoration has been applied.
+     */
+    public DecoratedUserContext getDecoratedUserContext() {
+        return decoratedUserContext;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/7357e51b/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecorationService.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecorationService.java b/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecorationService.java
new file mode 100644
index 0000000..b63b037
--- /dev/null
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecorationService.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.rest.auth;
+
+import com.google.inject.Inject;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.UserContext;
+
+/**
+ * A service for applying or reapplying layers of decoration to UserContexts.
+ * The semantics of UserContext decoration/redecoration is defined by the
+ * AuthenticationProvider interface.
+ */
+public class DecorationService {
+
+    /**
+     * All configured authentication providers which can be used to
+     * authenticate users or retrieve data associated with authenticated users.
+     */
+    @Inject
+    private List<AuthenticationProvider> authProviders;
+
+    /**
+     * Creates a new DecoratedUserContext, invoking the the decorate() function
+     * of all AuthenticationProviders to decorate the provided UserContext.
+     * Decoration by each AuthenticationProvider will occur in the order that
+     * the AuthenticationProviders were loaded. Only AuthenticationProviders
+     * which did not originate the given UserContext will be used.
+     *
+     * @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 new DecoratedUserContext which has been decorated by all
+     *     AuthenticationProviders.
+     *
+     * @throws GuacamoleException
+     *     If any AuthenticationProvider fails while decorating the UserContext.
+     */
+    public DecoratedUserContext decorate(UserContext userContext,
+            AuthenticatedUser authenticatedUser, Credentials credentials)
+            throws GuacamoleException {
+
+        // Get first AuthenticationProvider in list
+        Iterator<AuthenticationProvider> current = authProviders.iterator();
+        if (!current.hasNext())
+            return null;
+
+        // Use first AuthenticationProvider to produce the root-level
+        // decorated UserContext
+        DecoratedUserContext decorated = new DecoratedUserContext(current.next(),
+                userContext, authenticatedUser, credentials);
+
+        // Repeatedly wrap the decorated UserContext with additional layers of
+        // decoration for each remaining AuthenticationProvider
+        while (current.hasNext()) {
+            decorated = new DecoratedUserContext(current.next(), decorated,
+                    authenticatedUser, credentials);
+        }
+
+        return decorated;
+
+    }
+
+    /**
+     * Creates a new DecoratedUserContext, invoking the the redecorate()
+     * function of all AuthenticationProviders to reapply decoration. Decoration
+     * by each AuthenticationProvider will occur in the order that the
+     * AuthenticationProviders were loaded. Only AuthenticationProviders which
+     * did not originate the given UserContext will be used.
+     *
+     * @param decorated
+     *     The DecoratedUserContext associated with an older version of the
+     *     given UserContext.
+     *
+     * @param userContext
+     *     The new version of the UserContext which should be decorated.
+     *
+     * @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 new DecoratedUserContext which has been decorated by all
+     *     AuthenticationProviders.
+     *
+     * @throws GuacamoleException
+     *     If any AuthenticationProvider fails while decorating the UserContext.
+     */
+    public DecoratedUserContext redecorate(DecoratedUserContext decorated,
+            UserContext userContext, AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
+
+        // If the given DecoratedUserContext contains further decorated layers,
+        // redecorate those first
+        DecoratedUserContext next = decorated.getDecoratedUserContext();
+        if (next != null) {
+            return new DecoratedUserContext(decorated,
+                    redecorate(next, userContext, authenticatedUser, credentials),
+                    authenticatedUser, credentials);
+        }
+
+        // If only one layer of decoration is present, simply redecorate that
+        // layer
+        return new DecoratedUserContext(decorated, userContext,
+                authenticatedUser, credentials);
+
+    }
+
+}


[3/9] guacamole-client git commit: GUACAMOLE-96: Invoke decorate() for all AuthenticationProviders when creating or updating the UserContext.

Posted by vn...@apache.org.
GUACAMOLE-96: Invoke decorate() for all AuthenticationProviders when creating or updating the UserContext.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/a745569f
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/a745569f
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/a745569f

Branch: refs/heads/master
Commit: a745569f1303dd2f1f4a16190096680d53dbc9cd
Parents: 41059f5
Author: Michael Jumper <mj...@apache.org>
Authored: Fri Oct 27 14:30:42 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jan 13 17:23:08 2018 -0800

----------------------------------------------------------------------
 .../org/apache/guacamole/GuacamoleSession.java  |  13 +-
 .../rest/auth/AuthenticationService.java        |  25 ++--
 .../rest/auth/DecoratedUserContext.java         | 147 +++++++++++++++++++
 .../guacamole/rest/auth/TokenRESTService.java   |   2 +-
 4 files changed, 170 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/a745569f/guacamole/src/main/java/org/apache/guacamole/GuacamoleSession.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/GuacamoleSession.java b/guacamole/src/main/java/org/apache/guacamole/GuacamoleSession.java
index e723c0a..24ea196 100644
--- a/guacamole/src/main/java/org/apache/guacamole/GuacamoleSession.java
+++ b/guacamole/src/main/java/org/apache/guacamole/GuacamoleSession.java
@@ -28,6 +28,7 @@ import org.apache.guacamole.net.GuacamoleTunnel;
 import org.apache.guacamole.net.auth.AuthenticatedUser;
 import org.apache.guacamole.net.auth.AuthenticationProvider;
 import org.apache.guacamole.net.auth.UserContext;
+import org.apache.guacamole.rest.auth.DecoratedUserContext;
 import org.apache.guacamole.tunnel.UserTunnel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,7 +53,7 @@ public class GuacamoleSession {
      * All UserContexts associated with this session. Each
      * AuthenticationProvider may provide its own UserContext.
      */
-    private List<UserContext> userContexts;
+    private List<DecoratedUserContext> userContexts;
 
     /**
      * All currently-active tunnels, indexed by tunnel UUID.
@@ -84,7 +85,7 @@ public class GuacamoleSession {
      */
     public GuacamoleSession(Environment environment,
             AuthenticatedUser authenticatedUser,
-            List<UserContext> userContexts)
+            List<DecoratedUserContext> userContexts)
             throws GuacamoleException {
         this.lastAccessedTime = System.currentTimeMillis();
         this.authenticatedUser = authenticatedUser;
@@ -121,7 +122,7 @@ public class GuacamoleSession {
      *     An unmodifiable list of all UserContexts associated with this
      *     session.
      */
-    public List<UserContext> getUserContexts() {
+    public List<DecoratedUserContext> getUserContexts() {
         return Collections.unmodifiableList(userContexts);
     }
 
@@ -141,12 +142,12 @@ public class GuacamoleSession {
      * @throws GuacamoleException
      *     If no such UserContext exists.
      */
-    public UserContext getUserContext(String authProviderIdentifier)
+    public DecoratedUserContext getUserContext(String authProviderIdentifier)
             throws GuacamoleException {
 
         // Locate and return the UserContext associated with the
         // AuthenticationProvider having the given identifier, if any
-        for (UserContext userContext : getUserContexts()) {
+        for (DecoratedUserContext userContext : getUserContexts()) {
 
             // Get AuthenticationProvider associated with current UserContext
             AuthenticationProvider authProvider = userContext.getAuthenticationProvider();
@@ -170,7 +171,7 @@ public class GuacamoleSession {
      * @param userContexts
      *     The List of UserContexts to associate with this session.
      */
-    public void setUserContexts(List<UserContext> userContexts) {
+    public void setUserContexts(List<DecoratedUserContext> userContexts) {
         this.userContexts = userContexts;
     }
     

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/a745569f/guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java b/guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java
index fb118e1..b6572f8 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/auth/AuthenticationService.java
@@ -343,26 +343,30 @@ public class AuthenticationService {
      * @throws GuacamoleException
      *     If an error occurs while creating or updating any UserContext.
      */
-    private List<UserContext> getUserContexts(GuacamoleSession existingSession,
+    private List<DecoratedUserContext> getUserContexts(GuacamoleSession existingSession,
             AuthenticatedUser authenticatedUser, Credentials credentials)
             throws GuacamoleException {
 
-        List<UserContext> userContexts = new ArrayList<UserContext>(authProviders.size());
+        List<DecoratedUserContext> userContexts =
+                new ArrayList<DecoratedUserContext>(authProviders.size());
 
         // If UserContexts already exist, update them and add to the list
         if (existingSession != null) {
 
             // Update all old user contexts
-            List<UserContext> oldUserContexts = existingSession.getUserContexts();
-            for (UserContext oldUserContext : oldUserContexts) {
+            List<DecoratedUserContext> oldUserContexts = existingSession.getUserContexts();
+            for (DecoratedUserContext userContext : oldUserContexts) {
+
+                UserContext oldUserContext = userContext.getOriginal();
 
                 // Update existing UserContext
                 AuthenticationProvider authProvider = oldUserContext.getAuthenticationProvider();
-                UserContext userContext = authProvider.updateUserContext(oldUserContext, authenticatedUser, credentials);
+                UserContext updatedUserContext = authProvider.updateUserContext(oldUserContext, authenticatedUser, credentials);
 
                 // Add to available data, if successful
-                if (userContext != null)
-                    userContexts.add(userContext);
+                if (updatedUserContext != null)
+                    userContexts.add(new DecoratedUserContext(updatedUserContext,
+                            authenticatedUser, credentials, authProviders));
 
                 // If unsuccessful, log that this happened, as it may be a bug
                 else
@@ -384,7 +388,8 @@ public class AuthenticationService {
 
                 // Add to available data, if successful
                 if (userContext != null)
-                    userContexts.add(userContext);
+                    userContexts.add(new DecoratedUserContext(userContext,
+                            authenticatedUser, credentials, authProviders));
 
             }
 
@@ -428,7 +433,7 @@ public class AuthenticationService {
 
         // Get up-to-date AuthenticatedUser and associated UserContexts
         AuthenticatedUser authenticatedUser = getAuthenticatedUser(existingSession, credentials);
-        List<UserContext> userContexts = getUserContexts(existingSession, authenticatedUser, credentials);
+        List<DecoratedUserContext> userContexts = getUserContexts(existingSession, authenticatedUser, credentials);
 
         // Update existing session, if it exists
         String authToken;
@@ -513,7 +518,7 @@ public class AuthenticationService {
      * @throws GuacamoleException
      *     If the auth token does not correspond to any logged in user.
      */
-    public List<UserContext> getUserContexts(String authToken)
+    public List<DecoratedUserContext> getUserContexts(String authToken)
             throws GuacamoleException {
         return getGuacamoleSession(authToken).getUserContexts();
     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/a745569f/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecoratedUserContext.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecoratedUserContext.java b/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecoratedUserContext.java
new file mode 100644
index 0000000..69b6846
--- /dev/null
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/auth/DecoratedUserContext.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.rest.auth;
+
+import java.util.List;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.DelegatingUserContext;
+import org.apache.guacamole.net.auth.UserContext;
+
+/**
+ * A UserContext which has been decorated by all applicable
+ * AuthenticationProviders.
+ */
+public class DecoratedUserContext extends DelegatingUserContext {
+
+    /**
+     * The original, undecorated UserContext.
+     */
+    private final UserContext original;
+
+    /**
+     * Repeatedly decorates the given UserContext, invoking the decorate()
+     * function of each given AuthenticationProvider, wrapping the UserContext
+     * within successive layers of decoration. The AuthenticationProvider which
+     * originated the given UserContext will be ignored.
+     *
+     * @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.
+     *
+     * @param authProviders
+     *     The AuthenticationProviders which should be used to decorate the
+     *     given UserContext. The order of this list dictates the order in
+     *     which each AuthenticationProvider's decorate() function will be
+     *     invoked.
+     *
+     * @return
+     *     A UserContext instance which has been decorated (wrapped) by all
+     *     applicable AuthenticationProviders.
+     *
+     * @throws GuacamoleException
+     *     If any of the given AuthenticationProviders fails while decorating
+     *     the UserContext.
+     */
+    private static UserContext decorate(UserContext userContext,
+            AuthenticatedUser authenticatedUser, Credentials credentials,
+            List<AuthenticationProvider> authProviders) throws GuacamoleException {
+
+        AuthenticationProvider owner = userContext.getAuthenticationProvider();
+
+        // Poll each AuthenticationProvider to decorate the given UserContext
+        for (AuthenticationProvider authProvider : authProviders) {
+
+            // Skip the AuthenticationProvider which produced the UserContext
+            // being decorated
+            if (authProvider == owner)
+                continue;
+
+            // Apply next layer of wrapping around UserContext
+            UserContext decorated = authProvider.decorate(userContext,
+                    authenticatedUser, credentials);
+
+            // Do not allow misbehaving extensions to wipe out the
+            // UserContext entirely
+            if (decorated != null)
+                userContext = decorated;
+
+        }
+
+        return userContext;
+
+    }
+
+    /**
+     * Creates a new DecoratedUserContext, invoking the the decorate() function
+     * of the given AuthenticationProviders to decorate the provided
+     * UserContext. Decoration by each AuthenticationProvider will occur in the
+     * order given. Only AuthenticationProviders which did not originate the
+     * given UserContext will be used.
+     *
+     * @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.
+     *
+     * @param authProviders
+     *     The AuthenticationProviders which should be used to decorate the
+     *     given UserContext. The order of this list dictates the order in
+     *     which each AuthenticationProvider's decorate() function will be
+     *     invoked.
+     *
+     * @throws GuacamoleException
+     *     If any of the given AuthenticationProviders fails while decorating
+     *     the UserContext.
+     */
+    public DecoratedUserContext(UserContext userContext,
+            AuthenticatedUser authenticatedUser, Credentials credentials,
+            List<AuthenticationProvider> authProviders) throws GuacamoleException {
+        super(decorate(userContext, authenticatedUser, credentials, authProviders));
+        this.original = userContext;
+    }
+
+    /**
+     * Returns the original, undecorated UserContext, as provided to the
+     * constructor of this DecoratedUserContext.
+     *
+     * @return
+     *     The original, undecorated UserContext.
+     */
+    public UserContext getOriginal() {
+        return original;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/a745569f/guacamole/src/main/java/org/apache/guacamole/rest/auth/TokenRESTService.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/auth/TokenRESTService.java b/guacamole/src/main/java/org/apache/guacamole/rest/auth/TokenRESTService.java
index 6366d28..cea0315 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/auth/TokenRESTService.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/auth/TokenRESTService.java
@@ -186,7 +186,7 @@ public class TokenRESTService {
             throw new GuacamoleResourceNotFoundException("No such token.");
 
         // Build list of all available auth providers
-        List<UserContext> userContexts = session.getUserContexts();
+        List<DecoratedUserContext> userContexts = session.getUserContexts();
         List<String> authProviderIdentifiers = new ArrayList<String>(userContexts.size());
         for (UserContext userContext : userContexts)
             authProviderIdentifiers.add(userContext.getAuthenticationProvider().getIdentifier());


[6/9] guacamole-client git commit: GUACAMOLE-96: Add convenience classes for overriding the behavior of objects commonly stored in a Directory.

Posted by vn...@apache.org.
GUACAMOLE-96: Add convenience classes for overriding the behavior of objects commonly stored in a Directory.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/b37e041d
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/b37e041d
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/b37e041d

Branch: refs/heads/master
Commit: b37e041d3ee263873cc55388cfa0cb9079f32bfb
Parents: a915f7b
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Oct 28 22:56:07 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jan 13 17:23:15 2018 -0800

----------------------------------------------------------------------
 .../net/auth/DelegatingConnection.java          | 131 +++++++++++++++++++
 .../net/auth/DelegatingConnectionGroup.java     | 120 +++++++++++++++++
 .../net/auth/DelegatingSharingProfile.java      |  96 ++++++++++++++
 .../guacamole/net/auth/DelegatingUser.java      | 127 ++++++++++++++++++
 4 files changed, 474 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/b37e041d/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnection.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnection.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnection.java
new file mode 100644
index 0000000..c5e9a1f
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnection.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.net.auth;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.GuacamoleTunnel;
+import org.apache.guacamole.protocol.GuacamoleClientInformation;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Connection implementation which simply delegates all function calls to an
+ * underlying Connection.
+ */
+public class DelegatingConnection implements Connection {
+
+    /**
+     * The wrapped Connection.
+     */
+    private final Connection connection;
+
+    /**
+     * Wraps the given Connection such that all function calls against this
+     * DelegatingConnection will be delegated to it.
+     *
+     * @param connection
+     *     The Connection to wrap.
+     */
+    public DelegatingConnection(Connection connection) {
+        this.connection = connection;
+    }
+
+    @Override
+    public String getIdentifier() {
+        return connection.getIdentifier();
+    }
+
+    @Override
+    public void setIdentifier(String identifier) {
+        connection.setIdentifier(identifier);
+    }
+
+    @Override
+    public String getName() {
+        return connection.getName();
+    }
+
+    @Override
+    public void setName(String name) {
+        connection.setName(name);
+    }
+
+    @Override
+    public String getParentIdentifier() {
+        return connection.getParentIdentifier();
+    }
+
+    @Override
+    public void setParentIdentifier(String parentIdentifier) {
+        connection.setParentIdentifier(parentIdentifier);
+    }
+
+    @Override
+    public GuacamoleConfiguration getConfiguration() {
+        return connection.getConfiguration();
+    }
+
+    @Override
+    public void setConfiguration(GuacamoleConfiguration config) {
+        connection.setConfiguration(config);
+    }
+
+    @Override
+    public Map<String, String> getAttributes() {
+        return connection.getAttributes();
+    }
+
+    @Override
+    public void setAttributes(Map<String, String> attributes) {
+        connection.setAttributes(attributes);
+    }
+
+    @Override
+    public Date getLastActive() {
+        return connection.getLastActive();
+    }
+
+    @Override
+    public List<? extends ConnectionRecord> getHistory()
+            throws GuacamoleException {
+        return connection.getHistory();
+    }
+
+    @Override
+    public Set<String> getSharingProfileIdentifiers()
+            throws GuacamoleException {
+        return connection.getSharingProfileIdentifiers();
+    }
+
+    @Override
+    public GuacamoleTunnel connect(GuacamoleClientInformation info)
+            throws GuacamoleException {
+        return connection.connect(info);
+    }
+
+    @Override
+    public int getActiveConnections() {
+        return connection.getActiveConnections();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/b37e041d/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnectionGroup.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnectionGroup.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnectionGroup.java
new file mode 100644
index 0000000..9f71ebb
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingConnectionGroup.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.net.auth;
+
+import java.util.Map;
+import java.util.Set;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.GuacamoleTunnel;
+import org.apache.guacamole.protocol.GuacamoleClientInformation;
+
+/**
+ * ConnectionGroup implementation which simply delegates all function calls to
+ * an underlying ConnectionGroup.
+ */
+public class DelegatingConnectionGroup implements ConnectionGroup {
+
+    /**
+     * The wrapped ConnectionGroup.
+     */
+    private final ConnectionGroup connectionGroup;
+
+    /**
+     * Wraps the given ConnectionGroup such that all function calls against this
+     * DelegatingConnectionGroup will be delegated to it.
+     *
+     * @param connectionGroup
+     *     The ConnectionGroup to wrap.
+     */
+    public DelegatingConnectionGroup(ConnectionGroup connectionGroup) {
+        this.connectionGroup = connectionGroup;
+    }
+
+    @Override
+    public String getIdentifier() {
+        return connectionGroup.getIdentifier();
+    }
+
+    @Override
+    public void setIdentifier(String identifier) {
+        connectionGroup.setIdentifier(identifier);
+    }
+
+    @Override
+    public String getName() {
+        return connectionGroup.getName();
+    }
+
+    @Override
+    public void setName(String name) {
+        connectionGroup.setName(name);
+    }
+
+    @Override
+    public String getParentIdentifier() {
+        return connectionGroup.getParentIdentifier();
+    }
+
+    @Override
+    public void setParentIdentifier(String parentIdentifier) {
+        connectionGroup.setParentIdentifier(parentIdentifier);
+    }
+
+    @Override
+    public void setType(Type type) {
+        connectionGroup.setType(type);
+    }
+
+    @Override
+    public Type getType() {
+        return connectionGroup.getType();
+    }
+
+    @Override
+    public Set<String> getConnectionIdentifiers() throws GuacamoleException {
+        return connectionGroup.getConnectionIdentifiers();
+    }
+
+    @Override
+    public Set<String> getConnectionGroupIdentifiers() throws GuacamoleException {
+        return connectionGroup.getConnectionGroupIdentifiers();
+    }
+
+    @Override
+    public Map<String, String> getAttributes() {
+        return connectionGroup.getAttributes();
+    }
+
+    @Override
+    public void setAttributes(Map<String, String> attributes) {
+        connectionGroup.setAttributes(attributes);
+    }
+
+    @Override
+    public GuacamoleTunnel connect(GuacamoleClientInformation info) throws GuacamoleException {
+        return connectionGroup.connect(info);
+    }
+
+    @Override
+    public int getActiveConnections() {
+        return connectionGroup.getActiveConnections();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/b37e041d/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingSharingProfile.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingSharingProfile.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingSharingProfile.java
new file mode 100644
index 0000000..576e882
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingSharingProfile.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.net.auth;
+
+import java.util.Map;
+
+/**
+ * SharingProfile implementation which simply delegates all function calls to an
+ * underlying SharingProfile.
+ */
+public class DelegatingSharingProfile implements SharingProfile {
+
+    /**
+     * The wrapped SharingProfile.
+     */
+    private final SharingProfile sharingProfile;
+
+    /**
+     * Wraps the given SharingProfile such that all function calls against this
+     * DelegatingSharingProfile will be delegated to it.
+     *
+     * @param sharingProfile
+     *     The SharingProfile to wrap.
+     */
+    public DelegatingSharingProfile(SharingProfile sharingProfile) {
+        this.sharingProfile = sharingProfile;
+    }
+
+    @Override
+    public String getIdentifier() {
+        return sharingProfile.getIdentifier();
+    }
+
+    @Override
+    public void setIdentifier(String identifier) {
+        sharingProfile.setIdentifier(identifier);
+    }
+
+    @Override
+    public String getName() {
+        return sharingProfile.getName();
+    }
+
+    @Override
+    public void setName(String name) {
+        sharingProfile.setName(name);
+    }
+
+    @Override
+    public String getPrimaryConnectionIdentifier() {
+        return sharingProfile.getPrimaryConnectionIdentifier();
+    }
+
+    @Override
+    public void setPrimaryConnectionIdentifier(String identifier) {
+        sharingProfile.setPrimaryConnectionIdentifier(identifier);
+    }
+
+    @Override
+    public Map<String, String> getParameters() {
+        return sharingProfile.getParameters();
+    }
+
+    @Override
+    public void setParameters(Map<String, String> parameters) {
+        sharingProfile.setParameters(parameters);
+    }
+
+    @Override
+    public Map<String, String> getAttributes() {
+        return sharingProfile.getAttributes();
+    }
+
+    @Override
+    public void setAttributes(Map<String, String> attributes) {
+        sharingProfile.setAttributes(attributes);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/b37e041d/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingUser.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingUser.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingUser.java
new file mode 100644
index 0000000..65f0577
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingUser.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.net.auth;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
+import org.apache.guacamole.net.auth.permission.SystemPermissionSet;
+
+/**
+ * User implementation which simply delegates all function calls to an
+ * underlying User.
+ */
+public class DelegatingUser implements User {
+
+    /**
+     * The wrapped User.
+     */
+    private final User user;
+
+    /**
+     * Wraps the given User such that all function calls against this
+     * DelegatingUser will be delegated to it.
+     *
+     * @param user
+     *     The User to wrap.
+     */
+    public DelegatingUser(User user) {
+        this.user = user;
+    }
+
+    @Override
+    public String getIdentifier() {
+        return user.getIdentifier();
+    }
+
+    @Override
+    public void setIdentifier(String identifier) {
+        user.setIdentifier(identifier);
+    }
+
+    @Override
+    public String getPassword() {
+        return user.getPassword();
+    }
+
+    @Override
+    public void setPassword(String password) {
+        user.setPassword(password);
+    }
+
+    @Override
+    public Map<String, String> getAttributes() {
+        return user.getAttributes();
+    }
+
+    @Override
+    public void setAttributes(Map<String, String> attributes) {
+        user.setAttributes(attributes);
+    }
+
+    @Override
+    public Date getLastActive() {
+        return user.getLastActive();
+    }
+
+    @Override
+    public List<? extends ActivityRecord> getHistory()
+            throws GuacamoleException {
+        return user.getHistory();
+    }
+
+    @Override
+    public SystemPermissionSet getSystemPermissions()
+            throws GuacamoleException {
+        return user.getSystemPermissions();
+    }
+
+    @Override
+    public ObjectPermissionSet getConnectionPermissions()
+            throws GuacamoleException {
+        return user.getConnectionPermissions();
+    }
+
+    @Override
+    public ObjectPermissionSet getConnectionGroupPermissions()
+            throws GuacamoleException {
+        return user.getConnectionGroupPermissions();
+    }
+
+    @Override
+    public ObjectPermissionSet getSharingProfilePermissions()
+            throws GuacamoleException {
+        return user.getSharingProfilePermissions();
+    }
+
+    @Override
+    public ObjectPermissionSet getActiveConnectionPermissions()
+            throws GuacamoleException {
+        return user.getActiveConnectionPermissions();
+    }
+
+    @Override
+    public ObjectPermissionSet getUserPermissions() throws GuacamoleException {
+        return user.getUserPermissions();
+    }
+
+}


[2/9] guacamole-client git commit: GUACAMOLE-96: Add convenience class for overriding the behavior of an existing UserContext.

Posted by vn...@apache.org.
GUACAMOLE-96: Add convenience class for overriding the behavior of an existing UserContext.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/41059f5e
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/41059f5e
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/41059f5e

Branch: refs/heads/master
Commit: 41059f5e09016669b7384f71fd636ee28a8bc7c6
Parents: ffad189
Author: Michael Jumper <mj...@apache.org>
Authored: Fri Oct 27 11:08:08 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jan 13 17:23:02 2018 -0800

----------------------------------------------------------------------
 .../net/auth/DelegatingUserContext.java         | 134 +++++++++++++++++++
 1 file changed, 134 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/41059f5e/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingUserContext.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingUserContext.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingUserContext.java
new file mode 100644
index 0000000..a37faf9
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingUserContext.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.net.auth;
+
+import java.util.Collection;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.form.Form;
+
+/**
+ * UserContext implementation which simply delegates all function calls to
+ * an underlying UserContext.
+ */
+public class DelegatingUserContext implements UserContext {
+
+    /**
+     * The wrapped UserContext.
+     */
+    private final UserContext userContext;
+
+    /**
+     * Wraps the given UserContext such that all function calls against this
+     * DelegatingUserContext will be delegated to it.
+     *
+     * @param userContext
+     *     The UserContext to wrap.
+     */
+    public DelegatingUserContext(UserContext userContext) {
+        this.userContext = userContext;
+    }
+
+    @Override
+    public User self() {
+        return userContext.self();
+    }
+
+    @Override
+    public Object getResource() throws GuacamoleException {
+        return userContext.getResource();
+    }
+
+    @Override
+    public AuthenticationProvider getAuthenticationProvider() {
+        return userContext.getAuthenticationProvider();
+    }
+
+    @Override
+    public Directory<User> getUserDirectory() throws GuacamoleException {
+        return userContext.getUserDirectory();
+    }
+
+    @Override
+    public Directory<Connection> getConnectionDirectory()
+            throws GuacamoleException {
+        return userContext.getConnectionDirectory();
+    }
+
+    @Override
+    public Directory<ConnectionGroup> getConnectionGroupDirectory()
+            throws GuacamoleException {
+        return userContext.getConnectionGroupDirectory();
+    }
+
+    @Override
+    public Directory<ActiveConnection> getActiveConnectionDirectory()
+            throws GuacamoleException {
+        return userContext.getActiveConnectionDirectory();
+    }
+
+    @Override
+    public Directory<SharingProfile> getSharingProfileDirectory()
+            throws GuacamoleException {
+        return userContext.getSharingProfileDirectory();
+    }
+
+    @Override
+    public ActivityRecordSet<ConnectionRecord> getConnectionHistory()
+            throws GuacamoleException {
+        return userContext.getConnectionHistory();
+    }
+
+    @Override
+    public ActivityRecordSet<ActivityRecord> getUserHistory()
+            throws GuacamoleException {
+        return userContext.getUserHistory();
+    }
+
+    @Override
+    public ConnectionGroup getRootConnectionGroup() throws GuacamoleException {
+        return userContext.getRootConnectionGroup();
+    }
+
+    @Override
+    public Collection<Form> getUserAttributes() {
+        return userContext.getUserAttributes();
+    }
+
+    @Override
+    public Collection<Form> getConnectionAttributes() {
+        return userContext.getConnectionAttributes();
+    }
+
+    @Override
+    public Collection<Form> getConnectionGroupAttributes() {
+        return userContext.getConnectionGroupAttributes();
+    }
+
+    @Override
+    public Collection<Form> getSharingProfileAttributes() {
+        return userContext.getSharingProfileAttributes();
+    }
+
+    @Override
+    public void invalidate() {
+        userContext.invalidate();
+    }
+
+}


[7/9] guacamole-client git commit: GUACAMOLE-96: Objects should be decorated upon add(), not undecorated (they by definition come from an external source, not the decorated extension).

Posted by vn...@apache.org.
GUACAMOLE-96: Objects should be decorated upon add(), not undecorated (they by definition come from an external source, not the decorated extension).


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/63bb3a03
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/63bb3a03
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/63bb3a03

Branch: refs/heads/master
Commit: 63bb3a033ae344f81ad29795c4f19e277d39d7b0
Parents: b37e041
Author: Michael Jumper <mj...@apache.org>
Authored: Wed Nov 22 09:52:59 2017 -0800
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jan 13 17:23:19 2018 -0800

----------------------------------------------------------------------
 .../java/org/apache/guacamole/net/auth/DecoratingDirectory.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/63bb3a03/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
index 23ea087..bb2eac4 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
@@ -122,7 +122,7 @@ public abstract class DecoratingDirectory<ObjectType extends Identifiable>
 
     @Override
     public void add(ObjectType object) throws GuacamoleException {
-        super.add(undecorate(object));
+        super.add(decorate(object));
     }
 
     @Override


[8/9] guacamole-client git commit: GUACAMOLE-96: Rearrange logic of DecoratingDirectory.get() to make more intuitive sense.

Posted by vn...@apache.org.
GUACAMOLE-96: Rearrange logic of DecoratingDirectory.get() to make more intuitive sense.

Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/1c99f6a8
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/1c99f6a8
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/1c99f6a8

Branch: refs/heads/master
Commit: 1c99f6a8cf45b55f142c8526b81717313abc886c
Parents: 63bb3a0
Author: Michael Jumper <mj...@apache.org>
Authored: Wed Jan 17 18:41:36 2018 -0800
Committer: Michael Jumper <mj...@apache.org>
Committed: Wed Jan 17 18:41:36 2018 -0800

----------------------------------------------------------------------
 .../org/apache/guacamole/net/auth/DecoratingDirectory.java    | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1c99f6a8/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
index bb2eac4..dc35e3b 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
@@ -99,10 +99,11 @@ public abstract class DecoratingDirectory<ObjectType extends Identifiable>
 
         // Decorate only if object exists
         ObjectType object = super.get(identifier);
-        if (object == null)
-            return object;
+        if (object != null)
+            return decorate(object);
+
+        return null;
 
-        return decorate(object);
     }
 
     @Override


[9/9] guacamole-client git commit: GUACAMOLE-96: Merge allow extensions to decorate each other's objects.

Posted by vn...@apache.org.
GUACAMOLE-96: Merge allow extensions to decorate each other's objects.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/eaeaeb10
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/eaeaeb10
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/eaeaeb10

Branch: refs/heads/master
Commit: eaeaeb10cd56a6e90d14fcf564f32be2f157e431
Parents: 9d58749 1c99f6a
Author: Nick Couchman <vn...@apache.org>
Authored: Tue Jan 30 14:31:04 2018 -0500
Committer: Nick Couchman <vn...@apache.org>
Committed: Tue Jan 30 14:31:04 2018 -0500

----------------------------------------------------------------------
 .../auth/cas/CASAuthenticationProvider.java     |  14 +
 .../auth/duo/DuoAuthenticationProvider.java     |  14 +
 .../HTTPHeaderAuthenticationProvider.java       |  14 +
 .../jdbc/InjectedAuthenticationProvider.java    |  14 +
 .../auth/ldap/LDAPAuthenticationProvider.java   |  14 +
 .../openid/OpenIDAuthenticationProvider.java    |  14 +
 .../net/auth/AuthenticationProvider.java        |  73 ++++
 .../guacamole/net/auth/DecoratingDirectory.java | 134 +++++++
 .../net/auth/DelegatingConnection.java          | 131 +++++++
 .../net/auth/DelegatingConnectionGroup.java     | 120 ++++++
 .../guacamole/net/auth/DelegatingDirectory.java |  83 +++++
 .../net/auth/DelegatingSharingProfile.java      |  96 +++++
 .../guacamole/net/auth/DelegatingUser.java      | 127 +++++++
 .../net/auth/DelegatingUserContext.java         | 134 +++++++
 .../simple/SimpleAuthenticationProvider.java    |  17 +
 .../org/apache/guacamole/GuacamoleSession.java  |  13 +-
 .../extension/AuthenticationProviderFacade.java |  29 ++
 .../guacamole/rest/RESTServiceModule.java       |   2 +
 .../rest/auth/AuthenticationService.java        |  31 +-
 .../rest/auth/DecoratedUserContext.java         | 361 +++++++++++++++++++
 .../guacamole/rest/auth/DecorationService.java  | 145 ++++++++
 .../guacamole/rest/auth/TokenRESTService.java   |   2 +-
 22 files changed, 1565 insertions(+), 17 deletions(-)
----------------------------------------------------------------------



[5/9] guacamole-client git commit: GUACAMOLE-96: Add convenience class for decorating the objects returned by a Directory.

Posted by vn...@apache.org.
GUACAMOLE-96: Add convenience class for decorating the objects returned by a Directory.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/a915f7b1
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/a915f7b1
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/a915f7b1

Branch: refs/heads/master
Commit: a915f7b190bd6a0ce01e3e991daabed95d26493f
Parents: 7357e51
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Oct 28 22:43:31 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jan 13 17:23:13 2018 -0800

----------------------------------------------------------------------
 .../guacamole/net/auth/DecoratingDirectory.java | 133 +++++++++++++++++++
 .../guacamole/net/auth/DelegatingDirectory.java |  83 ++++++++++++
 2 files changed, 216 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/a915f7b1/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
new file mode 100644
index 0000000..23ea087
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.net.auth;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import org.apache.guacamole.GuacamoleException;
+
+/**
+ * Directory implementation which simplifies decorating the objects within an
+ * underlying Directory. The decorate() and undecorate() functions must be
+ * implemented to define how each object is decorated, and how that decoration
+ * may be removed.
+ *
+ * @param <ObjectType>
+ *     The type of objects stored within this Directory.
+ */
+public abstract class DecoratingDirectory<ObjectType extends Identifiable>
+        extends DelegatingDirectory<ObjectType> {
+
+    /**
+     * Creates a new DecoratingDirectory which decorates the objects within
+     * the given directory.
+     *
+     * @param directory
+     *     The Directory whose objects are being decorated.
+     */
+    public DecoratingDirectory(Directory<ObjectType> directory) {
+        super(directory);
+    }
+
+    /**
+     * Given an object retrieved from a Directory which originates from a
+     * different AuthenticationProvider, returns an identical type of object
+     * optionally wrapped with additional information, functionality, etc. If
+     * this directory chooses to decorate the object provided, it is up to the
+     * implementation of that decorated object to properly pass through
+     * operations as appropriate, as well as provide for an eventual
+     * undecorate() operation. All objects retrieved from this
+     * DecoratingDirectory will first be passed through this function.
+     *
+     * @param object
+     *     An object from a Directory which originates from a different
+     *     AuthenticationProvider.
+     *
+     * @return
+     *     An object which may have been decorated by this
+     *     DecoratingDirectory. If the object was not decorated, the original,
+     *     unmodified object may be returned instead.
+     *
+     * @throws GuacamoleException
+     *     If the provided object cannot be decorated due to an error.
+     */
+    protected abstract ObjectType decorate(ObjectType object)
+            throws GuacamoleException;
+
+    /**
+     * Given an object originally returned from a call to this
+     * DecoratingDirectory's decorate() function, reverses the decoration
+     * operation, returning the original object. This function is effectively
+     * the exact inverse of the decorate() function. The return value of
+     * undecorate(decorate(X)) must be identically X. All objects given to this
+     * DecoratingDirectory via add() or update() will first be passed through
+     * this function.
+     *
+     * @param object
+     *     An object which was originally returned by a call to this
+     *     DecoratingDirectory's decorate() function.
+     *
+     * @return
+     *     The original object which was provided to this DecoratingDirectory's
+     *     decorate() function.
+     *
+     * @throws GuacamoleException
+     *     If the provided object cannot be undecorated due to an error.
+     */
+    protected abstract ObjectType undecorate(ObjectType object)
+            throws GuacamoleException;
+
+    @Override
+    public ObjectType get(String identifier) throws GuacamoleException {
+
+        // Decorate only if object exists
+        ObjectType object = super.get(identifier);
+        if (object == null)
+            return object;
+
+        return decorate(object);
+    }
+
+    @Override
+    public Collection<ObjectType> getAll(Collection<String> identifiers)
+            throws GuacamoleException {
+
+        Collection<ObjectType> objects = super.getAll(identifiers);
+
+        // Decorate all retrieved objects, if any
+        Collection<ObjectType> decorated = new ArrayList<ObjectType>(objects.size());
+        for (ObjectType object : objects)
+            decorated.add(decorate(object));
+
+        return decorated;
+
+    }
+
+    @Override
+    public void add(ObjectType object) throws GuacamoleException {
+        super.add(undecorate(object));
+    }
+
+    @Override
+    public void update(ObjectType object) throws GuacamoleException {
+        super.update(undecorate(object));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/a915f7b1/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingDirectory.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingDirectory.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingDirectory.java
new file mode 100644
index 0000000..f1bf274
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingDirectory.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.net.auth;
+
+import java.util.Collection;
+import java.util.Set;
+import org.apache.guacamole.GuacamoleException;
+
+/**
+ * Directory implementation which simply delegates all function calls to an
+ * underlying Directory.
+ *
+ * @param <ObjectType>
+ *     The type of objects stored within this Directory.
+ */
+public class DelegatingDirectory<ObjectType extends Identifiable>
+        implements Directory<ObjectType> {
+
+    /**
+     * The wrapped Directory.
+     */
+    private final Directory<ObjectType> directory;
+
+    /**
+     * Wraps the given Directory such that all function calls against this
+     * DelegatingDirectory will be delegated to it.
+     *
+     * @param directory
+     *     The directory to wrap.
+     */
+    public DelegatingDirectory(Directory<ObjectType> directory) {
+        this.directory = directory;
+    }
+
+    @Override
+    public ObjectType get(String identifier) throws GuacamoleException {
+        return directory.get(identifier);
+    }
+
+    @Override
+    public Collection<ObjectType> getAll(Collection<String> identifiers)
+            throws GuacamoleException {
+        return directory.getAll(identifiers);
+    }
+
+    @Override
+    public Set<String> getIdentifiers() throws GuacamoleException {
+        return directory.getIdentifiers();
+    }
+
+    @Override
+    public void add(ObjectType object) throws GuacamoleException {
+        directory.add(object);
+    }
+
+    @Override
+    public void update(ObjectType object) throws GuacamoleException {
+        directory.update(object);
+    }
+
+    @Override
+    public void remove(String identifier) throws GuacamoleException {
+        directory.remove(identifier);
+    }
+
+}