GUACAMOLE-38: Use newly-implemented AbstractuserContext and 
AbstractAuthenticationProvider classes, remove deprecated classes.


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

Branch: refs/heads/master
Commit: 3feb2c2de1d1d1af96e422b2050e85cb499c39ef
Parents: 43919e5
Author: Nick Couchman <vn...@apache.org>
Authored: Sat Apr 14 11:22:40 2018 -0400
Committer: Nick Couchman <vn...@apache.org>
Committed: Fri Jun 1 13:40:51 2018 -0400

----------------------------------------------------------------------
 .../QuickConnectAuthenticationProvider.java     | 70 +----------------
 .../quickconnect/QuickConnectDirectory.java     | 71 +++++------------
 .../quickconnect/QuickConnectUserContext.java   | 81 ++++----------------
 3 files changed, 34 insertions(+), 188 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/3feb2c2d/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProvider.java
----------------------------------------------------------------------
diff --git 
a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProvider.java
 
b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProvider.java
index d638ff8..6e6f2bc 100644
--- 
a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProvider.java
+++ 
b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProvider.java
@@ -23,7 +23,7 @@ import java.util.Collections;
 import java.util.Map;
 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.AbstractAuthenticationProvider;
 import org.apache.guacamole.net.auth.Credentials;
 import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
 import 
org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
@@ -35,7 +35,7 @@ import org.apache.guacamole.protocol.GuacamoleConfiguration;
  * process so that the QuickConnect functionality can be initialized and be 
used
  * throughout the web client.
  */
