You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by jm...@apache.org on 2018/11/09 04:44:58 UTC

[02/13] guacamole-client git commit: GUACAMOLE-220: Add user group permissions to SimpleUser.

GUACAMOLE-220: Add user group permissions to SimpleUser.


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

Branch: refs/heads/staging/1.0.0
Commit: 929c7de2c9a50d8b7727f5fc107bdc2b355c3f8f
Parents: 5362bc6
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Nov 3 10:09:14 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Nov 3 12:41:54 2018 -0700

----------------------------------------------------------------------
 .../guacamole/net/auth/simple/SimpleUser.java   | 66 +++++++++++++++-----
 1 file changed, 52 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/929c7de2/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUser.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUser.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUser.java
index 61fce20..302150e 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUser.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUser.java
@@ -41,22 +41,24 @@ import org.apache.guacamole.net.auth.permission.SystemPermissionSet;
 public class SimpleUser extends AbstractUser {
 
     /**
-     * All connection permissions granted to this user.
+     * All user permissions granted to this user.
      */
-    private final Set<ObjectPermission> userPermissions =
-            new HashSet<ObjectPermission>();
+    private final Set<ObjectPermission> userPermissions = new HashSet<>();
+
+    /**
+     * All user group permissions granted to this user.
+     */
+    private final Set<ObjectPermission> userGroupPermissions = new HashSet<>();
 
     /**
      * All connection permissions granted to this user.
      */
-    private final Set<ObjectPermission> connectionPermissions =
-            new HashSet<ObjectPermission>();
+    private final Set<ObjectPermission> connectionPermissions = new HashSet<>();
     
     /**
      * All connection group permissions granted to this user.
      */
-    private final Set<ObjectPermission> connectionGroupPermissions =
-            new HashSet<ObjectPermission>();
+    private final Set<ObjectPermission> connectionGroupPermissions = new HashSet<>();
 
     /**
      * Creates a completely uninitialized SimpleUser.
@@ -73,7 +75,7 @@ public class SimpleUser extends AbstractUser {
     public SimpleUser(String username) {
 
         // Set username
-        setIdentifier(username);
+        super.setIdentifier(username);
 
     }
 
@@ -92,18 +94,17 @@ public class SimpleUser extends AbstractUser {
             Collection<String> identifiers) {
 
         // Add a READ permission to the set for each identifier given
-        for (String identifier : identifiers) {
-            permissions.add(new ObjectPermission (
+        identifiers.forEach(identifier ->
+            permissions.add(new ObjectPermission(
                 ObjectPermission.Type.READ,
-                identifier
+                identifier)
             ));
-        }
 
     }
-    
+
     /**
      * Creates a new SimpleUser having the given username and READ access to
-     * the connections and groups having the given identifiers.
+     * the connections and connection groups having the given identifiers.
      *
      * @param username
      *     The username to assign to this SimpleUser.
@@ -129,6 +130,43 @@ public class SimpleUser extends AbstractUser {
 
     /**
      * Creates a new SimpleUser having the given username and READ access to
+     * the users, user groups, connections, and connection groups having the
+     * given identifiers.
+     *
+     * @param username
+     *     The username to assign to this SimpleUser.
+     *
+     * @param userIdentifiers
+     *     The identifiers of all users this user has READ access to.
+     *
+     * @param userGroupIdentifiers
+     *     The identifiers of all user groups this user has READ access to.
+     *
+     * @param connectionIdentifiers
+     *     The identifiers of all connections this user has READ access to.
+     *
+     * @param connectionGroupIdentifiers
+     *     The identifiers of all connection groups this user has READ access
+     *     to.
+     */
+    public SimpleUser(String username,
+            Collection<String> userIdentifiers,
+            Collection<String> userGroupIdentifiers,
+            Collection<String> connectionIdentifiers,
+            Collection<String> connectionGroupIdentifiers) {
+
+        this(username);
+
+        // Add permissions
+        addReadPermissions(userPermissions,            userIdentifiers);
+        addReadPermissions(userGroupPermissions,       userGroupIdentifiers);
+        addReadPermissions(connectionPermissions,      connectionIdentifiers);
+        addReadPermissions(connectionGroupPermissions, connectionGroupIdentifiers);
+
+    }
+
+    /**
+     * Creates a new SimpleUser having the given username and READ access to
      * the users, connections, and groups having the given identifiers.
      *
      * @param username