mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 09:03:21 +00:00 
			
		
		
		
	GUAC-1100: Add getAll() to Directory. Create AbstractDirectory and migrate the Simple* implementations appropriately.
This commit is contained in:
		| @@ -22,6 +22,7 @@ | ||||
|  | ||||
| package org.glyptodon.guacamole.net.auth; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.Set; | ||||
| import org.glyptodon.guacamole.GuacamoleException; | ||||
|  | ||||
| @@ -57,6 +58,29 @@ public interface Directory<IdentifierType, ObjectType> { | ||||
|      */ | ||||
|     ObjectType get(IdentifierType identifier) throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns the objects having the given identifiers. Note that changes to | ||||
|      * any object returned will not necessarily affect the object stored within | ||||
|      * the Directory. To update an object stored within a | ||||
|      * Directory such that future calls to get() will return the updated | ||||
|      * object, you must call update() on the object after modification. | ||||
|      * | ||||
|      * @param identifiers | ||||
|      *     The identifiers to use when locating the objects to return. | ||||
|      * | ||||
|      * @return | ||||
|      *     The objects having the given identifiers. If any identifiers do not | ||||
|      *     correspond to accessible objects, those identifiers will be ignored. | ||||
|      *     If no objects correspond to any of the given identifiers, the | ||||
|      *     returned collection will be empty. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving the objects, or if permission | ||||
|      *     to retrieve the requested objects is denied. | ||||
|      */ | ||||
|     Collection<ObjectType> getAll(Collection<IdentifierType> identifiers) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns a Set containing all identifiers for all objects within this | ||||
|      * Directory. | ||||
|   | ||||
| @@ -25,11 +25,7 @@ package org.glyptodon.guacamole.net.auth.simple; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.Map.Entry; | ||||
| import java.util.Set; | ||||
| import org.glyptodon.guacamole.GuacamoleException; | ||||
| import org.glyptodon.guacamole.GuacamoleSecurityException; | ||||
| import org.glyptodon.guacamole.net.auth.Connection; | ||||
| import org.glyptodon.guacamole.net.auth.Directory; | ||||
| import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; | ||||
|  | ||||
| /** | ||||
| @@ -39,13 +35,12 @@ import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SimpleConnectionDirectory | ||||
|     implements Directory<String, Connection> { | ||||
| public class SimpleConnectionDirectory extends SimpleDirectory<String, Connection> { | ||||
|  | ||||
|     /** | ||||
|      * The Map of Connections to provide access to. | ||||
|      */ | ||||
|     private Map<String, Connection> connections = | ||||
|     private final Map<String, Connection> connections = | ||||
|             new HashMap<String, Connection>(); | ||||
|  | ||||
|     /** | ||||
| @@ -60,56 +55,25 @@ public class SimpleConnectionDirectory | ||||
|         // Create connections for each config | ||||
|         for (Entry<String, GuacamoleConfiguration> entry : configs.entrySet()) | ||||
|             connections.put(entry.getKey(), | ||||
|                     new SimpleConnection(entry.getKey(), entry.getKey(),  | ||||
|                     new SimpleConnection(entry.getKey(), entry.getKey(), | ||||
|                 entry.getValue())); | ||||
|  | ||||
|         // Use the connection map to back the underlying AbstractDirectory | ||||
|         super.setObjects(connections); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Connection get(String identifier) | ||||
|             throws GuacamoleException { | ||||
|         return connections.get(identifier); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Set<String> getIdentifiers() throws GuacamoleException { | ||||
|         return connections.keySet(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void add(Connection connection) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void update(Connection connection) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void remove(String identifier) throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void move(String identifier, Directory<String, Connection> directory)  | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * An internal method for modifying the Connections in this Directory. | ||||
|      * Returns the previous connection for the given identifier, if found. | ||||
|      *  | ||||
|      * | ||||
|      * @param connection The connection to add or update the Directory with. | ||||
|      * @return The previous connection for the connection identifier, if found. | ||||
|      */ | ||||
|     public Connection putConnection(Connection connection) { | ||||
|         return connections.put(connection.getIdentifier(), connection); | ||||
|     } | ||||
|      | ||||
|  | ||||
|     /** | ||||
|      * An internal method for removing a Connection from this Directory. | ||||
|      * @param identifier The identifier of the Connection to remove. | ||||
|   | ||||
| @@ -25,11 +25,7 @@ package org.glyptodon.guacamole.net.auth.simple; | ||||
| import java.util.Collection; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.Set; | ||||
| import org.glyptodon.guacamole.GuacamoleException; | ||||
| import org.glyptodon.guacamole.GuacamoleSecurityException; | ||||
| import org.glyptodon.guacamole.net.auth.ConnectionGroup; | ||||
| import org.glyptodon.guacamole.net.auth.Directory; | ||||
|  | ||||
| /** | ||||
|  * An extremely simple read-only implementation of a Directory of | ||||
| @@ -39,18 +35,18 @@ import org.glyptodon.guacamole.net.auth.Directory; | ||||
|  * @author James Muehlner | ||||
|  */ | ||||
| public class SimpleConnectionGroupDirectory | ||||
|     implements Directory<String, ConnectionGroup> { | ||||
|     extends SimpleDirectory<String, ConnectionGroup> { | ||||
|  | ||||
|     /** | ||||
|      * The Map of ConnectionGroups to provide access to. | ||||
|      */ | ||||
|     private Map<String, ConnectionGroup> connectionGroups = | ||||
|     private final Map<String, ConnectionGroup> connectionGroups = | ||||
|             new HashMap<String, ConnectionGroup>(); | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleConnectionGroupDirectory which contains the given | ||||
|      * groups. | ||||
|      *  | ||||
|      * | ||||
|      * @param groups A Collection of all groups that should be present in this | ||||
|      *               connection group directory. | ||||
|      */ | ||||
| @@ -60,46 +56,15 @@ public class SimpleConnectionGroupDirectory | ||||
|         for (ConnectionGroup group : groups) | ||||
|             connectionGroups.put(group.getIdentifier(), group); | ||||
|  | ||||
|     } | ||||
|         // Use the connection group map to back the underlying AbstractDirectory | ||||
|         super.setObjects(connectionGroups); | ||||
|  | ||||
|     @Override | ||||
|     public ConnectionGroup get(String identifier) | ||||
|             throws GuacamoleException { | ||||
|         return connectionGroups.get(identifier); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Set<String> getIdentifiers() throws GuacamoleException { | ||||
|         return connectionGroups.keySet(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void add(ConnectionGroup connectionGroup) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void update(ConnectionGroup connectionGroup) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void remove(String identifier) throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void move(String identifier, Directory<String, ConnectionGroup> directory)  | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * An internal method for modifying the ConnectionGroups in this Directory. | ||||
|      * Returns the previous connection group for the given identifier, if found. | ||||
|      *  | ||||
|      * | ||||
|      * @param connectionGroup The connection group to add or update the | ||||
|      *                        Directory with. | ||||
|      * @return The previous connection group for the connection group | ||||
| @@ -108,10 +73,10 @@ public class SimpleConnectionGroupDirectory | ||||
|     public ConnectionGroup putConnectionGroup(ConnectionGroup connectionGroup) { | ||||
|         return connectionGroups.put(connectionGroup.getIdentifier(), connectionGroup); | ||||
|     } | ||||
|      | ||||
|  | ||||
|     /** | ||||
|      * An internal method for removing a ConnectionGroup from this Directory. | ||||
|      *  | ||||
|      * | ||||
|      * @param identifier The identifier of the ConnectionGroup to remove. | ||||
|      * @return The previous connection group for the given identifier, if found. | ||||
|      */ | ||||
|   | ||||
| @@ -0,0 +1,153 @@ | ||||
| /* | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import java.util.Map; | ||||
| import java.util.Set; | ||||
| import org.glyptodon.guacamole.GuacamoleException; | ||||
| import org.glyptodon.guacamole.GuacamoleSecurityException; | ||||
| import org.glyptodon.guacamole.net.auth.Directory; | ||||
|  | ||||
| /** | ||||
|  * An extremely simple read-only implementation of a Directory which provides | ||||
|  * access to a pre-defined Map of arbitrary objects. Any changes to the Map | ||||
|  * will affect the available contents of this SimpleDirectory. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  * @param <IdentifierType> | ||||
|  *     The type of identifier used to identify objects stored within this | ||||
|  *     SimpleDirectory. | ||||
|  * | ||||
|  * @param <ObjectType> | ||||
|  *     The type of objects stored within this SimpleDirectory. | ||||
|  */ | ||||
| public class SimpleDirectory<IdentifierType, ObjectType> | ||||
|     implements Directory<IdentifierType, ObjectType> { | ||||
|  | ||||
|     /** | ||||
|      * The Map of objects to provide access to. | ||||
|      */ | ||||
|     private Map<IdentifierType, ObjectType> objects = Collections.EMPTY_MAP; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new empty SimpleDirectory which does not provide access to | ||||
|      * any objects. | ||||
|      */ | ||||
|     public SimpleDirectory() { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleDirectory which provides access to the objects | ||||
|      * contained within the given Map. | ||||
|      * | ||||
|      * @param objects | ||||
|      *     The Map of objects to provide access to. | ||||
|      */ | ||||
|     public SimpleDirectory(Map<IdentifierType, ObjectType> objects) { | ||||
|         this.objects = objects; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the Map which backs this SimpleDirectory. Future function calls | ||||
|      * which retrieve objects from this SimpleDirectory will use the provided | ||||
|      * Map. | ||||
|      * | ||||
|      * @param objects | ||||
|      *     The Map of objects to provide access to. | ||||
|      */ | ||||
|     protected void setObjects(Map<IdentifierType, ObjectType> objects) { | ||||
|         this.objects = objects; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the Map which currently backs this SimpleDirectory. Changes to | ||||
|      * this Map will affect future function calls that retrieve objects from | ||||
|      * this SimpleDirectory. | ||||
|      * | ||||
|      * @return | ||||
|      *     The Map of objects which currently backs this SimpleDirectory. | ||||
|      */ | ||||
|     protected Map<IdentifierType, ObjectType> getObjects() { | ||||
|         return objects; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ObjectType get(IdentifierType identifier) | ||||
|             throws GuacamoleException { | ||||
|         return objects.get(identifier); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<ObjectType> getAll(Collection<IdentifierType> identifiers) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         // Create collection which has an appropriate initial size | ||||
|         Collection<ObjectType> foundObjects = new ArrayList<ObjectType>(identifiers.size()); | ||||
|  | ||||
|         // Populate collection with matching objects | ||||
|         for (IdentifierType identifier : identifiers) { | ||||
|  | ||||
|             // Add the object which has the current identifier, if any | ||||
|             ObjectType object = objects.get(identifier); | ||||
|             if (object != null) | ||||
|                 foundObjects.add(object); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         return foundObjects; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Set<IdentifierType> getIdentifiers() throws GuacamoleException { | ||||
|         return objects.keySet(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void add(ObjectType connection) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void update(ObjectType connection) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void remove(IdentifierType identifier) throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void move(IdentifierType identifier, | ||||
|             Directory<IdentifierType, ObjectType> directory) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -23,10 +23,6 @@ | ||||
| package org.glyptodon.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.Collections; | ||||
| import java.util.Set; | ||||
| import org.glyptodon.guacamole.GuacamoleException; | ||||
| import org.glyptodon.guacamole.GuacamoleSecurityException; | ||||
| import org.glyptodon.guacamole.net.auth.Directory; | ||||
| import org.glyptodon.guacamole.net.auth.User; | ||||
|  | ||||
| /** | ||||
| @@ -35,12 +31,7 @@ import org.glyptodon.guacamole.net.auth.User; | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SimpleUserDirectory implements Directory<String, User> { | ||||
|  | ||||
|     /** | ||||
|      * The only user to be contained within this directory. | ||||
|      */ | ||||
|     private User user; | ||||
| public class SimpleUserDirectory extends SimpleDirectory<String, User> { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleUserDirectory which provides access to the single | ||||
| @@ -49,45 +40,7 @@ public class SimpleUserDirectory implements Directory<String, User> { | ||||
|      * @param user The user to provide access to. | ||||
|      */ | ||||
|     public SimpleUserDirectory(User user) { | ||||
|         this.user = user; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public User get(String username) throws GuacamoleException { | ||||
|  | ||||
|         // If username matches, return the user | ||||
|         if (user.getUsername().equals(username)) | ||||
|             return user; | ||||
|  | ||||
|         // Otherwise, not found | ||||
|         return null; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Set<String> getIdentifiers() throws GuacamoleException { | ||||
|         return Collections.singleton(user.getUsername()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void add(User user) throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void update(User user) throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void remove(String username) throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void move(String identifier, Directory<String, User> directory)  | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|         super(Collections.singletonMap(user.getUsername(), user)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user