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 2016/07/17 22:28:44 UTC

[16/19] incubator-guacamole-client git commit: GUACAMOLE-5: Add DirectoryView object, providing a Directory interface around a restricted subset of objects within another existing Directory.

GUACAMOLE-5: Add DirectoryView object, providing a Directory interface around a restricted subset of objects within another existing Directory.

Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/bb36045f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/bb36045f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/bb36045f

Branch: refs/heads/master
Commit: bb36045ff8df506d890311aefacdd6a395434a98
Parents: 62dcd9e
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Jul 16 00:31:23 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jul 16 11:42:48 2016 -0700

----------------------------------------------------------------------
 .../guacamole/rest/directory/DirectoryView.java | 120 +++++++++++++++++++
 1 file changed, 120 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/bb36045f/guacamole/src/main/java/org/apache/guacamole/rest/directory/DirectoryView.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/directory/DirectoryView.java b/guacamole/src/main/java/org/apache/guacamole/rest/directory/DirectoryView.java
new file mode 100644
index 0000000..aee18f3
--- /dev/null
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/directory/DirectoryView.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.rest.directory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Set;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleUnsupportedException;
+import org.apache.guacamole.net.auth.Directory;
+import org.apache.guacamole.net.auth.Identifiable;
+
+/**
+ * Directory implementation which represents a read-only subset of another
+ * existing Directory. Access is provided only to a limited set of objects,
+ * determined by the set of identifiers provided when the DirectoryView is
+ * created.
+ *
+ * @author Michael Jumper
+ * @param <ObjectType>
+ *     The type of objects accessible through this DirectoryView.
+ */
+public class DirectoryView<ObjectType extends Identifiable>
+        implements Directory<ObjectType> {
+
+    /**
+     * The Directory from which the given set of objects will be retrieved.
+     */
+    private final Directory<ObjectType> directory;
+
+    /**
+     * The set of identifiers representing the restricted set of objects that
+     * this DirectoryView should provide access to.
+     */
+    private final Set<String> identifiers;
+
+    /**
+     * Creates a new DirectoryView which provides access to a read-only subset
+     * of the objects in the given Directory. Only objects whose identifiers
+     * are within the provided set will be accessible.
+     *
+     * @param directory
+     *     The Directory of which this DirectoryView represents a subset.
+     *
+     * @param identifiers
+     *     The identifiers of all objects which should be accessible through
+     *     this DirectoryView. Objects which do not have identifiers within
+     *     the provided set will be inaccessible.
+     */
+    public DirectoryView(Directory<ObjectType> directory,
+            Set<String> identifiers) {
+        this.directory = directory;
+        this.identifiers = identifiers;
+    }
+
+    @Override
+    public ObjectType get(String identifier) throws GuacamoleException {
+
+        // Attempt to retrieve the requested object ONLY if it's within the
+        // originally-specified subset
+        if (!identifiers.contains(identifier))
+            return null;
+
+        // Delegate to underlying directory
+        return directory.get(identifier);
+
+    }
+
+    @Override
+    public Collection<ObjectType> getAll(Collection<String> identifiers)
+            throws GuacamoleException {
+
+        // Reduce requested identifiers to only those which occur within the
+        // originally-specified subset
+        identifiers = new ArrayList<String>(identifiers);
+        identifiers.retainAll(this.identifiers);
+
+        // Delegate to underlying directory
+        return directory.getAll(identifiers);
+
+    }
+
+    @Override
+    public Set<String> getIdentifiers() throws GuacamoleException {
+        return identifiers;
+    }
+
+    @Override
+    public void add(ObjectType object) throws GuacamoleException {
+        throw new GuacamoleUnsupportedException("Directory view is read-only");
+    }
+
+    @Override
+    public void update(ObjectType object) throws GuacamoleException {
+        throw new GuacamoleUnsupportedException("Directory view is read-only");
+    }
+
+    @Override
+    public void remove(String identifier) throws GuacamoleException {
+        throw new GuacamoleUnsupportedException("Directory view is read-only");
+    }
+
+}