You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/01/30 19:32:16 UTC
[5/9] guacamole-client git commit: GUACAMOLE-96: Add convenience
class for decorating the objects returned by a Directory.
GUACAMOLE-96: Add convenience class for decorating the objects returned by a Directory.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/a915f7b1
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/a915f7b1
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/a915f7b1
Branch: refs/heads/master
Commit: a915f7b190bd6a0ce01e3e991daabed95d26493f
Parents: 7357e51
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Oct 28 22:43:31 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Jan 13 17:23:13 2018 -0800
----------------------------------------------------------------------
.../guacamole/net/auth/DecoratingDirectory.java | 133 +++++++++++++++++++
.../guacamole/net/auth/DelegatingDirectory.java | 83 ++++++++++++
2 files changed, 216 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/a915f7b1/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
new file mode 100644
index 0000000..23ea087
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DecoratingDirectory.java
@@ -0,0 +1,133 @@
+/*
+ * 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.net.auth;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import org.apache.guacamole.GuacamoleException;
+
+/**
+ * Directory implementation which simplifies decorating the objects within an
+ * underlying Directory. The decorate() and undecorate() functions must be
+ * implemented to define how each object is decorated, and how that decoration
+ * may be removed.
+ *
+ * @param <ObjectType>
+ * The type of objects stored within this Directory.
+ */
+public abstract class DecoratingDirectory<ObjectType extends Identifiable>
+ extends DelegatingDirectory<ObjectType> {
+
+ /**
+ * Creates a new DecoratingDirectory which decorates the objects within
+ * the given directory.
+ *
+ * @param directory
+ * The Directory whose objects are being decorated.
+ */
+ public DecoratingDirectory(Directory<ObjectType> directory) {
+ super(directory);
+ }
+
+ /**
+ * Given an object retrieved from a Directory which originates from a
+ * different AuthenticationProvider, returns an identical type of object
+ * optionally wrapped with additional information, functionality, etc. If
+ * this directory chooses to decorate the object provided, it is up to the
+ * implementation of that decorated object to properly pass through
+ * operations as appropriate, as well as provide for an eventual
+ * undecorate() operation. All objects retrieved from this
+ * DecoratingDirectory will first be passed through this function.
+ *
+ * @param object
+ * An object from a Directory which originates from a different
+ * AuthenticationProvider.
+ *
+ * @return
+ * An object which may have been decorated by this
+ * DecoratingDirectory. If the object was not decorated, the original,
+ * unmodified object may be returned instead.
+ *
+ * @throws GuacamoleException
+ * If the provided object cannot be decorated due to an error.
+ */
+ protected abstract ObjectType decorate(ObjectType object)
+ throws GuacamoleException;
+
+ /**
+ * Given an object originally returned from a call to this
+ * DecoratingDirectory's decorate() function, reverses the decoration
+ * operation, returning the original object. This function is effectively
+ * the exact inverse of the decorate() function. The return value of
+ * undecorate(decorate(X)) must be identically X. All objects given to this
+ * DecoratingDirectory via add() or update() will first be passed through
+ * this function.
+ *
+ * @param object
+ * An object which was originally returned by a call to this
+ * DecoratingDirectory's decorate() function.
+ *
+ * @return
+ * The original object which was provided to this DecoratingDirectory's
+ * decorate() function.
+ *
+ * @throws GuacamoleException
+ * If the provided object cannot be undecorated due to an error.
+ */
+ protected abstract ObjectType undecorate(ObjectType object)
+ throws GuacamoleException;
+
+ @Override
+ public ObjectType get(String identifier) throws GuacamoleException {
+
+ // Decorate only if object exists
+ ObjectType object = super.get(identifier);
+ if (object == null)
+ return object;
+
+ return decorate(object);
+ }
+
+ @Override
+ public Collection<ObjectType> getAll(Collection<String> identifiers)
+ throws GuacamoleException {
+
+ Collection<ObjectType> objects = super.getAll(identifiers);
+
+ // Decorate all retrieved objects, if any
+ Collection<ObjectType> decorated = new ArrayList<ObjectType>(objects.size());
+ for (ObjectType object : objects)
+ decorated.add(decorate(object));
+
+ return decorated;
+
+ }
+
+ @Override
+ public void add(ObjectType object) throws GuacamoleException {
+ super.add(undecorate(object));
+ }
+
+ @Override
+ public void update(ObjectType object) throws GuacamoleException {
+ super.update(undecorate(object));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/a915f7b1/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingDirectory.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingDirectory.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingDirectory.java
new file mode 100644
index 0000000..f1bf274
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/DelegatingDirectory.java
@@ -0,0 +1,83 @@
+/*
+ * 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.net.auth;
+
+import java.util.Collection;
+import java.util.Set;
+import org.apache.guacamole.GuacamoleException;
+
+/**
+ * Directory implementation which simply delegates all function calls to an
+ * underlying Directory.
+ *
+ * @param <ObjectType>
+ * The type of objects stored within this Directory.
+ */
+public class DelegatingDirectory<ObjectType extends Identifiable>
+ implements Directory<ObjectType> {
+
+ /**
+ * The wrapped Directory.
+ */
+ private final Directory<ObjectType> directory;
+
+ /**
+ * Wraps the given Directory such that all function calls against this
+ * DelegatingDirectory will be delegated to it.
+ *
+ * @param directory
+ * The directory to wrap.
+ */
+ public DelegatingDirectory(Directory<ObjectType> directory) {
+ this.directory = directory;
+ }
+
+ @Override
+ public ObjectType get(String identifier) throws GuacamoleException {
+ return directory.get(identifier);
+ }
+
+ @Override
+ public Collection<ObjectType> getAll(Collection<String> identifiers)
+ throws GuacamoleException {
+ return directory.getAll(identifiers);
+ }
+
+ @Override
+ public Set<String> getIdentifiers() throws GuacamoleException {
+ return directory.getIdentifiers();
+ }
+
+ @Override
+ public void add(ObjectType object) throws GuacamoleException {
+ directory.add(object);
+ }
+
+ @Override
+ public void update(ObjectType object) throws GuacamoleException {
+ directory.update(object);
+ }
+
+ @Override
+ public void remove(String identifier) throws GuacamoleException {
+ directory.remove(identifier);
+ }
+
+}