From 55fb19c87be5e2aa4f6de18a201fc27e74fe76fe Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 20 Mar 2015 16:19:06 -0700 Subject: [PATCH] GUAC-1132: Extract non-database pieces of DirectoryObjectService into IdentifiableObjectService interface. --- .../jdbc/base/DirectoryObjectService.java | 105 ++---------- .../jdbc/base/IdentifiableObjectService.java | 155 ++++++++++++++++++ 2 files changed, 165 insertions(+), 95 deletions(-) create mode 100644 extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/IdentifiableObjectService.java diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/DirectoryObjectService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/DirectoryObjectService.java index abe5ce1c3..788aea4df 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/DirectoryObjectService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/DirectoryObjectService.java @@ -54,7 +54,8 @@ import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet; * database. */ public abstract class DirectoryObjectService, - ExternalType, ModelType extends ObjectModel> { + ExternalType, ModelType extends ObjectModel> + implements IdentifiableObjectService { /** * All object permissions which are implicitly granted upon creation to the @@ -289,23 +290,7 @@ public abstract class DirectoryObjectService retrieveObjects(AuthenticatedUser user, Collection identifiers) throws GuacamoleException { @@ -403,25 +373,8 @@ public abstract class DirectoryObjectService getIdentifiers(AuthenticatedUser user) throws GuacamoleException { diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/IdentifiableObjectService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/IdentifiableObjectService.java new file mode 100644 index 000000000..c76b223b1 --- /dev/null +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/IdentifiableObjectService.java @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2013 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.auth.jdbc.base; + +import java.util.Collection; +import java.util.Set; +import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser; +import org.glyptodon.guacamole.GuacamoleException; + +/** + * Service which provides convenience methods for creating, retrieving, and + * manipulating objects that have unique identifiers, such as the objects + * within directories. This service will automatically enforce the permissions + * of the current user. + * + * @author Michael Jumper + * @param + * The specific internal implementation of the type of object this service + * provides access to. + * + * @param + * The external interface or implementation of the type of object this + * service provides access to, as defined by the guacamole-ext API. + */ +public interface IdentifiableObjectService { + + /** + * Retrieves the single object that has the given identifier, if it exists + * and the user has permission to read it. + * + * @param user + * The user retrieving the object. + * + * @param identifier + * The identifier of the object to retrieve. + * + * @return + * The object having the given identifier, or null if no such object + * exists. + * + * @throws GuacamoleException + * If an error occurs while retrieving the requested object. + */ + InternalType retrieveObject(AuthenticatedUser user, String identifier) + throws GuacamoleException; + + /** + * Retrieves all objects that have the identifiers in the given collection. + * Only objects that the user has permission to read will be returned. + * + * @param user + * The user retrieving the objects. + * + * @param identifiers + * The identifiers of the objects to retrieve. + * + * @return + * The objects having the given identifiers. + * + * @throws GuacamoleException + * If an error occurs while retrieving the requested objects. + */ + Collection retrieveObjects(AuthenticatedUser user, + Collection identifiers) throws GuacamoleException; + + /** + * Creates the given object. If the object already exists, an error will be + * thrown. + * + * @param user + * The user creating the object. + * + * @param object + * The object to create. + * + * @return + * The newly-created object. + * + * @throws GuacamoleException + * If the user lacks permission to create the object, or an error + * occurs while creating the object. + */ + InternalType createObject(AuthenticatedUser user, ExternalType object) + throws GuacamoleException; + + /** + * Deletes the object having the given identifier. If no such object + * exists, this function has no effect. + * + * @param user + * The user deleting the object. + * + * @param identifier + * The identifier of the object to delete. + * + * @throws GuacamoleException + * If the user lacks permission to delete the object, or an error + * occurs while deleting the object. + */ + void deleteObject(AuthenticatedUser user, String identifier) + throws GuacamoleException; + + /** + * Updates the given object, applying any changes that have been made. If + * no such object exists, this function has no effect. + * + * @param user + * The user updating the object. + * + * @param object + * The object to update. + * + * @throws GuacamoleException + * If the user lacks permission to update the object, or an error + * occurs while updating the object. + */ + void updateObject(AuthenticatedUser user, InternalType object) + throws GuacamoleException; + + /** + * Returns the set of all identifiers for all objects that the user has + * read access to. + * + * @param user + * The user retrieving the identifiers. + * + * @return + * The set of all identifiers for all objects. + * + * @throws GuacamoleException + * If an error occurs while reading identifiers. + */ + Set getIdentifiers(AuthenticatedUser user) throws GuacamoleException; + +}