From 7a20a33e95f8232fec63f8246193969444b91aec Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 23 May 2015 21:04:18 -0700 Subject: [PATCH 1/8] GUAC-800: Define ObjectAttribute and associated interfaces. --- .../net/auth/attribute/Attribute.java | 122 ++++++++++++++ .../net/auth/attribute/AttributeSet.java | 69 ++++++++ .../net/auth/attribute/ObjectAttribute.java | 152 ++++++++++++++++++ .../auth/attribute/ObjectAttributeSet.java | 31 ++++ .../net/auth/attribute/package-info.java | 27 ++++ 5 files changed, 401 insertions(+) create mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java create mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/AttributeSet.java create mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttribute.java create mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttributeSet.java create mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/package-info.java diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java new file mode 100644 index 000000000..446eb0c4e --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java @@ -0,0 +1,122 @@ +/* + * 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.attribute; + +import org.glyptodon.guacamole.net.auth.Identifiable; + +/** + * An arbitrary attribute. Each attribute associates an identifier with a + * value, essentially a key/value pair, where the type dictates the semantics + * and legal values of the attribute. + * + * @author Michael Jumper + */ +public interface Attribute extends Identifiable { + + /** + * Specific types of attributes. Each attribute type describes the kind of + * values the attribute can accept, and defines any semantics associated + * with those values. + */ + public enum Type { + + /** + * A text attribute, accepting arbitrary values. + */ + TEXT, + + /** + * A username attribute. This attribute type generally behaves + * identically to arbitrary text attributes, but has semantic + * differences. + */ + USERNAME, + + /** + * A password attribute, whose value is sensitive and must be hidden. + */ + PASSWORD, + + /** + * A numeric attribute, whose value must contain only digits. + */ + NUMERIC, + + /** + * A boolean attribute, whose value is either blank or "true". + */ + BOOLEAN, + + /** + * An enumerated attribute, whose legal values are fully enumerated + * by a provided, finite list. + */ + ENUM, + + /** + * A text attribute that can span more than one line. + */ + MULTILINE + + } + + /** + * Returns the type of this attribute. The attribute type dictates the kind + * of values the attribute can contain, and the semantics of the attribute + * as a whole. + * + * @return + * The type of this attribute. + */ + Type getType(); + + /** + * Sets the type of this attribute. Attribute type dictates the kind of + * values the attribute can contain, and the semantics of the attribute as + * a whole. + * + * @param type + * The type to associate with this attribute. + */ + void setType(Type type); + + /** + * Returns the value currently associated with this attribute, if any. The + * values acceptable by this attribute are dictated by the type. + * + * @return + * The value currently associated with this attribute, or null if no + * value is present. + */ + String getValue(); + + /** + * Sets the value currently associated with this attribute, if any. The + * values acceptable by this attribute are dictated by the type. + * + * @param value + * The value to associate with this attribute. + */ + void setValue(String value); + +} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/AttributeSet.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/AttributeSet.java new file mode 100644 index 000000000..8b02b2cd8 --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/AttributeSet.java @@ -0,0 +1,69 @@ +/* + * 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.attribute; + +import java.util.Set; +import org.glyptodon.guacamole.GuacamoleException; + +/** + * An arbitrary set of attributes. + * + * @author Michael Jumper + * @param + * The type of attribute stored within this AttributeSet. + */ +public interface AttributeSet { + + /** + * Returns a Set which contains all attributes stored or storable within + * this attribute set. The value of each attribute, if any, is associated + * with the attribute object within the set. The set itself may not be + * mutable. + * + * @return + * A Set containing all attributes stored or storable within this + * attribute set, which may not be mutable. + * + * @throws GuacamoleException + * If an error occurs while retrieving the attributes, or if attributes + * cannot be retrieved due to lack of permissions to do so. + */ + Set getAttributes() throws GuacamoleException; + + /** + * Changes each of the given attributes. If a specified attribute is + * already set, the previous value will be overwritten with the new value. + * If the new value is null, the previous value will be unset. + * + * @param attributes + * The attributes to update. + * + * @throws GuacamoleException + * If an error occurs while updating the attributes, if permission to + * update attributes is denied, or if any one of the given attributes + * is invalid or malformed. + */ + void updateAttributes(Set attributes) + throws GuacamoleException; + +} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttribute.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttribute.java new file mode 100644 index 000000000..820f9da90 --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttribute.java @@ -0,0 +1,152 @@ +/* + * 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.attribute; + +/** + * An attribute which applies to a specific object. + * + * @author Michael Jumper + */ +public class ObjectAttribute implements Attribute { + + /** + * The identifier of the object associated with the attribute. + */ + private String objectIdentifier; + + /** + * The type of value stored within this attribute. + */ + private Type type; + + /** + * A string which uniquely identifies this attribute. + */ + private String identifier; + + /** + * The value currently assigned to this attribute. + */ + private String value; + + /** + * Creates a new ObjectAttribute having the given identifier and type. + * The identifier must be unique with respect to other attributes that + * apply to the same kind of object. + * + * @param identifier + * The string which uniquely identifies this attribute. + * + * @param type + * The type of value stored within this attribute. + */ + public ObjectAttribute(String identifier, Type type) { + this.identifier = identifier; + this.type = type; + } + + /** + * Returns the identifier of the specific object associated with this + * attribute. + * + * @return + * The identifier of the specific object associated with this + * attribute. + */ + public String getObjectIdentifier() { + return objectIdentifier; + } + + /** + * Sets the identifier of the specific object associated with this + * attribute. + * + * @param objectIdentifier + * The identifier of the specific object associated with this + * attribute. + */ + public void setObjectIdentifier(String objectIdentifier) { + this.objectIdentifier = objectIdentifier; + } + + @Override + public Type getType() { + return type; + } + + @Override + public void setType(Type type) { + this.type = type; + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } + + @Override + public int hashCode() { + + // The identifier always uniquely identifies an attribute + if (identifier != null) + return identifier.hashCode(); + + return 0; + + } + + @Override + public boolean equals(Object obj) { + + // Not equal if null or wrong type + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + + final ObjectAttribute other = (ObjectAttribute) obj; + + // If null identifier, equality depends on whether other identifier + // is null + if (identifier == null) + return other.identifier == null; + + // Otherwise, equality depends entirely on identifier + return identifier.equals(other.identifier); + + } + +} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttributeSet.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttributeSet.java new file mode 100644 index 000000000..57def7004 --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttributeSet.java @@ -0,0 +1,31 @@ +/* + * 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.attribute; + +/** + * A set of attributes associated with a particular object or group of objects. + * + * @author Michael Jumper + */ +public interface ObjectAttributeSet extends AttributeSet { +} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/package-info.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/package-info.java new file mode 100644 index 000000000..e653cf71a --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/package-info.java @@ -0,0 +1,27 @@ +/* + * 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. + */ + +/** + * Provides classes which describe the various attributes that can be + * associated with Guacamole objects, such as a user or a connection. + */ +package org.glyptodon.guacamole.net.auth.attribute; From 75f6e75176109936d399375cc8b4b611a957b626 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 23 May 2015 21:29:42 -0700 Subject: [PATCH 2/8] GUAC-800: Associate attributes with users and connections. --- .../guacamole/net/auth/Connection.java | 14 +++ .../glyptodon/guacamole/net/auth/User.java | 13 +++ .../net/auth/simple/SimpleConnection.java | 6 ++ .../auth/simple/SimpleObjectAttributeSet.java | 85 +++++++++++++++++++ .../guacamole/net/auth/simple/SimpleUser.java | 6 ++ 5 files changed, 124 insertions(+) create mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectAttributeSet.java diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connection.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connection.java index 6fac0809f..ecd30dcce 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connection.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connection.java @@ -24,6 +24,7 @@ package org.glyptodon.guacamole.net.auth; import java.util.List; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; /** @@ -100,4 +101,17 @@ public interface Connection extends Identifiable, Connectable { */ public List getHistory() throws GuacamoleException; + /** + * Returns all attributes associated with this connection. + * + * @return + * An ObjectAttributeSet of all attributes associated with this + * connection + * + * @throws GuacamoleException + * If an error occurs while retrieving the attributes, or if reading + * attributes is not allowed. + */ + ObjectAttributeSet getAttributes() throws GuacamoleException; + } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/User.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/User.java index 267ad1f0f..99773501f 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/User.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/User.java @@ -23,6 +23,7 @@ package org.glyptodon.guacamole.net.auth; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet; import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet; import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet; @@ -119,4 +120,16 @@ public interface User extends Identifiable { */ ObjectPermissionSet getUserPermissions() throws GuacamoleException; + /** + * Returns all attributes associated with this user. + * + * @return + * An ObjectAttributeSet of all attributes associated with this user. + * + * @throws GuacamoleException + * If an error occurs while retrieving the attributes, or if reading + * attributes is not allowed. + */ + ObjectAttributeSet getAttributes() throws GuacamoleException; + } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java index e5f2f0d1e..a7f98ec79 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java @@ -34,6 +34,7 @@ import org.glyptodon.guacamole.net.SSLGuacamoleSocket; import org.glyptodon.guacamole.net.SimpleGuacamoleTunnel; import org.glyptodon.guacamole.net.auth.AbstractConnection; import org.glyptodon.guacamole.net.auth.ConnectionRecord; +import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet; import org.glyptodon.guacamole.protocol.ConfiguredGuacamoleSocket; import org.glyptodon.guacamole.protocol.GuacamoleClientInformation; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; @@ -132,4 +133,9 @@ public class SimpleConnection extends AbstractConnection { return Collections.emptyList(); } + @Override + public ObjectAttributeSet getAttributes() throws GuacamoleException { + return new SimpleObjectAttributeSet(); + } + } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectAttributeSet.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectAttributeSet.java new file mode 100644 index 000000000..0bf395d2b --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectAttributeSet.java @@ -0,0 +1,85 @@ +/* + * 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.Collections; +import java.util.Set; +import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.GuacamoleSecurityException; +import org.glyptodon.guacamole.net.auth.attribute.ObjectAttribute; +import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet; + +/** + * A read-only implementation of ObjectAttributeSet which uses a backing Set + * of Attribute for attribute/value storage. + * + * @author Michael Jumper + */ +public class SimpleObjectAttributeSet implements ObjectAttributeSet { + + /** + * The set of all attributes currently set. + */ + private Set attributes = Collections.emptySet(); + + /** + * Creates a new empty SimpleObjectAttributeSet. + */ + public SimpleObjectAttributeSet() { + } + + /** + * Creates a new SimpleObjectAttributeSet which contains the attributes + * within the given Set. + * + * @param attributes + * The Set of attributes this SimpleObjectAttributeSet should + * contain. + */ + public SimpleObjectAttributeSet(Set attributes) { + this.attributes = attributes; + } + + /** + * Sets the Set which backs this SimpleObjectAttributeSet. Future function + * calls on this SimpleObjectAttributeSet will use the provided Set. + * + * @param attributes + * The Set of attributes this SimpleObjectAttributeSet should + * contain. + */ + protected void setAttributes(Set attributes) { + this.attributes = attributes; + } + + @Override + public Set getAttributes() throws GuacamoleException { + return attributes; + } + + @Override + public void updateAttributes(Set attributes) throws GuacamoleException { + throw new GuacamoleSecurityException("Permission denied."); + } + +} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUser.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUser.java index a9da2e939..7b9a04653 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUser.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUser.java @@ -27,6 +27,7 @@ import java.util.HashSet; import java.util.Set; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.net.auth.AbstractUser; +import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet; import org.glyptodon.guacamole.net.auth.permission.ObjectPermission; import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet; import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet; @@ -136,4 +137,9 @@ public class SimpleUser extends AbstractUser { return new SimpleObjectPermissionSet(); } + @Override + public ObjectAttributeSet getAttributes() throws GuacamoleException { + return new SimpleObjectAttributeSet(); + } + } From 9585d0fc6ca62cd2a1d6242c173258e7cd66e87e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 24 May 2015 15:01:15 -0700 Subject: [PATCH 3/8] GUAC-800: Handle attributes as dynamic properties (no GuacamoleExceptions). Use Attribute for schema information only. Allow retrieval of schema information from UserContext. Add attributes to ConnectionGroup. --- .../guacamole/net/auth/Connection.java | 34 ++-- .../guacamole/net/auth/ConnectionGroup.java | 22 ++- .../glyptodon/guacamole/net/auth/User.java | 33 ++-- .../guacamole/net/auth/UserContext.java | 35 ++++ .../net/auth/attribute/Attribute.java | 53 +++--- .../net/auth/attribute/AttributeSet.java | 69 -------- .../net/auth/attribute/ObjectAttribute.java | 152 ------------------ .../auth/attribute/ObjectAttributeSet.java | 31 ---- .../net/auth/simple/SimpleConnection.java | 17 +- .../auth/simple/SimpleConnectionGroup.java | 12 ++ .../auth/simple/SimpleObjectAttributeSet.java | 85 ---------- .../guacamole/net/auth/simple/SimpleUser.java | 19 ++- .../net/auth/simple/SimpleUserContext.java | 16 ++ 13 files changed, 177 insertions(+), 401 deletions(-) delete mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/AttributeSet.java delete mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttribute.java delete mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttributeSet.java delete mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectAttributeSet.java diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connection.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connection.java index ecd30dcce..6ab34dab4 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connection.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connection.java @@ -23,8 +23,8 @@ package org.glyptodon.guacamole.net.auth; import java.util.List; +import java.util.Map; import org.glyptodon.guacamole.GuacamoleException; -import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; /** @@ -85,6 +85,25 @@ public interface Connection extends Identifiable, Connectable { */ public void setConfiguration(GuacamoleConfiguration config); + /** + * Returns all attributes associated with this connection. + * + * @return + * A map of all attribute identifiers to their corresponding values, + * for all attributes associated with this connection. + */ + Map getAttributes(); + + /** + * Replaces all attributes associated with this connection with the + * attributes in the given map. + * + * @param attributes + * A map of all attribute identifiers to their corresponding values, + * for all attributes associated with this connection. + */ + void setAttributes(Map attributes); + /** * Returns a list of ConnectionRecords representing the usage history * of this Connection, including any active users. ConnectionRecords @@ -101,17 +120,4 @@ public interface Connection extends Identifiable, Connectable { */ public List getHistory() throws GuacamoleException; - /** - * Returns all attributes associated with this connection. - * - * @return - * An ObjectAttributeSet of all attributes associated with this - * connection - * - * @throws GuacamoleException - * If an error occurs while retrieving the attributes, or if reading - * attributes is not allowed. - */ - ObjectAttributeSet getAttributes() throws GuacamoleException; - } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/ConnectionGroup.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/ConnectionGroup.java index 97c66ad02..25eb11797 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/ConnectionGroup.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/ConnectionGroup.java @@ -22,6 +22,7 @@ package org.glyptodon.guacamole.net.auth; +import java.util.Map; import java.util.Set; import org.glyptodon.guacamole.GuacamoleException; @@ -127,5 +128,24 @@ public interface ConnectionGroup extends Identifiable, Connectable { public Set getConnectionGroupIdentifiers() throws GuacamoleException; - + + /** + * Returns all attributes associated with this connection group. + * + * @return + * A map of all attribute identifiers to their corresponding values, + * for all attributes associated with this connection group. + */ + Map getAttributes(); + + /** + * Replaces all attributes associated with this connection group with the + * attributes in the given map. + * + * @param attributes + * A map of all attribute identifiers to their corresponding values, + * for all attributes associated with this connection group. + */ + void setAttributes(Map attributes); + } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/User.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/User.java index 99773501f..b2f13ea23 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/User.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/User.java @@ -22,8 +22,8 @@ package org.glyptodon.guacamole.net.auth; +import java.util.Map; import org.glyptodon.guacamole.GuacamoleException; -import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet; import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet; import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet; @@ -52,6 +52,25 @@ public interface User extends Identifiable { */ public void setPassword(String password); + /** + * Returns all attributes associated with this user. + * + * @return + * A map of all attribute identifiers to their corresponding values, + * for all attributes associated with this user. + */ + Map getAttributes(); + + /** + * Replaces all attributes associated with this user with the attributes in + * the given map. + * + * @param attributes + * A map of all attribute identifiers to their corresponding values, + * for all attributes associated with this user. + */ + void setAttributes(Map attributes); + /** * Returns all system-level permissions given to this user. * @@ -120,16 +139,4 @@ public interface User extends Identifiable { */ ObjectPermissionSet getUserPermissions() throws GuacamoleException; - /** - * Returns all attributes associated with this user. - * - * @return - * An ObjectAttributeSet of all attributes associated with this user. - * - * @throws GuacamoleException - * If an error occurs while retrieving the attributes, or if reading - * attributes is not allowed. - */ - ObjectAttributeSet getAttributes() throws GuacamoleException; - } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java index 38538bce1..0d782e9dc 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java @@ -22,7 +22,9 @@ package org.glyptodon.guacamole.net.auth; +import java.util.Collection; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.net.auth.attribute.Attribute; /** * The context of an active user. The functions of this class enforce all @@ -110,4 +112,37 @@ public interface UserContext { */ ConnectionGroup getRootConnectionGroup() throws GuacamoleException; + /** + * Retrieves a collection of all attributes applicable to users. This + * collection will contain only those attributes which the current user has + * general permission to view or modify. If there are no such attributes, + * this collection will be empty. + * + * @return + * A collection of all attributes applicable to users. + */ + Collection getUserAttributes(); + + /** + * Retrieves a collection of all attributes applicable to connections. This + * collection will contain only those attributes which the current user has + * general permission to view or modify. If there are no such attributes, + * this collection will be empty. + * + * @return + * A collection of all attributes applicable to connections. + */ + Collection getConnectionAttributes(); + + /** + * Retrieves a collection of all attributes applicable to connection + * groups. This collection will contain only those attributes which the + * current user has general permission to view or modify. If there are no + * such attributes, this collection will be empty. + * + * @return + * A collection of all attributes applicable to connection groups. + */ + Collection getConnectionGroupAttributes(); + } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java index 446eb0c4e..38e75b538 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java @@ -26,12 +26,22 @@ import org.glyptodon.guacamole.net.auth.Identifiable; /** * An arbitrary attribute. Each attribute associates an identifier with a - * value, essentially a key/value pair, where the type dictates the semantics - * and legal values of the attribute. + * type, where the type dictates the semantics and legal values of the + * attribute. * * @author Michael Jumper */ -public interface Attribute extends Identifiable { +public class Attribute implements Identifiable { + + /** + * The string which uniquely identifies this attribute. + */ + private String identifier; + + /** + * The type of this attribute. + */ + private Type type; /** * Specific types of attributes. Each attribute type describes the kind of @@ -80,6 +90,16 @@ public interface Attribute extends Identifiable { } + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + /** * Returns the type of this attribute. The attribute type dictates the kind * of values the attribute can contain, and the semantics of the attribute @@ -88,7 +108,9 @@ public interface Attribute extends Identifiable { * @return * The type of this attribute. */ - Type getType(); + public Type getType() { + return type; + } /** * Sets the type of this attribute. Attribute type dictates the kind of @@ -98,25 +120,8 @@ public interface Attribute extends Identifiable { * @param type * The type to associate with this attribute. */ - void setType(Type type); - - /** - * Returns the value currently associated with this attribute, if any. The - * values acceptable by this attribute are dictated by the type. - * - * @return - * The value currently associated with this attribute, or null if no - * value is present. - */ - String getValue(); - - /** - * Sets the value currently associated with this attribute, if any. The - * values acceptable by this attribute are dictated by the type. - * - * @param value - * The value to associate with this attribute. - */ - void setValue(String value); + void setType(Type type) { + this.type = type; + } } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/AttributeSet.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/AttributeSet.java deleted file mode 100644 index 8b02b2cd8..000000000 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/AttributeSet.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.attribute; - -import java.util.Set; -import org.glyptodon.guacamole.GuacamoleException; - -/** - * An arbitrary set of attributes. - * - * @author Michael Jumper - * @param - * The type of attribute stored within this AttributeSet. - */ -public interface AttributeSet { - - /** - * Returns a Set which contains all attributes stored or storable within - * this attribute set. The value of each attribute, if any, is associated - * with the attribute object within the set. The set itself may not be - * mutable. - * - * @return - * A Set containing all attributes stored or storable within this - * attribute set, which may not be mutable. - * - * @throws GuacamoleException - * If an error occurs while retrieving the attributes, or if attributes - * cannot be retrieved due to lack of permissions to do so. - */ - Set getAttributes() throws GuacamoleException; - - /** - * Changes each of the given attributes. If a specified attribute is - * already set, the previous value will be overwritten with the new value. - * If the new value is null, the previous value will be unset. - * - * @param attributes - * The attributes to update. - * - * @throws GuacamoleException - * If an error occurs while updating the attributes, if permission to - * update attributes is denied, or if any one of the given attributes - * is invalid or malformed. - */ - void updateAttributes(Set attributes) - throws GuacamoleException; - -} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttribute.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttribute.java deleted file mode 100644 index 820f9da90..000000000 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttribute.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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.attribute; - -/** - * An attribute which applies to a specific object. - * - * @author Michael Jumper - */ -public class ObjectAttribute implements Attribute { - - /** - * The identifier of the object associated with the attribute. - */ - private String objectIdentifier; - - /** - * The type of value stored within this attribute. - */ - private Type type; - - /** - * A string which uniquely identifies this attribute. - */ - private String identifier; - - /** - * The value currently assigned to this attribute. - */ - private String value; - - /** - * Creates a new ObjectAttribute having the given identifier and type. - * The identifier must be unique with respect to other attributes that - * apply to the same kind of object. - * - * @param identifier - * The string which uniquely identifies this attribute. - * - * @param type - * The type of value stored within this attribute. - */ - public ObjectAttribute(String identifier, Type type) { - this.identifier = identifier; - this.type = type; - } - - /** - * Returns the identifier of the specific object associated with this - * attribute. - * - * @return - * The identifier of the specific object associated with this - * attribute. - */ - public String getObjectIdentifier() { - return objectIdentifier; - } - - /** - * Sets the identifier of the specific object associated with this - * attribute. - * - * @param objectIdentifier - * The identifier of the specific object associated with this - * attribute. - */ - public void setObjectIdentifier(String objectIdentifier) { - this.objectIdentifier = objectIdentifier; - } - - @Override - public Type getType() { - return type; - } - - @Override - public void setType(Type type) { - this.type = type; - } - - @Override - public String getIdentifier() { - return identifier; - } - - @Override - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - @Override - public String getValue() { - return value; - } - - @Override - public void setValue(String value) { - this.value = value; - } - - @Override - public int hashCode() { - - // The identifier always uniquely identifies an attribute - if (identifier != null) - return identifier.hashCode(); - - return 0; - - } - - @Override - public boolean equals(Object obj) { - - // Not equal if null or wrong type - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - - final ObjectAttribute other = (ObjectAttribute) obj; - - // If null identifier, equality depends on whether other identifier - // is null - if (identifier == null) - return other.identifier == null; - - // Otherwise, equality depends entirely on identifier - return identifier.equals(other.identifier); - - } - -} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttributeSet.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttributeSet.java deleted file mode 100644 index 57def7004..000000000 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/ObjectAttributeSet.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.attribute; - -/** - * A set of attributes associated with a particular object or group of objects. - * - * @author Michael Jumper - */ -public interface ObjectAttributeSet extends AttributeSet { -} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java index a7f98ec79..f59d205b0 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java @@ -24,6 +24,7 @@ package org.glyptodon.guacamole.net.auth.simple; import java.util.Collections; import java.util.List; +import java.util.Map; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.environment.LocalEnvironment; @@ -34,7 +35,6 @@ import org.glyptodon.guacamole.net.SSLGuacamoleSocket; import org.glyptodon.guacamole.net.SimpleGuacamoleTunnel; import org.glyptodon.guacamole.net.auth.AbstractConnection; import org.glyptodon.guacamole.net.auth.ConnectionRecord; -import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet; import org.glyptodon.guacamole.protocol.ConfiguredGuacamoleSocket; import org.glyptodon.guacamole.protocol.GuacamoleClientInformation; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; @@ -98,6 +98,16 @@ public class SimpleConnection extends AbstractConnection { return 0; } + @Override + public Map getAttributes() { + return Collections.emptyMap(); + } + + @Override + public void setAttributes(Map attributes) { + // Do nothing - there are no attributes + } + @Override public GuacamoleTunnel connect(GuacamoleClientInformation info) throws GuacamoleException { @@ -133,9 +143,4 @@ public class SimpleConnection extends AbstractConnection { return Collections.emptyList(); } - @Override - public ObjectAttributeSet getAttributes() throws GuacamoleException { - return new SimpleObjectAttributeSet(); - } - } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionGroup.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionGroup.java index a302f4676..179a86b64 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionGroup.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionGroup.java @@ -23,7 +23,9 @@ package org.glyptodon.guacamole.net.auth.simple; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleSecurityException; @@ -101,6 +103,16 @@ public class SimpleConnectionGroup extends AbstractConnectionGroup { return connectionGroupIdentifiers; } + @Override + public Map getAttributes() { + return Collections.emptyMap(); + } + + @Override + public void setAttributes(Map attributes) { + // Do nothing - there are no attributes + } + @Override public GuacamoleTunnel connect(GuacamoleClientInformation info) throws GuacamoleException { diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectAttributeSet.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectAttributeSet.java deleted file mode 100644 index 0bf395d2b..000000000 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectAttributeSet.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.Collections; -import java.util.Set; -import org.glyptodon.guacamole.GuacamoleException; -import org.glyptodon.guacamole.GuacamoleSecurityException; -import org.glyptodon.guacamole.net.auth.attribute.ObjectAttribute; -import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet; - -/** - * A read-only implementation of ObjectAttributeSet which uses a backing Set - * of Attribute for attribute/value storage. - * - * @author Michael Jumper - */ -public class SimpleObjectAttributeSet implements ObjectAttributeSet { - - /** - * The set of all attributes currently set. - */ - private Set attributes = Collections.emptySet(); - - /** - * Creates a new empty SimpleObjectAttributeSet. - */ - public SimpleObjectAttributeSet() { - } - - /** - * Creates a new SimpleObjectAttributeSet which contains the attributes - * within the given Set. - * - * @param attributes - * The Set of attributes this SimpleObjectAttributeSet should - * contain. - */ - public SimpleObjectAttributeSet(Set attributes) { - this.attributes = attributes; - } - - /** - * Sets the Set which backs this SimpleObjectAttributeSet. Future function - * calls on this SimpleObjectAttributeSet will use the provided Set. - * - * @param attributes - * The Set of attributes this SimpleObjectAttributeSet should - * contain. - */ - protected void setAttributes(Set attributes) { - this.attributes = attributes; - } - - @Override - public Set getAttributes() throws GuacamoleException { - return attributes; - } - - @Override - public void updateAttributes(Set attributes) throws GuacamoleException { - throw new GuacamoleSecurityException("Permission denied."); - } - -} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUser.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUser.java index 7b9a04653..96171c381 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUser.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUser.java @@ -23,11 +23,13 @@ package org.glyptodon.guacamole.net.auth.simple; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.GuacamoleSecurityException; import org.glyptodon.guacamole.net.auth.AbstractUser; -import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet; import org.glyptodon.guacamole.net.auth.permission.ObjectPermission; import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet; import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet; @@ -107,6 +109,16 @@ public class SimpleUser extends AbstractUser { } + @Override + public Map getAttributes() { + return Collections.emptyMap(); + } + + @Override + public void setAttributes(Map attributes) { + // Do nothing - there are no attributes + } + @Override public SystemPermissionSet getSystemPermissions() throws GuacamoleException { @@ -137,9 +149,4 @@ public class SimpleUser extends AbstractUser { return new SimpleObjectPermissionSet(); } - @Override - public ObjectAttributeSet getAttributes() throws GuacamoleException { - return new SimpleObjectAttributeSet(); - } - } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java index fd558a668..ddbaef80f 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java @@ -34,6 +34,7 @@ import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.User; import org.glyptodon.guacamole.net.auth.UserContext; +import org.glyptodon.guacamole.net.auth.attribute.Attribute; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; /** @@ -174,4 +175,19 @@ public class SimpleUserContext implements UserContext { return new SimpleDirectory(); } + @Override + public Collection getUserAttributes() { + return Collections.emptyList(); + } + + @Override + public Collection getConnectionAttributes() { + return Collections.emptyList(); + } + + @Override + public Collection getConnectionGroupAttributes() { + return Collections.emptyList(); + } + } From 7d13731ffad668bcfccb27b820aadfbd003e4b37 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 24 May 2015 15:37:28 -0700 Subject: [PATCH 4/8] GUAC-800: Add attribute-related stubs to JDBC auth. --- .../jdbc/connection/ModeledConnection.java | 14 ++++++++++++++ .../ModeledConnectionGroup.java | 14 ++++++++++++++ .../connectiongroup/RootConnectionGroup.java | 12 ++++++++++++ .../guacamole/auth/jdbc/user/ModeledUser.java | 14 ++++++++++++++ .../guacamole/auth/jdbc/user/UserContext.java | 18 ++++++++++++++++++ 5 files changed, 72 insertions(+) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ModeledConnection.java index 477b58175..58776f1b6 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -24,7 +24,9 @@ package org.glyptodon.guacamole.auth.jdbc.connection; import com.google.inject.Inject; import com.google.inject.Provider; +import java.util.Collections; import java.util.List; +import java.util.Map; import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.auth.jdbc.base.ModeledGroupedDirectoryObject; @@ -123,4 +125,16 @@ public class ModeledConnection extends ModeledGroupedDirectoryObject getAttributes() { + // FIXME: STUB + return Collections.emptyMap(); + } + + @Override + public void setAttributes(Map attributes) { + // FIXME: STUB + throw new UnsupportedOperationException("STUB"); + } + } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java index 01f09006f..5de208e11 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java @@ -23,6 +23,8 @@ package org.glyptodon.guacamole.auth.jdbc.connectiongroup; import com.google.inject.Inject; +import java.util.Collections; +import java.util.Map; import java.util.Set; import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionService; import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService; @@ -108,4 +110,16 @@ public class ModeledConnectionGroup extends ModeledGroupedDirectoryObject getAttributes() { + // FIXME: STUB + return Collections.emptyMap(); + } + + @Override + public void setAttributes(Map attributes) { + // FIXME: STUB + throw new UnsupportedOperationException("STUB"); + } + } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/RootConnectionGroup.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/RootConnectionGroup.java index cca42af27..74fb4295d 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/RootConnectionGroup.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/RootConnectionGroup.java @@ -23,6 +23,8 @@ package org.glyptodon.guacamole.auth.jdbc.connectiongroup; import com.google.inject.Inject; +import java.util.Collections; +import java.util.Map; import java.util.Set; import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionService; import org.glyptodon.guacamole.GuacamoleException; @@ -135,4 +137,14 @@ public class RootConnectionGroup extends RestrictedObject return 0; } + @Override + public Map getAttributes() { + return Collections.emptyMap(); + } + + @Override + public void setAttributes(Map attributes) { + throw new UnsupportedOperationException("The root connection group cannot be modified."); + } + } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/ModeledUser.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/ModeledUser.java index 1f1b4f508..307a064a6 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/ModeledUser.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/ModeledUser.java @@ -23,6 +23,8 @@ package org.glyptodon.guacamole.auth.jdbc.user; import com.google.inject.Inject; +import java.util.Collections; +import java.util.Map; import org.glyptodon.guacamole.auth.jdbc.base.ModeledDirectoryObject; import org.glyptodon.guacamole.auth.jdbc.security.PasswordEncryptionService; import org.glyptodon.guacamole.auth.jdbc.security.SaltService; @@ -179,4 +181,16 @@ public class ModeledUser extends ModeledDirectoryObject implements Us return userPermissionService.getPermissionSet(getCurrentUser(), this); } + @Override + public Map getAttributes() { + // FIXME: STUB + return Collections.emptyMap(); + } + + @Override + public void setAttributes(Map attributes) { + // FIXME: STUB + throw new UnsupportedOperationException("STUB"); + } + } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java index 0b496240b..ea88cc7f4 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java @@ -28,6 +28,8 @@ import org.glyptodon.guacamole.auth.jdbc.connectiongroup.ConnectionGroupDirector import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionDirectory; import com.google.inject.Inject; import com.google.inject.Provider; +import java.util.Collection; +import java.util.Collections; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject; import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionDirectory; @@ -36,6 +38,7 @@ import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.User; +import org.glyptodon.guacamole.net.auth.attribute.Attribute; /** * UserContext implementation which is driven by an arbitrary, underlying @@ -130,4 +133,19 @@ public class UserContext extends RestrictedObject } + @Override + public Collection getUserAttributes() { + return Collections.emptyList(); + } + + @Override + public Collection getConnectionAttributes() { + return Collections.emptyList(); + } + + @Override + public Collection getConnectionGroupAttributes() { + return Collections.emptyList(); + } + } From c5364f4bffcca84e68b1be24cbbc5b440b893fa8 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 24 May 2015 15:56:49 -0700 Subject: [PATCH 5/8] GUAC-800: Update REST services to allow read/write of attributes on users, connections, and groups. --- .../basic/rest/connection/APIConnection.java | 36 ++++++++++++++++- .../rest/connection/APIConnectionWrapper.java | 10 +++++ .../connection/ConnectionRESTService.java | 1 + .../connectiongroup/APIConnectionGroup.java | 39 ++++++++++++++++++- .../APIConnectionGroupWrapper.java | 11 ++++++ .../ConnectionGroupRESTService.java | 1 + .../net/basic/rest/user/APIUser.java | 36 +++++++++++++++++ .../net/basic/rest/user/APIUserWrapper.java | 11 ++++++ .../net/basic/rest/user/UserRESTService.java | 3 ++ .../main/webapp/app/rest/types/Connection.js | 11 +++++- .../webapp/app/rest/types/ConnectionGroup.js | 9 +++++ .../src/main/webapp/app/rest/types/User.js | 9 +++++ 12 files changed, 173 insertions(+), 4 deletions(-) diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java index 5b8da3f75..628ee1c30 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java @@ -24,6 +24,7 @@ package org.glyptodon.guacamole.net.basic.rest.connection; import java.util.Map; import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.codehaus.jackson.map.annotate.JsonSerialize; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; @@ -34,6 +35,7 @@ import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; * @author James Muehlner */ @JsonIgnoreProperties(ignoreUnknown = true) +@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) public class APIConnection { /** @@ -61,6 +63,11 @@ public class APIConnection { */ private Map parameters; + /** + * Map of all associated attributes by attribute identifier. + */ + private Map attributes; + /** * The count of currently active connections using this connection. */ @@ -92,6 +99,9 @@ public class APIConnection { GuacamoleConfiguration configuration = connection.getConfiguration(); this.protocol = configuration.getProtocol(); + // Associate any attributes + this.attributes = connection.getAttributes(); + } /** @@ -195,5 +205,29 @@ public class APIConnection { public void setActiveUsers(int activeConnections) { this.activeConnections = activeConnections; } - + + /** + * Returns a map of all attributes associated with this connection. Each + * entry key is the attribute identifier, while each value is the attribute + * value itself. + * + * @return + * The attribute map for this connection. + */ + public Map getAttributes() { + return attributes; + } + + /** + * Sets the map of all attributes associated with this connection. Each + * entry key is the attribute identifier, while each value is the attribute + * value itself. + * + * @param attributes + * The attribute map for this connection. + */ + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java index 41d64ceb3..ec0b3c7fb 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java @@ -115,6 +115,16 @@ public class APIConnectionWrapper implements Connection { } + @Override + public Map getAttributes() { + return apiConnection.getAttributes(); + } + + @Override + public void setAttributes(Map attributes) { + apiConnection.setAttributes(attributes); + } + @Override public GuacamoleTunnel connect(GuacamoleClientInformation info) throws GuacamoleException { throw new UnsupportedOperationException("Operation not supported."); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java index 30cd75f94..5b67465c5 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java @@ -305,6 +305,7 @@ public class ConnectionRESTService { existingConnection.setConfiguration(config); existingConnection.setParentIdentifier(connection.getParentIdentifier()); existingConnection.setName(connection.getName()); + existingConnection.setAttributes(connection.getAttributes()); connectionDirectory.update(existingConnection); } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroup.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroup.java index b980983b5..82418b906 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroup.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroup.java @@ -23,7 +23,9 @@ package org.glyptodon.guacamole.net.basic.rest.connectiongroup; import java.util.Collection; +import java.util.Map; import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.codehaus.jackson.map.annotate.JsonSerialize; import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.ConnectionGroup.Type; import org.glyptodon.guacamole.net.basic.rest.connection.APIConnection; @@ -34,6 +36,7 @@ import org.glyptodon.guacamole.net.basic.rest.connection.APIConnection; * @author James Muehlner */ @JsonIgnoreProperties(ignoreUnknown = true) +@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) public class APIConnectionGroup { /** @@ -78,6 +81,11 @@ public class APIConnectionGroup { */ private Collection childConnections; + /** + * Map of all associated attributes by attribute identifier. + */ + private Map attributes; + /** * Create an empty APIConnectionGroup. */ @@ -91,13 +99,16 @@ public class APIConnectionGroup { */ public APIConnectionGroup(ConnectionGroup connectionGroup) { + // Set connection group information this.identifier = connectionGroup.getIdentifier(); this.parentIdentifier = connectionGroup.getParentIdentifier(); - this.name = connectionGroup.getName(); this.type = connectionGroup.getType(); this.activeConnections = connectionGroup.getActiveConnections(); + // Associate any attributes + this.attributes = connectionGroup.getAttributes(); + } /** @@ -233,5 +244,29 @@ public class APIConnectionGroup { public void setActiveUsers(int activeConnections) { this.activeConnections = activeConnections; } - + + /** + * Returns a map of all attributes associated with this connection group. + * Each entry key is the attribute identifier, while each value is the + * attribute value itself. + * + * @return + * The attribute map for this connection group. + */ + public Map getAttributes() { + return attributes; + } + + /** + * Sets the map of all attributes associated with this connection group. + * Each entry key is the attribute identifier, while each value is the + * attribute value itself. + * + * @param attributes + * The attribute map for this connection group. + */ + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroupWrapper.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroupWrapper.java index c37aee94a..8d3dd2679 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroupWrapper.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroupWrapper.java @@ -22,6 +22,7 @@ package org.glyptodon.guacamole.net.basic.rest.connectiongroup; +import java.util.Map; import java.util.Set; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.net.GuacamoleTunnel; @@ -105,6 +106,16 @@ public class APIConnectionGroupWrapper implements ConnectionGroup { throw new UnsupportedOperationException("Operation not supported."); } + @Override + public Map getAttributes() { + return apiConnectionGroup.getAttributes(); + } + + @Override + public void setAttributes(Map attributes) { + apiConnectionGroup.setAttributes(attributes); + } + @Override public GuacamoleTunnel connect(GuacamoleClientInformation info) throws GuacamoleException { throw new UnsupportedOperationException("Operation not supported."); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/ConnectionGroupRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/ConnectionGroupRESTService.java index 8153421cf..2dbf94d1e 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/ConnectionGroupRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/ConnectionGroupRESTService.java @@ -253,6 +253,7 @@ public class ConnectionGroupRESTService { existingConnectionGroup.setName(connectionGroup.getName()); existingConnectionGroup.setParentIdentifier(connectionGroup.getParentIdentifier()); existingConnectionGroup.setType(connectionGroup.getType()); + existingConnectionGroup.setAttributes(connectionGroup.getAttributes()); connectionGroupDirectory.update(existingConnectionGroup); } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/APIUser.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/APIUser.java index 6351f2942..a278e0797 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/APIUser.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/APIUser.java @@ -22,6 +22,7 @@ package org.glyptodon.guacamole.net.basic.rest.user; +import java.util.Map; import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.map.annotate.JsonSerialize; import org.glyptodon.guacamole.net.auth.User; @@ -45,6 +46,11 @@ public class APIUser { */ private String password; + /** + * Map of all associated attributes by attribute identifier. + */ + private Map attributes; + /** * Construct a new empty APIUser. */ @@ -55,8 +61,14 @@ public class APIUser { * @param user The User to construct the APIUser from. */ public APIUser(User user) { + + // Set user information this.username = user.getIdentifier(); this.password = user.getPassword(); + + // Associate any attributes + this.attributes = user.getAttributes(); + } /** @@ -91,4 +103,28 @@ public class APIUser { this.password = password; } + /** + * Returns a map of all attributes associated with this user. Each entry + * key is the attribute identifier, while each value is the attribute + * value itself. + * + * @return + * The attribute map for this user. + */ + public Map getAttributes() { + return attributes; + } + + /** + * Sets the map of all attributes associated with this user. Each entry key + * is the attribute identifier, while each value is the attribute value + * itself. + * + * @param attributes + * The attribute map for this user. + */ + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/APIUserWrapper.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/APIUserWrapper.java index c1bc8b58a..f918dbf05 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/APIUserWrapper.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/APIUserWrapper.java @@ -22,6 +22,7 @@ package org.glyptodon.guacamole.net.basic.rest.user; +import java.util.Map; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleUnsupportedException; import org.glyptodon.guacamole.net.auth.User; @@ -71,6 +72,16 @@ public class APIUserWrapper implements User { apiUser.setPassword(password); } + @Override + public Map getAttributes() { + return apiUser.getAttributes(); + } + + @Override + public void setAttributes(Map attributes) { + apiUser.setAttributes(attributes); + } + @Override public SystemPermissionSet getSystemPermissions() throws GuacamoleException { diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/UserRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/UserRESTService.java index af785fc65..6e57520d1 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/UserRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/UserRESTService.java @@ -291,6 +291,9 @@ public class UserRESTService { if (user.getPassword() != null) existingUser.setPassword(user.getPassword()); + // Update user attributes + existingUser.setAttributes(user.getAttributes()); + // Update the user userDirectory.update(existingUser); diff --git a/guacamole/src/main/webapp/app/rest/types/Connection.js b/guacamole/src/main/webapp/app/rest/types/Connection.js index 3c3efb87a..488cfdcff 100644 --- a/guacamole/src/main/webapp/app/rest/types/Connection.js +++ b/guacamole/src/main/webapp/app/rest/types/Connection.js @@ -79,7 +79,16 @@ angular.module('rest').factory('Connection', [function defineConnection() { * @type Object. */ this.parameters = template.parameters; - + + /** + * Arbitrary name/value pairs which further describe this connection. + * The semantics and validity of these attributes are dictated by the + * extension which defines them. + * + * @type Object. + */ + this.attributes = {}; + /** * The count of currently active connections using this connection. * This field will be returned from the REST API during a get diff --git a/guacamole/src/main/webapp/app/rest/types/ConnectionGroup.js b/guacamole/src/main/webapp/app/rest/types/ConnectionGroup.js index cdb3fe232..7c3dc2b85 100644 --- a/guacamole/src/main/webapp/app/rest/types/ConnectionGroup.js +++ b/guacamole/src/main/webapp/app/rest/types/ConnectionGroup.js @@ -91,6 +91,15 @@ angular.module('rest').factory('ConnectionGroup', [function defineConnectionGrou */ this.childConnectionGroups = template.childConnectionGroups; + /** + * Arbitrary name/value pairs which further describe this connection + * group. The semantics and validity of these attributes are dictated + * by the extension which defines them. + * + * @type Object. + */ + this.attributes = {}; + /** * The count of currently active connections using this connection * group. This field will be returned from the REST API during a get diff --git a/guacamole/src/main/webapp/app/rest/types/User.js b/guacamole/src/main/webapp/app/rest/types/User.js index 499e4d2ab..8c18d0157 100644 --- a/guacamole/src/main/webapp/app/rest/types/User.js +++ b/guacamole/src/main/webapp/app/rest/types/User.js @@ -56,6 +56,15 @@ angular.module('rest').factory('User', [function defineUser() { */ this.password = template.password; + /** + * Arbitrary name/value pairs which further describe this user. The + * semantics and validity of these attributes are dictated by the + * extension which defines them. + * + * @type Object. + */ + this.attributes = {}; + }; return User; From 191bc0d465e4fbbf800a8b3858eabf7e0d0caf1e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 24 May 2015 18:48:52 -0700 Subject: [PATCH 6/8] GUAC-800: Remove stubs - no supported attributes for now. --- .../guacamole/auth/jdbc/connection/ModeledConnection.java | 4 +--- .../auth/jdbc/connectiongroup/ModeledConnectionGroup.java | 4 +--- .../org/glyptodon/guacamole/auth/jdbc/user/ModeledUser.java | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ModeledConnection.java index 58776f1b6..dad6c69dd 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -127,14 +127,12 @@ public class ModeledConnection extends ModeledGroupedDirectoryObject getAttributes() { - // FIXME: STUB return Collections.emptyMap(); } @Override public void setAttributes(Map attributes) { - // FIXME: STUB - throw new UnsupportedOperationException("STUB"); + // Drop all attributes - none currently supported } } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java index 5de208e11..5d46147f5 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java @@ -112,14 +112,12 @@ public class ModeledConnectionGroup extends ModeledGroupedDirectoryObject getAttributes() { - // FIXME: STUB return Collections.emptyMap(); } @Override public void setAttributes(Map attributes) { - // FIXME: STUB - throw new UnsupportedOperationException("STUB"); + // Drop all attributes - none currently supported } } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/ModeledUser.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/ModeledUser.java index 307a064a6..36479f96c 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/ModeledUser.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/ModeledUser.java @@ -183,14 +183,12 @@ public class ModeledUser extends ModeledDirectoryObject implements Us @Override public Map getAttributes() { - // FIXME: STUB return Collections.emptyMap(); } @Override public void setAttributes(Map attributes) { - // FIXME: STUB - throw new UnsupportedOperationException("STUB"); + // Drop all attributes - none currently supported } } From a4a2a3762305e589325b1e0f17320c8c87987505 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 24 May 2015 19:20:36 -0700 Subject: [PATCH 7/8] GUAC-800: Use Parameter for describing attributes. --- .../guacamole/auth/jdbc/user/UserContext.java | 14 +- .../guacamole/net/auth/UserContext.java | 8 +- .../net/auth/attribute/Attribute.java | 127 ------------------ .../net/auth/attribute/package-info.java | 27 ---- .../net/auth/simple/SimpleUserContext.java | 14 +- 5 files changed, 18 insertions(+), 172 deletions(-) delete mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java delete mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/package-info.java diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java index ea88cc7f4..171642e7b 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java @@ -33,12 +33,12 @@ import java.util.Collections; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject; import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionDirectory; +import org.glyptodon.guacamole.form.Parameter; import org.glyptodon.guacamole.net.auth.ActiveConnection; import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.User; -import org.glyptodon.guacamole.net.auth.attribute.Attribute; /** * UserContext implementation which is driven by an arbitrary, underlying @@ -134,18 +134,18 @@ public class UserContext extends RestrictedObject } @Override - public Collection getUserAttributes() { - return Collections.emptyList(); + public Collection getUserAttributes() { + return Collections.emptyList(); } @Override - public Collection getConnectionAttributes() { - return Collections.emptyList(); + public Collection getConnectionAttributes() { + return Collections.emptyList(); } @Override - public Collection getConnectionGroupAttributes() { - return Collections.emptyList(); + public Collection getConnectionGroupAttributes() { + return Collections.emptyList(); } } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java index 0d782e9dc..e5d1f2547 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java @@ -24,7 +24,7 @@ package org.glyptodon.guacamole.net.auth; import java.util.Collection; import org.glyptodon.guacamole.GuacamoleException; -import org.glyptodon.guacamole.net.auth.attribute.Attribute; +import org.glyptodon.guacamole.form.Parameter; /** * The context of an active user. The functions of this class enforce all @@ -121,7 +121,7 @@ public interface UserContext { * @return * A collection of all attributes applicable to users. */ - Collection getUserAttributes(); + Collection getUserAttributes(); /** * Retrieves a collection of all attributes applicable to connections. This @@ -132,7 +132,7 @@ public interface UserContext { * @return * A collection of all attributes applicable to connections. */ - Collection getConnectionAttributes(); + Collection getConnectionAttributes(); /** * Retrieves a collection of all attributes applicable to connection @@ -143,6 +143,6 @@ public interface UserContext { * @return * A collection of all attributes applicable to connection groups. */ - Collection getConnectionGroupAttributes(); + Collection getConnectionGroupAttributes(); } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java deleted file mode 100644 index 38e75b538..000000000 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/Attribute.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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.attribute; - -import org.glyptodon.guacamole.net.auth.Identifiable; - -/** - * An arbitrary attribute. Each attribute associates an identifier with a - * type, where the type dictates the semantics and legal values of the - * attribute. - * - * @author Michael Jumper - */ -public class Attribute implements Identifiable { - - /** - * The string which uniquely identifies this attribute. - */ - private String identifier; - - /** - * The type of this attribute. - */ - private Type type; - - /** - * Specific types of attributes. Each attribute type describes the kind of - * values the attribute can accept, and defines any semantics associated - * with those values. - */ - public enum Type { - - /** - * A text attribute, accepting arbitrary values. - */ - TEXT, - - /** - * A username attribute. This attribute type generally behaves - * identically to arbitrary text attributes, but has semantic - * differences. - */ - USERNAME, - - /** - * A password attribute, whose value is sensitive and must be hidden. - */ - PASSWORD, - - /** - * A numeric attribute, whose value must contain only digits. - */ - NUMERIC, - - /** - * A boolean attribute, whose value is either blank or "true". - */ - BOOLEAN, - - /** - * An enumerated attribute, whose legal values are fully enumerated - * by a provided, finite list. - */ - ENUM, - - /** - * A text attribute that can span more than one line. - */ - MULTILINE - - } - - @Override - public String getIdentifier() { - return identifier; - } - - @Override - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - /** - * Returns the type of this attribute. The attribute type dictates the kind - * of values the attribute can contain, and the semantics of the attribute - * as a whole. - * - * @return - * The type of this attribute. - */ - public Type getType() { - return type; - } - - /** - * Sets the type of this attribute. Attribute type dictates the kind of - * values the attribute can contain, and the semantics of the attribute as - * a whole. - * - * @param type - * The type to associate with this attribute. - */ - void setType(Type type) { - this.type = type; - } - -} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/package-info.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/package-info.java deleted file mode 100644 index e653cf71a..000000000 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/attribute/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ - -/** - * Provides classes which describe the various attributes that can be - * associated with Guacamole objects, such as a user or a connection. - */ -package org.glyptodon.guacamole.net.auth.attribute; diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java index ddbaef80f..1f722428f 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java @@ -28,13 +28,13 @@ import java.util.Collections; import java.util.Map; import java.util.UUID; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.form.Parameter; import org.glyptodon.guacamole.net.auth.ActiveConnection; import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.User; import org.glyptodon.guacamole.net.auth.UserContext; -import org.glyptodon.guacamole.net.auth.attribute.Attribute; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; /** @@ -176,18 +176,18 @@ public class SimpleUserContext implements UserContext { } @Override - public Collection getUserAttributes() { - return Collections.emptyList(); + public Collection getUserAttributes() { + return Collections.emptyList(); } @Override - public Collection getConnectionAttributes() { - return Collections.emptyList(); + public Collection getConnectionAttributes() { + return Collections.emptyList(); } @Override - public Collection getConnectionGroupAttributes() { - return Collections.emptyList(); + public Collection getConnectionGroupAttributes() { + return Collections.emptyList(); } } From dfedcf3058538c294907091ba2a62aa2c085632a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 24 May 2015 19:37:07 -0700 Subject: [PATCH 8/8] GUAC-800: Provide access via REST to attribute information. Move protocol descriptions into common REST service. --- .../net/basic/rest/RESTServletModule.java | 4 +- .../rest/protocol/ProtocolRESTService.java | 88 ---------- .../basic/rest/schema/SchemaRESTService.java | 163 ++++++++++++++++++ .../{protocol => schema}/package-info.java | 8 +- .../controllers/manageConnectionController.js | 4 +- .../webapp/app/rest/services/cacheService.js | 6 +- .../app/rest/services/protocolService.js | 64 ------- .../webapp/app/rest/services/schemaService.js | 145 ++++++++++++++++ 8 files changed, 319 insertions(+), 163 deletions(-) delete mode 100644 guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/protocol/ProtocolRESTService.java create mode 100644 guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/schema/SchemaRESTService.java rename guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/{protocol => schema}/package-info.java (82%) delete mode 100644 guacamole/src/main/webapp/app/rest/services/protocolService.js create mode 100644 guacamole/src/main/webapp/app/rest/services/schemaService.js diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java index a6e54c7a6..568630d7a 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java @@ -31,9 +31,9 @@ import org.glyptodon.guacamole.net.basic.rest.auth.TokenRESTService; import org.glyptodon.guacamole.net.basic.rest.clipboard.ClipboardRESTService; import org.glyptodon.guacamole.net.basic.rest.connection.ConnectionRESTService; import org.glyptodon.guacamole.net.basic.rest.connectiongroup.ConnectionGroupRESTService; -import org.glyptodon.guacamole.net.basic.rest.protocol.ProtocolRESTService; import org.glyptodon.guacamole.net.basic.rest.activeconnection.ActiveConnectionRESTService; import org.glyptodon.guacamole.net.basic.rest.language.LanguageRESTService; +import org.glyptodon.guacamole.net.basic.rest.schema.SchemaRESTService; import org.glyptodon.guacamole.net.basic.rest.user.UserRESTService; /** @@ -62,7 +62,7 @@ public class RESTServletModule extends ServletModule { bind(ConnectionGroupRESTService.class); bind(ConnectionRESTService.class); bind(LanguageRESTService.class); - bind(ProtocolRESTService.class); + bind(SchemaRESTService.class); bind(TokenRESTService.class); bind(UserRESTService.class); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/protocol/ProtocolRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/protocol/ProtocolRESTService.java deleted file mode 100644 index 4d99465ee..000000000 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/protocol/ProtocolRESTService.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2014 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.basic.rest.protocol; - -import com.google.inject.Inject; -import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import org.glyptodon.guacamole.GuacamoleException; -import org.glyptodon.guacamole.environment.Environment; -import org.glyptodon.guacamole.environment.LocalEnvironment; -import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; -import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; -import org.glyptodon.guacamole.protocols.ProtocolInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A REST Service for handling the listing of protocols. - * - * @author James Muehlner - */ -@Path("/protocols") -@Produces(MediaType.APPLICATION_JSON) -public class ProtocolRESTService { - - /** - * Logger for this class. - */ - private static final Logger logger = LoggerFactory.getLogger(ProtocolRESTService.class); - - /** - * A service for authenticating users from auth tokens. - */ - @Inject - private AuthenticationService authenticationService; - - /** - * Gets a map of protocols defined in the system - protocol name to protocol. - * - * @param authToken - * The authentication token that is used to authenticate the user - * performing the operation. - * - * @return - * A map of protocol information, where each key is the unique name - * associated with that protocol. - * - * @throws GuacamoleException - * If an error occurs while retrieving the available protocols. - */ - @GET - @AuthProviderRESTExposure - public Map getProtocols(@QueryParam("token") String authToken) throws GuacamoleException { - - // Verify the given auth token is valid - authenticationService.getUserContext(authToken); - - // Get and return a map of all protocols. - Environment env = new LocalEnvironment(); - return env.getProtocols(); - - } - -} diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/schema/SchemaRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/schema/SchemaRESTService.java new file mode 100644 index 000000000..029700ec0 --- /dev/null +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/schema/SchemaRESTService.java @@ -0,0 +1,163 @@ +/* + * 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.basic.rest.schema; + +import com.google.inject.Inject; +import java.util.Collection; +import java.util.Map; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.environment.Environment; +import org.glyptodon.guacamole.environment.LocalEnvironment; +import org.glyptodon.guacamole.form.Parameter; +import org.glyptodon.guacamole.net.auth.UserContext; +import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; +import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; +import org.glyptodon.guacamole.protocols.ProtocolInfo; + +/** + * A REST service which provides access to descriptions of the properties, + * attributes, etc. of objects used within the Guacamole REST API. + * + * @author Michael Jumper + */ +@Path("/schema") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class SchemaRESTService { + + /** + * A service for authenticating users from auth tokens. + */ + @Inject + private AuthenticationService authenticationService; + + /** + * Retrieves the possible attributes of a user object. + * + * @param authToken + * The authentication token that is used to authenticate the user + * performing the operation. + * + * @return + * A collection of form parameters which describe the possible + * attributes of a user object. + * + * @throws GuacamoleException + * If an error occurs while retrieving the possible attributes. + */ + @GET + @Path("/users/attributes") + @AuthProviderRESTExposure + public Collection getUserAttributes(@QueryParam("token") String authToken) throws GuacamoleException { + + // Retrieve all possible user attributes + UserContext userContext = authenticationService.getUserContext(authToken); + return userContext.getUserAttributes(); + + } + + /** + * Retrieves the possible attributes of a connection object. + * + * @param authToken + * The authentication token that is used to authenticate the user + * performing the operation. + * + * @return + * A collection of form parameters which describe the possible + * attributes of a connection object. + * + * @throws GuacamoleException + * If an error occurs while retrieving the possible attributes. + */ + @GET + @Path("/connections/attributes") + @AuthProviderRESTExposure + public Collection getConnectionAttributes(@QueryParam("token") String authToken) throws GuacamoleException { + + // Retrieve all possible connection attributes + UserContext userContext = authenticationService.getUserContext(authToken); + return userContext.getConnectionAttributes(); + + } + + /** + * Retrieves the possible attributes of a connection group object. + * + * @param authToken + * The authentication token that is used to authenticate the user + * performing the operation. + * + * @return + * A collection of form parameters which describe the possible + * attributes of a connection group object. + * + * @throws GuacamoleException + * If an error occurs while retrieving the possible attributes. + */ + @GET + @Path("/connectionGroups/attributes") + @AuthProviderRESTExposure + public Collection getConnectionGroupAttributes(@QueryParam("token") String authToken) throws GuacamoleException { + + // Retrieve all possible connection group attributes + UserContext userContext = authenticationService.getUserContext(authToken); + return userContext.getConnectionGroupAttributes(); + + } + + /** + * Gets a map of protocols defined in the system - protocol name to protocol. + * + * @param authToken + * The authentication token that is used to authenticate the user + * performing the operation. + * + * @return + * A map of protocol information, where each key is the unique name + * associated with that protocol. + * + * @throws GuacamoleException + * If an error occurs while retrieving the available protocols. + */ + @GET + @Path("/protocols") + @AuthProviderRESTExposure + public Map getProtocols(@QueryParam("token") String authToken) throws GuacamoleException { + + // Verify the given auth token is valid + authenticationService.getUserContext(authToken); + + // Get and return a map of all protocols. + Environment env = new LocalEnvironment(); + return env.getProtocols(); + + } + +} diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/protocol/package-info.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/schema/package-info.java similarity index 82% rename from guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/protocol/package-info.java rename to guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/schema/package-info.java index 445dc5cef..e9aaaa552 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/protocol/package-info.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/schema/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Glyptodon LLC + * 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 @@ -21,7 +21,7 @@ */ /** - * Classes related to the protocol retrieval aspect of the Guacamole REST API. + * Classes related to the self-description of the Guacamole REST API, such as + * the attributes or parameters applicable to specific objects. */ -package org.glyptodon.guacamole.net.basic.rest.protocol; - +package org.glyptodon.guacamole.net.basic.rest.schema; diff --git a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js index 989875a69..731950db3 100644 --- a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js +++ b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js @@ -41,7 +41,7 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i var connectionService = $injector.get('connectionService'); var connectionGroupService = $injector.get('connectionGroupService'); var permissionService = $injector.get('permissionService'); - var protocolService = $injector.get('protocolService'); + var schemaService = $injector.get('schemaService'); var translationStringService = $injector.get('translationStringService'); /** @@ -205,7 +205,7 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i }); // Get protocol metadata - protocolService.getProtocols().success(function protocolsReceived(protocols) { + schemaService.getProtocols().success(function protocolsReceived(protocols) { $scope.protocols = protocols; }); diff --git a/guacamole/src/main/webapp/app/rest/services/cacheService.js b/guacamole/src/main/webapp/app/rest/services/cacheService.js index 12ee0f275..ef523dcb8 100644 --- a/guacamole/src/main/webapp/app/rest/services/cacheService.js +++ b/guacamole/src/main/webapp/app/rest/services/cacheService.js @@ -49,11 +49,11 @@ angular.module('rest').factory('cacheService', ['$injector', service.languages = $cacheFactory('API-LANGUAGES'); /** - * Cache used by protocolService. + * Cache used by schemaService. * * @type $cacheFactory.Cache */ - service.protocols = $cacheFactory('API-PROTOCOLS'); + service.schema = $cacheFactory('API-SCHEMA'); /** * Shared cache used by both userService and permissionService. @@ -68,7 +68,7 @@ angular.module('rest').factory('cacheService', ['$injector', service.clearCaches = function clearCaches() { service.connections.removeAll(); service.languages.removeAll(); - service.protocols.removeAll(); + service.schema.removeAll(); service.users.removeAll(); }; diff --git a/guacamole/src/main/webapp/app/rest/services/protocolService.js b/guacamole/src/main/webapp/app/rest/services/protocolService.js deleted file mode 100644 index 3306f8b1a..000000000 --- a/guacamole/src/main/webapp/app/rest/services/protocolService.js +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -/** - * Service for operating on protocol metadata via the REST API. - */ -angular.module('rest').factory('protocolService', ['$injector', - function protocolService($injector) { - - // Required services - var $http = $injector.get('$http'); - var authenticationService = $injector.get('authenticationService'); - var cacheService = $injector.get('cacheService'); - - var service = {}; - - /** - * Makes a request to the REST API to get the list of protocols, returning - * a promise that provides a map of @link{Protocol} objects by protocol - * name if successful. - * - * @returns {Promise.>} - * A promise which will resolve with a map of @link{Protocol} - * objects by protocol name upon success. - */ - service.getProtocols = function getProtocols() { - - // Build HTTP parameters set - var httpParameters = { - token : authenticationService.getCurrentToken() - }; - - // Retrieve available protocols - return $http({ - cache : cacheService.protocols, - method : 'GET', - url : 'api/protocols', - params : httpParameters - }); - - }; - - return service; - -}]); diff --git a/guacamole/src/main/webapp/app/rest/services/schemaService.js b/guacamole/src/main/webapp/app/rest/services/schemaService.js new file mode 100644 index 000000000..bb8986fa2 --- /dev/null +++ b/guacamole/src/main/webapp/app/rest/services/schemaService.js @@ -0,0 +1,145 @@ +/* + * 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. + */ + +/** + * Service for operating on metadata via the REST API. + */ +angular.module('rest').factory('schemaService', ['$injector', + function schemaService($injector) { + + // Required services + var $http = $injector.get('$http'); + var authenticationService = $injector.get('authenticationService'); + var cacheService = $injector.get('cacheService'); + + var service = {}; + + /** + * Makes a request to the REST API to get the list of available attributes + * for user objects, returning a promise that provides an array of + * @link{Field} objects if successful. Each element of the array describes + * a possible attribute. + * + * @returns {Promise.} + * A promise which will resolve with an array of @link{Field} + * objects, where each @link{Field} describes a possible attribute. + */ + service.getUserAttributes = function getUserAttributes() { + + // Build HTTP parameters set + var httpParameters = { + token : authenticationService.getCurrentToken() + }; + + // Retrieve available user attributes + return $http({ + cache : cacheService.schema, + method : 'GET', + url : 'api/schema/users/attributes', + params : httpParameters + }); + + }; + + /** + * Makes a request to the REST API to get the list of available attributes + * for connection objects, returning a promise that provides an array of + * @link{Field} objects if successful. Each element of the array describes + * a possible attribute. + * + * @returns {Promise.} + * A promise which will resolve with an array of @link{Field} + * objects, where each @link{Field} describes a possible attribute. + */ + service.getConnectionAttributes = function getConnectionAttributes() { + + // Build HTTP parameters set + var httpParameters = { + token : authenticationService.getCurrentToken() + }; + + // Retrieve available connection attributes + return $http({ + cache : cacheService.schema, + method : 'GET', + url : 'api/schema/connections/attributes', + params : httpParameters + }); + + }; + + /** + * Makes a request to the REST API to get the list of available attributes + * for connection group objects, returning a promise that provides an array + * of @link{Field} objects if successful. Each element of the array + * describes a possible attribute. + * + * @returns {Promise.} + * A promise which will resolve with an array of @link{Field} + * objects, where each @link{Field} describes a possible attribute. + */ + service.getConnectionGroupAttributes = function getConnectionGroupAttributes() { + + // Build HTTP parameters set + var httpParameters = { + token : authenticationService.getCurrentToken() + }; + + // Retrieve available connection group attributes + return $http({ + cache : cacheService.schema, + method : 'GET', + url : 'api/schema/connectionGroups/attributes', + params : httpParameters + }); + + }; + + /** + * Makes a request to the REST API to get the list of protocols, returning + * a promise that provides a map of @link{Protocol} objects by protocol + * name if successful. + * + * @returns {Promise.>} + * A promise which will resolve with a map of @link{Protocol} + * objects by protocol name upon success. + */ + service.getProtocols = function getProtocols() { + + // Build HTTP parameters set + var httpParameters = { + token : authenticationService.getCurrentToken() + }; + + // Retrieve available protocols + return $http({ + cache : cacheService.schema, + method : 'GET', + url : 'api/schema/protocols', + params : httpParameters + }); + + }; + + return service; + +}]);