-public class QuickConnectAuthenticationProvider implements 
AuthenticationProvider {
+public class QuickConnectAuthenticationProvider extends 
AbstractAuthenticationProvider {
 
     /**
      * userContext for this authentication provider.
@@ -48,31 +48,6 @@ public class QuickConnectAuthenticationProvider implements 
AuthenticationProvide
     }
 
     @Override
-    public Object getResource() throws GuacamoleException {
-        return null;
-    }
-
-    /**
-     * For QuickConnect, authenticateUser simply returns null because this
-     * extension is designed to provide only a connection directory to users
-     * that are already authenticated and not any actual authentication.
-     *
-     * @param credentials
-     *     Credentials object passed in from Guacamole login.
-     *
-     * @return
-     *     Returns null, which causes the client to move on to the next
-     *     module.
-     */
-    @Override
-    public AuthenticatedUser authenticateUser(Credentials credentials)
-        throws GuacamoleException {
-
-        return null;
-
-    }
-
-    @Override
     public UserContext getUserContext(AuthenticatedUser authenticatedUser)
             throws GuacamoleException {
 
@@ -80,45 +55,4 @@ public class QuickConnectAuthenticationProvider implements 
AuthenticationProvide
 
     }
 
-    @Override
-    public AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser 
authenticatedUser,
-            Credentials credentials) throws GuacamoleException {
-
-        // Simply return the given user, updating nothing
-        return authenticatedUser;
-
-    }
-
-    @Override
-    public UserContext updateUserContext(UserContext context,
-        AuthenticatedUser authorizedUser, Credentials credentials)
-            throws GuacamoleException {
-
-        // Simply return the given context, updating nothing
-        return context;
-
-    }
-
-    @Override
-    public UserContext decorate(UserContext context,
-            AuthenticatedUser authenticatedUser, Credentials credentials)
-            throws GuacamoleException {
-
-        // Simply return the given context, decorating nothing
-        return context;
-
-    }
-
-    @Override
-    public UserContext redecorate(UserContext decorated, UserContext context,
-            AuthenticatedUser authenticatedUser, Credentials credentials)
-            throws GuacamoleException {
-        return decorate(context, authenticatedUser, credentials);
-    }
-
-    @Override
-    public void shutdown() {
-        // Nothing to do, here.
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/3feb2c2d/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
----------------------------------------------------------------------
diff --git 
a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
 
b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
index 2e19870..d17c25b 100644
--- 
a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
+++ 
b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
@@ -19,12 +19,13 @@
 
 package org.apache.guacamole.auth.quickconnect;
 
-import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.guacamole.GuacamoleException;
 import org.apache.guacamole.auth.quickconnect.utility.QCParser;
 import org.apache.guacamole.net.auth.ConnectionGroup;
-import org.apache.guacamole.net.auth.simple.SimpleConnectionDirectory;
+import org.apache.guacamole.net.auth.simple.SimpleDirectory;
 import org.apache.guacamole.net.auth.Connection;
 import org.apache.guacamole.protocol.GuacamoleConfiguration;
 
@@ -32,7 +33,7 @@ import org.apache.guacamole.protocol.GuacamoleConfiguration;
  * Implementation of the Connection Directory, stored
  * completely in-memory.
  */
-public class QuickConnectDirectory extends SimpleConnectionDirectory {
+public class QuickConnectDirectory extends SimpleDirectory<Connection> {
 
     /**
      * The unique identifier of the root connection group.
@@ -40,6 +41,12 @@ public class QuickConnectDirectory extends 
SimpleConnectionDirectory {
     private static final String ROOT_IDENTIFIER = "ROOT";
 
     /**
+     * The connections to store.
+     */
+    private final Map<String, Connection> connections =
+            new HashMap<String, Connection>();
+
+    /**
      * The root connection group for this directory.
      */
     private final QuickConnectConnectionGroup rootGroup;
@@ -54,15 +61,15 @@ public class QuickConnectDirectory extends 
SimpleConnectionDirectory {
      * connections contained within the given Map.
      *
      * @param connections
-     *     A Collection of all connections that should be present in this
+     *     A Map of all connections that should be present in this
      *     connection directory.
      * @param rootGroup
      *     A group that should be at the base of this directory.
      */
-    public QuickConnectDirectory(Collection<Connection> connections, 
ConnectionGroup rootGroup) {
-        super(connections);
+    public QuickConnectDirectory(ConnectionGroup rootGroup) {
         this.rootGroup = (QuickConnectConnectionGroup)rootGroup;
         this.connectionId = new AtomicInteger();
+        super.setObjects(this.connections);
     }
 
     /**
@@ -77,56 +84,21 @@ public class QuickConnectDirectory extends 
SimpleConnectionDirectory {
     }
 
     @Override
-    public void add(Connection object) throws GuacamoleException {
-
-        put(new QuickConnection(object));
-
-    }
-
-    /**
-     * Create a connection object on the tree using an existing
-     * QuickConnection connection, after setting the identifier
-     * and parent object.
-     *
-     * @param connection
-     *     The QuickConnection object to add to the tree.
-     *
-     * @return
-     *     The connectionId of the object added to the directory.
-     *
-     * @throws GuacamoleException
-     *     If an error is encountered adding the object to the
-     *     directory.
-     */
-    public String put(QuickConnection connection) throws GuacamoleException {
-
-        // Get the next connection ID.
-        String connectionId = Integer.toString(getNextConnectionID());
-
-        // Set up identifier and parent on object.
-        connection.setIdentifier(connectionId);
-        connection.setParentIdentifier(ROOT_IDENTIFIER);
-
-        // Add connection to the directory
-        putConnection(connection);
-
-        // Add connection to the tree
-        this.rootGroup.addConnectionIdentifier(connectionId);
-
-        return connectionId;
-
+    public void add(Connection connection) throws GuacamoleException {
+        connections.put(connection.getIdentifier(), connection);
     }
 
     /**
      * Create a QuickConnection object from a GuacamoleConfiguration
-     * and get an ID and place it on the tree.
+     * and get an ID and place it on the tree, returning the new
+     * connection identifier value.
      *
      * @param config
      *     The GuacamoleConfiguration to use to create the
      *     QuickConnection object.
      *
      * @return
-     *     The connectionId of the object creation in the directory.
+     *     The identifier of the connection created in the directory.
      *
      * @throws GuacamoleException
      *     If an error occurs adding the object to the tree.
@@ -144,7 +116,7 @@ public class QuickConnectDirectory extends 
SimpleConnectionDirectory {
         connection.setParentIdentifier(ROOT_IDENTIFIER);
 
         // Place the object in directory
-        putConnection(connection);
+        add(connection);
 
         // Add connection to the tree.
         this.rootGroup.addConnectionIdentifier(connectionId);
@@ -152,9 +124,4 @@ public class QuickConnectDirectory extends 
SimpleConnectionDirectory {
         return connectionId;
     }
 
-    @Override
-    public void update(Connection object) throws GuacamoleException {
-        putConnection(object);
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/3feb2c2d/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectUserContext.java
----------------------------------------------------------------------
diff --git 
a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectUserContext.java
 
b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectUserContext.java
index 06ef630..60f6ded 100644
--- 
a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectUserContext.java
+++ 
b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectUserContext.java
@@ -24,6 +24,7 @@ import java.util.Collections;
 import org.apache.guacamole.auth.quickconnect.rest.QuickConnectREST;
 import org.apache.guacamole.GuacamoleException;
 import org.apache.guacamole.form.Form;
+import org.apache.guacamole.net.auth.AbstractUserContext;
 import org.apache.guacamole.net.auth.ActiveConnection;
 import org.apache.guacamole.net.auth.ActivityRecord;
 import org.apache.guacamole.net.auth.ActivityRecordSet;
@@ -36,22 +37,15 @@ import org.apache.guacamole.net.auth.SharingProfile;
 import org.apache.guacamole.net.auth.User;
 import org.apache.guacamole.net.auth.UserContext;
 import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet;
-import org.apache.guacamole.net.auth.simple.SimpleConnectionGroupDirectory;
 import org.apache.guacamole.net.auth.simple.SimpleDirectory;
 import org.apache.guacamole.net.auth.simple.SimpleUser;
-import org.apache.guacamole.net.auth.simple.SimpleUserDirectory;
 
 /**
  * A simple implementation of UserContext to support the QuickConnect
  * extension, primarily used for storing connections the user has
  * created using the QuickConnect bar in the webapp.
  */
-public class QuickConnectUserContext implements UserContext {
-
-    /**
-     * The unique identifier of the root connection group.
-     */
-    public static final String ROOT_IDENTIFIER = "ROOT";
+public class QuickConnectUserContext extends AbstractUserContext {
 
     /**
      * The AuthenticationProvider that created this UserContext.
@@ -104,20 +98,21 @@ public class QuickConnectUserContext implements 
UserContext {
         // Initialize the rootGroup to a basic connection group with a
         // single root identifier.
         this.rootGroup = new QuickConnectConnectionGroup(
-            ROOT_IDENTIFIER, ROOT_IDENTIFIER
+            DEFAULT_ROOT_CONNECTION_GROUP,
+            DEFAULT_ROOT_CONNECTION_GROUP
         );
 
         // Initialize the user to a SimpleUser with the username, no
         // preexisting connections, and the single root group.
         this.self = new SimpleUser(username,
             Collections.<String>emptyList(),
-            Collections.singleton(ROOT_IDENTIFIER)
+            Collections.singleton(DEFAULT_ROOT_CONNECTION_GROUP)
         );
 
         // Initialize each of the directories associated with the userContext.
-        this.userDirectory = new SimpleUserDirectory(self);
-        this.connectionDirectory = new 
QuickConnectDirectory(Collections.<Connection>emptyList(), this.rootGroup);
-        this.connectionGroupDirectory = new 
SimpleConnectionGroupDirectory(Collections.singleton(this.rootGroup));
+        this.userDirectory = new SimpleDirectory<User>(self);
+        this.connectionDirectory = new QuickConnectDirectory(this.rootGroup);
+        this.connectionGroupDirectory = new 
SimpleDirectory<ConnectionGroup>(Collections.singleton(this.rootGroup));
 
         // Set the authProvider to the calling authProvider object.
         this.authProvider = authProvider;
@@ -125,6 +120,11 @@ public class QuickConnectUserContext implements 
UserContext {
     }
 
     @Override
+    public QuickConnectDirectory getConnectionDirectory() {
+        return connectionDirectory;
+    }
+
+    @Override
     public User self() {
         return self;
     }
@@ -135,11 +135,6 @@ public class QuickConnectUserContext implements 
UserContext {
     }
 
     @Override
-    public void invalidate() {
-        // Do nothing.
-    }
-
-    @Override
     public AuthenticationProvider getAuthenticationProvider() {
         return authProvider;
     }
@@ -151,18 +146,6 @@ public class QuickConnectUserContext implements 
UserContext {
     }
 
     @Override
-    public ActivityRecordSet<ActivityRecord> getUserHistory()
-            throws GuacamoleException {
-        return new SimpleActivityRecordSet<ActivityRecord>();
-    }
-
-    @Override
-    public QuickConnectDirectory getConnectionDirectory()
-            throws GuacamoleException {
-        return connectionDirectory;
-    }
-
-    @Override
     public Directory<ConnectionGroup> getConnectionGroupDirectory()
             throws GuacamoleException {
         return connectionGroupDirectory;
@@ -173,42 +156,4 @@ public class QuickConnectUserContext implements 
UserContext {
         return rootGroup;
     }
 
-    @Override
-    public Directory<SharingProfile> getSharingProfileDirectory()
-            throws GuacamoleException {
-        return new SimpleDirectory<SharingProfile>();
-    }
-
-    @Override
-    public Directory<ActiveConnection> getActiveConnectionDirectory()
-            throws GuacamoleException {
-        return new SimpleDirectory<ActiveConnection>();
-    }
-
-    @Override
-    public ActivityRecordSet<ConnectionRecord> getConnectionHistory()
-            throws GuacamoleException {
-        return new SimpleActivityRecordSet<ConnectionRecord>();
-    }
-
-    @Override
-    public Collection<Form> getUserAttributes() {
-        return Collections.<Form>emptyList();
-    }
-
-    @Override
-    public Collection<Form> getConnectionAttributes() {
-        return Collections.<Form>emptyList();
-    }
-
-    @Override
-    public Collection<Form> getConnectionGroupAttributes() {
-        return Collections.<Form>emptyList();
-    }
-
-    @Override
-    public Collection<Form> getSharingProfileAttributes() {
-        return Collections.<Form>emptyList();
-    }
-
 }

Reply via email to