GUAC-800: Associate attributes with users and connections.

This commit is contained in:
Michael Jumper
2015-05-23 21:29:42 -07:00
parent 7a20a33e95
commit 75f6e75176
5 changed files with 124 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ package org.glyptodon.guacamole.net.auth;
import java.util.List; import java.util.List;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.net.auth.attribute.ObjectAttributeSet;
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
/** /**
@@ -100,4 +101,17 @@ public interface Connection extends Identifiable, Connectable {
*/ */
public List<? extends ConnectionRecord> getHistory() throws GuacamoleException; public List<? extends ConnectionRecord> 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;
} }

View File

@@ -23,6 +23,7 @@
package org.glyptodon.guacamole.net.auth; package org.glyptodon.guacamole.net.auth;
import org.glyptodon.guacamole.GuacamoleException; 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.ObjectPermissionSet;
import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet; import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet;
@@ -119,4 +120,16 @@ public interface User extends Identifiable {
*/ */
ObjectPermissionSet getUserPermissions() throws GuacamoleException; 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;
} }

View File

@@ -34,6 +34,7 @@ import org.glyptodon.guacamole.net.SSLGuacamoleSocket;
import org.glyptodon.guacamole.net.SimpleGuacamoleTunnel; import org.glyptodon.guacamole.net.SimpleGuacamoleTunnel;
import org.glyptodon.guacamole.net.auth.AbstractConnection; import org.glyptodon.guacamole.net.auth.AbstractConnection;
import org.glyptodon.guacamole.net.auth.ConnectionRecord; 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.ConfiguredGuacamoleSocket;
import org.glyptodon.guacamole.protocol.GuacamoleClientInformation; import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
@@ -132,4 +133,9 @@ public class SimpleConnection extends AbstractConnection {
return Collections.<ConnectionRecord>emptyList(); return Collections.<ConnectionRecord>emptyList();
} }
@Override
public ObjectAttributeSet getAttributes() throws GuacamoleException {
return new SimpleObjectAttributeSet();
}
} }

View File

@@ -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<ObjectAttribute> attributes = Collections.<ObjectAttribute>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<ObjectAttribute> 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<ObjectAttribute> attributes) {
this.attributes = attributes;
}
@Override
public Set<ObjectAttribute> getAttributes() throws GuacamoleException {
return attributes;
}
@Override
public void updateAttributes(Set<ObjectAttribute> attributes) throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied.");
}
}

View File

@@ -27,6 +27,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.net.auth.AbstractUser; 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.ObjectPermission;
import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet; import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet; import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet;
@@ -136,4 +137,9 @@ public class SimpleUser extends AbstractUser {
return new SimpleObjectPermissionSet(); return new SimpleObjectPermissionSet();
} }
@Override
public ObjectAttributeSet getAttributes() throws GuacamoleException {
return new SimpleObjectAttributeSet();
}
} }