mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUAC-800: Define ObjectAttribute and associated interfaces.
This commit is contained in:
@@ -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);
|
||||||
|
|
||||||
|
}
|
@@ -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 <AttributeType>
|
||||||
|
* The type of attribute stored within this AttributeSet.
|
||||||
|
*/
|
||||||
|
public interface AttributeSet<AttributeType extends Attribute> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<AttributeType> 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<AttributeType> attributes)
|
||||||
|
throws GuacamoleException;
|
||||||
|
|
||||||
|
}
|
@@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -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<ObjectAttribute> {
|
||||||
|
}
|
@@ -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;
|
Reference in New Issue
Block a user