mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 17:13:21 +00:00 
			
		
		
		
	GUACAMOLE-220: Add EMPTY_SET convenience constant to all core set interfaces.
This commit is contained in:
		| @@ -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."); | ||||
|         } | ||||
|  | ||||
|     }; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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."); | ||||
|         } | ||||
|  | ||||
|     }; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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."); | ||||
|         } | ||||
|  | ||||
|     }; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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() { | ||||
|     } | ||||
|   | ||||
| @@ -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() { | ||||
|     } | ||||
|   | ||||
| @@ -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() { | ||||
|     } | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user