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:45:03 UTC
[07/13] guacamole-client git commit: GUACAMOLE-220: Add EMPTY_SET
convenience constant to all core set interfaces.
GUACAMOLE-220: Add EMPTY_SET convenience constant to all core set interfaces.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/d533de11
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/d533de11
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/d533de11
Branch: refs/heads/staging/1.0.0
Commit: d533de118f26000cba4eefd6571964ba6614810b
Parents: d10256e
Author: Michael Jumper <mj...@apache.org>
Authored: Fri Nov 2 16:01:48 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Nov 3 14:08:46 2018 -0700
----------------------------------------------------------------------
.../auth/jdbc/sharing/user/SharedUser.java | 13 ++---
.../guacamole/net/auth/RelatedObjectSet.java | 26 ++++++++++
.../auth/permission/ObjectPermissionSet.java | 52 ++++++++++++++++++++
.../auth/permission/SystemPermissionSet.java | 46 +++++++++++++++++
.../auth/simple/SimpleObjectPermissionSet.java | 5 +-
.../net/auth/simple/SimpleRelatedObjectSet.java | 5 +-
.../auth/simple/SimpleSystemPermissionSet.java | 5 +-
.../guacamole/net/auth/simple/SimpleUser.java | 10 ++--
.../net/auth/simple/SimpleUserGroup.java | 20 ++++----
9 files changed, 156 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/d533de11/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUser.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUser.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUser.java
index 697b2ca..f0a48b8 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUser.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUser.java
@@ -35,9 +35,6 @@ import org.apache.guacamole.net.auth.RelatedObjectSet;
import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
import org.apache.guacamole.net.auth.permission.SystemPermissionSet;
-import org.apache.guacamole.net.auth.simple.SimpleObjectPermissionSet;
-import org.apache.guacamole.net.auth.simple.SimpleRelatedObjectSet;
-import org.apache.guacamole.net.auth.simple.SimpleSystemPermissionSet;
/**
* An immutable implementation of User which defines READ permission for each of
@@ -122,7 +119,7 @@ public class SharedUser implements User {
@Override
public SystemPermissionSet getSystemPermissions() throws GuacamoleException {
- return new SimpleSystemPermissionSet();
+ return SystemPermissionSet.EMPTY_SET;
}
@Override
@@ -145,22 +142,22 @@ public class SharedUser implements User {
@Override
public ObjectPermissionSet getUserGroupPermissions() throws GuacamoleException {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public ObjectPermissionSet getSharingProfilePermissions() throws GuacamoleException {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public ObjectPermissionSet getActiveConnectionPermissions() throws GuacamoleException {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public RelatedObjectSet getUserGroups() throws GuacamoleException {
- return new SimpleRelatedObjectSet();
+ return RelatedObjectSet.EMPTY_SET;
}
@Override
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/d533de11/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/RelatedObjectSet.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/RelatedObjectSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/RelatedObjectSet.java
index 58bee37..f49876d 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/RelatedObjectSet.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/RelatedObjectSet.java
@@ -19,8 +19,10 @@
package org.apache.guacamole.net.auth;
+import java.util.Collections;
import java.util.Set;
import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleSecurityException;
/**
* An arbitrary set of existing objects sharing some common relation. Unlike a
@@ -75,4 +77,28 @@ public interface RelatedObjectSet {
*/
void removeObjects(Set<String> identifiers) throws GuacamoleException;
+ /**
+ * An immutable instance of RelatedObjectSEt which contains no objects.
+ */
+ static final RelatedObjectSet EMPTY_SET = new RelatedObjectSet() {
+
+ @Override
+ public Set<String> getObjects() throws GuacamoleException {
+ return Collections.<String>emptySet();
+ }
+
+ @Override
+ public void addObjects(Set<String> identifiers)
+ throws GuacamoleException {
+ throw new GuacamoleSecurityException("Permission denied.");
+ }
+
+ @Override
+ public void removeObjects(Set<String> identifiers)
+ throws GuacamoleException {
+ throw new GuacamoleSecurityException("Permission denied.");
+ }
+
+ };
+
}
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/d533de11/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/permission/ObjectPermissionSet.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/permission/ObjectPermissionSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/permission/ObjectPermissionSet.java
index 3c3e910..d9ce666 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/permission/ObjectPermissionSet.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/permission/ObjectPermissionSet.java
@@ -20,8 +20,10 @@
package org.apache.guacamole.net.auth.permission;
import java.util.Collection;
+import java.util.Collections;
import java.util.Set;
import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleSecurityException;
/**
@@ -126,4 +128,54 @@ public interface ObjectPermissionSet extends PermissionSet<ObjectPermission> {
void removePermissions(Set<ObjectPermission> permissions)
throws GuacamoleException;
+ /**
+ * An immutable instance of ObjectPermissionSet which contains no
+ * permissions.
+ */
+ static final ObjectPermissionSet EMPTY_SET = new ObjectPermissionSet() {
+
+ @Override
+ public boolean hasPermission(ObjectPermission.Type permission,
+ String identifier) throws GuacamoleException {
+ return false;
+ }
+
+ @Override
+ public void addPermission(ObjectPermission.Type permission,
+ String identifier) throws GuacamoleException {
+ throw new GuacamoleSecurityException("Permission denied.");
+ }
+
+ @Override
+ public void removePermission(ObjectPermission.Type permission,
+ String identifier) throws GuacamoleException {
+ throw new GuacamoleSecurityException("Permission denied.");
+ }
+
+ @Override
+ public Collection<String> getAccessibleObjects(Collection<ObjectPermission.Type> permissions,
+ Collection<String> identifiers) throws GuacamoleException {
+ return Collections.<String>emptySet();
+ }
+
+ @Override
+ public Set<ObjectPermission> getPermissions()
+ throws GuacamoleException {
+ return Collections.<ObjectPermission>emptySet();
+ }
+
+ @Override
+ public void addPermissions(Set<ObjectPermission> permissions)
+ throws GuacamoleException {
+ throw new GuacamoleSecurityException("Permission denied.");
+ }
+
+ @Override
+ public void removePermissions(Set<ObjectPermission> permissions)
+ throws GuacamoleException {
+ throw new GuacamoleSecurityException("Permission denied.");
+ }
+
+ };
+
}
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/d533de11/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/permission/SystemPermissionSet.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/permission/SystemPermissionSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/permission/SystemPermissionSet.java
index 3f504db..b58baa6 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/permission/SystemPermissionSet.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/permission/SystemPermissionSet.java
@@ -19,8 +19,10 @@
package org.apache.guacamole.net.auth.permission;
+import java.util.Collections;
import java.util.Set;
import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleSecurityException;
/**
@@ -81,4 +83,48 @@ public interface SystemPermissionSet extends PermissionSet<SystemPermission> {
void removePermissions(Set<SystemPermission> permissions)
throws GuacamoleException;
+ /**
+ * An immutable instance of SystemPermissionSet which contains no
+ * permissions.
+ */
+ static final SystemPermissionSet EMPTY_SET = new SystemPermissionSet() {
+
+ @Override
+ public boolean hasPermission(SystemPermission.Type permission)
+ throws GuacamoleException {
+ return false;
+ }
+
+ @Override
+ public void addPermission(SystemPermission.Type permission)
+ throws GuacamoleException {
+ throw new GuacamoleSecurityException("Permission denied.");
+ }
+
+ @Override
+ public void removePermission(SystemPermission.Type permission)
+ throws GuacamoleException {
+ throw new GuacamoleSecurityException("Permission denied.");
+ }
+
+ @Override
+ public Set<SystemPermission> getPermissions()
+ throws GuacamoleException {
+ return Collections.<SystemPermission>emptySet();
+ }
+
+ @Override
+ public void addPermissions(Set<SystemPermission> permissions)
+ throws GuacamoleException {
+ throw new GuacamoleSecurityException("Permission denied.");
+ }
+
+ @Override
+ public void removePermissions(Set<SystemPermission> permissions)
+ throws GuacamoleException {
+ throw new GuacamoleSecurityException("Permission denied.");
+ }
+
+ };
+
}
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/d533de11/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleObjectPermissionSet.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleObjectPermissionSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleObjectPermissionSet.java
index 53a30ce..1fd9ac7 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleObjectPermissionSet.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleObjectPermissionSet.java
@@ -41,7 +41,10 @@ public class SimpleObjectPermissionSet implements ObjectPermissionSet {
private Set<ObjectPermission> permissions = Collections.<ObjectPermission>emptySet();
/**
- * Creates a new empty SimpleObjectPermissionSet.
+ * Creates a new empty SimpleObjectPermissionSet. If you are not extending
+ * SimpleObjectPermissionSet and only need an immutable, empty
+ * ObjectPermissionSet, consider using {@link ObjectPermissionSet#EMPTY_SET}
+ * instead.
*/
public SimpleObjectPermissionSet() {
}
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/d533de11/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleRelatedObjectSet.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleRelatedObjectSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleRelatedObjectSet.java
index 72f2da9..e1352cd 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleRelatedObjectSet.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleRelatedObjectSet.java
@@ -37,7 +37,10 @@ public class SimpleRelatedObjectSet implements RelatedObjectSet {
private Set<String> identifiers = Collections.<String>emptySet();
/**
- * Creates a new empty SimpleObjectPermissionSet.
+ * Creates a new empty SimpleRelatedObjectSet. If you are not extending
+ * SimpleRelatedObjectSet and only need an immutable, empty
+ * RelatedObjectSet, consider using {@link RelatedObjectSet#EMPTY_SET}
+ * instead.
*/
public SimpleRelatedObjectSet() {
}
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/d533de11/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleSystemPermissionSet.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleSystemPermissionSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleSystemPermissionSet.java
index ac82c83..dd0479b 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleSystemPermissionSet.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleSystemPermissionSet.java
@@ -38,7 +38,10 @@ public class SimpleSystemPermissionSet implements SystemPermissionSet {
private Set<SystemPermission> permissions = Collections.<SystemPermission>emptySet();
/**
- * Creates a new empty SimpleSystemPermissionSet.
+ * Creates a new empty SimpleSystemPermissionSet. If you are not extending
+ * SimpleSystemPermissionSet and only need an immutable, empty
+ * SystemPermissionSet, consider using {@link SystemPermissionSet#EMPTY_SET}
+ * instead.
*/
public SimpleSystemPermissionSet() {
}
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/d533de11/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 cce8bf0..9530392 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
@@ -193,7 +193,7 @@ public class SimpleUser extends AbstractUser {
@Override
public SystemPermissionSet getSystemPermissions()
throws GuacamoleException {
- return new SimpleSystemPermissionSet();
+ return SystemPermissionSet.EMPTY_SET;
}
@Override
@@ -217,23 +217,23 @@ public class SimpleUser extends AbstractUser {
@Override
public ObjectPermissionSet getUserGroupPermissions()
throws GuacamoleException {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public ObjectPermissionSet getActiveConnectionPermissions()
throws GuacamoleException {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public ObjectPermissionSet getSharingProfilePermissions() {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public RelatedObjectSet getUserGroups() throws GuacamoleException {
- return new SimpleRelatedObjectSet();
+ return RelatedObjectSet.EMPTY_SET;
}
@Override
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/d533de11/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUserGroup.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUserGroup.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUserGroup.java
index 2223206..83b7ce9 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUserGroup.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleUserGroup.java
@@ -62,57 +62,57 @@ public class SimpleUserGroup extends AbstractIdentifiable implements UserGroup {
@Override
public SystemPermissionSet getSystemPermissions()
throws GuacamoleException {
- return new SimpleSystemPermissionSet();
+ return SystemPermissionSet.EMPTY_SET;
}
@Override
public ObjectPermissionSet getConnectionPermissions()
throws GuacamoleException {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public ObjectPermissionSet getConnectionGroupPermissions()
throws GuacamoleException {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public ObjectPermissionSet getUserPermissions()
throws GuacamoleException {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public ObjectPermissionSet getUserGroupPermissions()
throws GuacamoleException {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public ObjectPermissionSet getActiveConnectionPermissions()
throws GuacamoleException {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public ObjectPermissionSet getSharingProfilePermissions() {
- return new SimpleObjectPermissionSet();
+ return ObjectPermissionSet.EMPTY_SET;
}
@Override
public RelatedObjectSet getUserGroups() throws GuacamoleException {
- return new SimpleRelatedObjectSet();
+ return RelatedObjectSet.EMPTY_SET;
}
@Override
public RelatedObjectSet getMemberUsers() throws GuacamoleException {
- return new SimpleRelatedObjectSet();
+ return RelatedObjectSet.EMPTY_SET;
}
@Override
public RelatedObjectSet getMemberUserGroups() throws GuacamoleException {
- return new SimpleRelatedObjectSet();
+ return RelatedObjectSet.EMPTY_SET;
}
}