From 75f6e75176109936d399375cc8b4b611a957b626 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 23 May 2015 21:29:42 -0700 Subject: [PATCH] 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(); + } + }