mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Remove Directory specifics, implement single, generic Directory interface.
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
package net.sourceforge.guacamole.net.auth;
|
||||
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is guacamole-ext.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Michael Jumper.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
import java.util.Set;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
|
||||
|
||||
/**
|
||||
* Provides access to a collection of all objects with associated identifiers,
|
||||
* and allows user manipulation and removal. Objects stored within a
|
||||
* Directory are not necessarily returned to the use as references to
|
||||
* the stored objects, thus updating an object requires calling an update
|
||||
* function.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public interface Directory<IdentifierType, ObjectType> {
|
||||
|
||||
/**
|
||||
* Returns the object having the given identifier. Note that changes to
|
||||
* the object returned will not necessarily affect the object stored within
|
||||
* the Directory. To update an object stored within an
|
||||
* Directory such that future calls to get() will return the updated
|
||||
* object, you must call update() on the object after modification.
|
||||
*
|
||||
* @param identifier The identifier to use when locating the object to
|
||||
* return.
|
||||
* @return The object having the given identifier, or null if no such object
|
||||
* exists.
|
||||
*
|
||||
* @throws GuacamoleException If an error occurs while retrieving the
|
||||
* object, or if permission for retrieving the
|
||||
* object is denied.
|
||||
*/
|
||||
ObjectType get(IdentifierType identifier) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns a Set containing all identifiers for all objects within this
|
||||
* Directory.
|
||||
*
|
||||
* @return A Set of all identifiers.
|
||||
* @throws GuacamoleException If an error occurs while retrieving
|
||||
* the identifiers.
|
||||
*/
|
||||
Set<IdentifierType> getIdentifiers() throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Adds the given object to the overall set.
|
||||
*
|
||||
* @param identifier The identifier to use when adding the object.
|
||||
* @param object The object to add.
|
||||
*
|
||||
* @throws GuacamoleException If an error occurs while adding the object , or
|
||||
* if adding the object is not allowed.
|
||||
*/
|
||||
void add(IdentifierType identifier, ObjectType object)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Updates the stored object with the data contained in the given object.
|
||||
* The object to update is identified using the identifier given.
|
||||
*
|
||||
* @param identifier The identifier of the object to update.
|
||||
* @param object The object which will supply the data for the update.
|
||||
*
|
||||
* @throws GuacamoleException If an error occurs while updating the object,
|
||||
* or if updating the object is not allowed.
|
||||
*/
|
||||
void update(IdentifierType identifier, ObjectType object)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Removes the object with the given identifier from the overall set.
|
||||
*
|
||||
* @param identifier The identifier of the object to remove.
|
||||
*
|
||||
* @throws GuacamoleException If an error occurs while removing the object,
|
||||
* or if removing object is not allowed.
|
||||
*/
|
||||
void remove(IdentifierType identifier) throws GuacamoleException;
|
||||
|
||||
}
|
@@ -1,117 +0,0 @@
|
||||
|
||||
package net.sourceforge.guacamole.net.auth;
|
||||
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is guacamole-ext.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Michael Jumper.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
import java.util.Map;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||
|
||||
|
||||
/**
|
||||
* Provides access to a collection of all configurations, and allows
|
||||
* configuration manipulation and removal.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public interface GuacamoleConfigurationDirectory {
|
||||
|
||||
/**
|
||||
* Returns the GuacamoleConfiguration having the given identifier.
|
||||
*
|
||||
* @param identifier The identifier of the GuacamoleConfiguration to
|
||||
* return.
|
||||
* @return The GuacamoleConfiguration having the given identifier, or null
|
||||
* if no such GuacamoleConfiguration exists.
|
||||
*
|
||||
* @throws GuacamoleException If an error occurs while retrieving the
|
||||
* configuration, or if access to the
|
||||
* configuration is denied.
|
||||
*/
|
||||
GuacamoleConfiguration getConfiguration(String identifier)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns a Map containing all GuacamoleConfigurations. The keys of this
|
||||
* Map are Strings which uniquely identify each configuration.
|
||||
*
|
||||
* @return A Map of all configurations visible.
|
||||
* @throws GuacamoleException If an error occurs while retrieving
|
||||
* configurations.
|
||||
*/
|
||||
Map<String, GuacamoleConfiguration> getConfigurations()
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Adds the given GuacamoleConfiguration to the overall set of available
|
||||
* GuacamoleConfigurations, using the given unique identifier.
|
||||
*
|
||||
* @param identifier The identifier to assign to the configuration.
|
||||
* @param config The configuration to add.
|
||||
* @throws GuacamoleException If an error occurs while adding the
|
||||
* configuration, or if adding the configuration
|
||||
* is not allowed.
|
||||
*/
|
||||
void addConfiguration(String identifier, GuacamoleConfiguration config)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Updates the GuacamoleConfiguration having the given unique identifier
|
||||
* with the data contained in the given GuacamoleConfiguration.
|
||||
*
|
||||
* @param identifier The identifier to use when locating the configuration
|
||||
* to update.
|
||||
* @param config The configuration to use when updating the stored
|
||||
* configuration.
|
||||
* @throws GuacamoleException If an error occurs while updating the
|
||||
* configuration, or if updating the
|
||||
* configuration is not allowed.
|
||||
*/
|
||||
void updateConfiguration(String identifier, GuacamoleConfiguration config)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Removes the GuacamoleConfiguration having the given unique identifier.
|
||||
*
|
||||
* @param identifier The identifier of the configuration to remove.
|
||||
* @throws GuacamoleException If an error occurs while removing the
|
||||
* configuration, or if removing the
|
||||
* configuration is not allowed.
|
||||
*/
|
||||
void removeConfiguration(String identifier) throws GuacamoleException;
|
||||
|
||||
}
|
@@ -38,6 +38,7 @@ package net.sourceforge.guacamole.net.auth;
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||
|
||||
/**
|
||||
* The context of an active user. The functions of this class enforce all
|
||||
@@ -67,7 +68,7 @@ public interface UserContext {
|
||||
* @throws GuacamoleException If an error occurs while creating the
|
||||
* UserDirectory.
|
||||
*/
|
||||
UserDirectory getUserDirectory() throws GuacamoleException;
|
||||
Directory<String, User> getUserDirectory() throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Retrieves a GuacamoleConfigurationDirectory which can be used to view
|
||||
@@ -80,7 +81,8 @@ public interface UserContext {
|
||||
* @throws GuacamoleException If an error occurs while creating the
|
||||
* GuacamoleConfigurationDirectory.
|
||||
*/
|
||||
GuacamoleConfigurationDirectory getGuacamoleConfigurationDirectory()
|
||||
Directory<String, GuacamoleConfiguration>
|
||||
getGuacamoleConfigurationDirectory()
|
||||
throws GuacamoleException;
|
||||
|
||||
}
|
||||
|
@@ -1,101 +0,0 @@
|
||||
package net.sourceforge.guacamole.net.auth;
|
||||
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is guacamole-ext.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Michael Jumper.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
import java.util.Set;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
|
||||
|
||||
/**
|
||||
* Provides access to a collection of all users, and allows user manipulation
|
||||
* and removal.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public interface UserDirectory {
|
||||
|
||||
/**
|
||||
* Returns the User having the given username.
|
||||
*
|
||||
* @param username The username of the User to return.
|
||||
* @return The User having the given username, or null if no such user
|
||||
* exists.
|
||||
*
|
||||
* @throws GuacamoleException If an error occurs while retrieving the user,
|
||||
* or if permission for retrieving the user is
|
||||
* denied.
|
||||
*/
|
||||
User getUser(String username) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns a Set containing all Users.
|
||||
*
|
||||
* @return A Set of all users.
|
||||
* @throws GuacamoleException If an error occurs while retrieving
|
||||
* users.
|
||||
*/
|
||||
Set<User> getUsers() throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Adds the given User to the overall set of available Users.
|
||||
*
|
||||
* @param user The user to add.
|
||||
* @throws GuacamoleException If an error occurs while adding the user, or
|
||||
* if adding the user is not allowed.
|
||||
*/
|
||||
void addUser(User user) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Updates the User with the data contained in the given User. The user to
|
||||
* update is identified using the username of the User given.
|
||||
*
|
||||
* @param user The user to use when updating the stored user.
|
||||
* @throws GuacamoleException If an error occurs while updating the user,
|
||||
* or if updating the user is not allowed.
|
||||
*/
|
||||
void updateUser(User user) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Removes the user with the given username from the overall set of
|
||||
* available Users.
|
||||
*
|
||||
* @throws GuacamoleException If an error occurs while removing the user,
|
||||
* or if removing user is not allowed.
|
||||
*/
|
||||
void removeUser(String username) throws GuacamoleException;
|
||||
|
||||
}
|
@@ -38,21 +38,22 @@ package net.sourceforge.guacamole.net.auth.simple;
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleSecurityException;
|
||||
import net.sourceforge.guacamole.net.auth.GuacamoleConfigurationDirectory;
|
||||
import net.sourceforge.guacamole.net.auth.Directory;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||
|
||||
|
||||
/**
|
||||
* An extremely simple read-only implementation of a
|
||||
* GuacamoleConfigurationDirectory which provides access to a pre-defined
|
||||
* Map of GuacamoleConfigurations.
|
||||
* An extremely simple read-only implementation of a Directory of
|
||||
* GuacamoleConfigurations which provides access to a pre-defined Map of
|
||||
* GuacamoleConfigurations.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class SimpleGuacamoleConfigurationDirectory
|
||||
implements GuacamoleConfigurationDirectory {
|
||||
implements Directory<String, GuacamoleConfiguration> {
|
||||
|
||||
/**
|
||||
* The Map of GuacamoleConfigurations to provide access to.
|
||||
@@ -71,32 +72,30 @@ public class SimpleGuacamoleConfigurationDirectory
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuacamoleConfiguration getConfiguration(String identifier)
|
||||
public GuacamoleConfiguration get(String identifier)
|
||||
throws GuacamoleException {
|
||||
return configs.get(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, GuacamoleConfiguration> getConfigurations()
|
||||
throws GuacamoleException {
|
||||
return configs;
|
||||
public Set<String> getIdentifiers() throws GuacamoleException {
|
||||
return configs.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConfiguration(String identifier,
|
||||
GuacamoleConfiguration config) throws GuacamoleException {
|
||||
public void add(String identifier, GuacamoleConfiguration config)
|
||||
throws GuacamoleException {
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConfiguration(String identifier,
|
||||
GuacamoleConfiguration config) throws GuacamoleException {
|
||||
public void update(String identifier, GuacamoleConfiguration config)
|
||||
throws GuacamoleException {
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeConfiguration(String identifier)
|
||||
throws GuacamoleException {
|
||||
public void remove(String identifier) throws GuacamoleException {
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
}
|
||||
|
||||
|
@@ -39,11 +39,9 @@ package net.sourceforge.guacamole.net.auth.simple;
|
||||
|
||||
import java.util.Map;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleSecurityException;
|
||||
import net.sourceforge.guacamole.net.auth.GuacamoleConfigurationDirectory;
|
||||
import net.sourceforge.guacamole.net.auth.Directory;
|
||||
import net.sourceforge.guacamole.net.auth.User;
|
||||
import net.sourceforge.guacamole.net.auth.UserContext;
|
||||
import net.sourceforge.guacamole.net.auth.UserDirectory;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||
|
||||
/**
|
||||
@@ -66,13 +64,13 @@ public class SimpleUserContext implements UserContext {
|
||||
* configurations that the User associated with this UserContext has
|
||||
* read access to.
|
||||
*/
|
||||
private final GuacamoleConfigurationDirectory configDirectory;
|
||||
private final Directory<String, GuacamoleConfiguration> configDirectory;
|
||||
|
||||
/**
|
||||
* The UserDirectory with access only to the User associated with this
|
||||
* UserContext.
|
||||
*/
|
||||
private final UserDirectory userDirectory;
|
||||
private final Directory<String, User> userDirectory;
|
||||
|
||||
/**
|
||||
* Creates a new SimpleUserContext which provides access to only those
|
||||
@@ -102,13 +100,15 @@ public class SimpleUserContext implements UserContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuacamoleConfigurationDirectory getGuacamoleConfigurationDirectory()
|
||||
public Directory<String, GuacamoleConfiguration>
|
||||
getGuacamoleConfigurationDirectory()
|
||||
throws GuacamoleException {
|
||||
return configDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDirectory getUserDirectory() throws GuacamoleException {
|
||||
public Directory<String, User> getUserDirectory()
|
||||
throws GuacamoleException {
|
||||
return userDirectory;
|
||||
}
|
||||
|
||||
|
@@ -41,17 +41,17 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleSecurityException;
|
||||
import net.sourceforge.guacamole.net.auth.Directory;
|
||||
import net.sourceforge.guacamole.net.auth.User;
|
||||
import net.sourceforge.guacamole.net.auth.UserDirectory;
|
||||
|
||||
|
||||
/**
|
||||
* An extremely simple read-only implementation of a UserDirectory which
|
||||
* An extremely simple read-only implementation of a Directory of Users which
|
||||
* provides access to a single pre-defined User.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class SimpleUserDirectory implements UserDirectory {
|
||||
public class SimpleUserDirectory implements Directory<String, User> {
|
||||
|
||||
/**
|
||||
* The only user to be contained within this directory.
|
||||
@@ -69,7 +69,7 @@ public class SimpleUserDirectory implements UserDirectory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(String username) throws GuacamoleException {
|
||||
public User get(String username) throws GuacamoleException {
|
||||
|
||||
// If username matches, return the user
|
||||
if (user.getUsername().equals(username))
|
||||
@@ -81,22 +81,22 @@ public class SimpleUserDirectory implements UserDirectory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<User> getUsers() throws GuacamoleException {
|
||||
return Collections.singleton(user);
|
||||
public Set<String> getIdentifiers() throws GuacamoleException {
|
||||
return Collections.singleton(user.getUsername());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUser(User user) throws GuacamoleException {
|
||||
public void add(String username, User user) throws GuacamoleException {
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(User user) throws GuacamoleException {
|
||||
public void update(String username, User user) throws GuacamoleException {
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUser(String username) throws GuacamoleException {
|
||||
public void remove(String username) throws GuacamoleException {
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user