Skip to content

Commit

Permalink
GUACAMOLE-1006: Add Environment support for property collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
necouchman committed Aug 21, 2021
1 parent b60eff4 commit 841194f
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.guacamole.environment;

import java.io.File;
import java.util.Collection;
import java.util.Map;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration;
Expand Down Expand Up @@ -73,11 +74,35 @@ public <Type> Type getProperty(GuacamoleProperty<Type> property) throws Guacamol
public <Type> Type getProperty(GuacamoleProperty<Type> property, Type defaultValue) throws GuacamoleException {
return environment.getProperty(property, defaultValue);
}

@Override
public <Type> Collection<Type> getPropertyCollection(GuacamoleProperty<Type> property)
throws GuacamoleException {
return environment.getPropertyCollection(property);
}

@Override
public <Type> Collection<Type> getPropertyCollection(GuacamoleProperty<Type> property,
Type defaultValue) throws GuacamoleException {
return environment.getPropertyCollection(property, defaultValue);
}

@Override
public <Type> Collection<Type> getPropertyCollection(GuacamoleProperty<Type> property,
Collection<Type> defaultValue) throws GuacamoleException {
return environment.getPropertyCollection(property, defaultValue);
}

@Override
public <Type> Type getRequiredProperty(GuacamoleProperty<Type> property) throws GuacamoleException {
return environment.getRequiredProperty(property);
}

@Override
public <Type> Collection<Type> getRequiredPropertyCollection(GuacamoleProperty<Type> property)
throws GuacamoleException {
return environment.getRequiredPropertyCollection(property);
}

@Override
public GuacamoleProxyConfiguration getDefaultGuacamoleProxyConfiguration() throws GuacamoleException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.guacamole.properties.GuacamoleProperties;
import java.io.File;
import java.util.Collection;
import java.util.Map;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleUnsupportedException;
Expand Down Expand Up @@ -102,13 +103,18 @@ public interface Environment {
* Given a GuacamoleProperty, parses and returns the value set for that
* property in guacamole.properties, if any.
*
* @param <Type> The type that the given property is parsed into.
* @param property The property to read from guacamole.properties.
* @return The parsed value of the property as read from
* guacamole.properties.
* @throws GuacamoleException If an error occurs while parsing the value
* for the given property in
* guacamole.properties.
* @param <Type>
* The type that the given property is parsed into.
*
* @param property
* The property to read from guacamole.properties.
*
* @return
* The parsed value of the property as read from guacamole.properties.
*
* @throws GuacamoleException
* If an error occurs while parsing the value for the given property in
* guacamole.properties.
*/
public <Type> Type getProperty(GuacamoleProperty<Type> property)
throws GuacamoleException;
Expand All @@ -118,20 +124,103 @@ public <Type> Type getProperty(GuacamoleProperty<Type> property)
* property in guacamole.properties, if any. If no value is found, the
* provided default value is returned.
*
* @param <Type> The type that the given property is parsed into.
* @param property The property to read from guacamole.properties.
* @param defaultValue The value to return if no value was given in
* guacamole.properties.
* @return The parsed value of the property as read from
* guacamole.properties, or the provided default value if no value
* was found.
* @throws GuacamoleException If an error occurs while parsing the value
* for the given property in
* guacamole.properties.
* @param <Type>
* The type that the given property is parsed into.
*
* @param property
* The property to read from guacamole.properties.
*
* @param defaultValue
* The value to return if no value was given in guacamole.properties.
*
* @return
* The parsed value of the property as read from guacamole.properties,
* or the provided default value if no value was found.
*
* @throws GuacamoleException
* If an error occurs while parsing the value for the given property in
* guacamole.properties.
*/
public <Type> Type getProperty(GuacamoleProperty<Type> property,
Type defaultValue) throws GuacamoleException;

/**
* Given a GuacamoleProperty, parses and returns a sorted Collection of the
* value set for that property in guacamole.properties, if any.
*
* @param <Type>
* The type that the given property is parsed into.
*
* @param property
* The property to read from guacamole.properties.
*
* @return
* A sorted collection of the the parsed values of the property as read
* from guacamole.properties.
*
* @throws GuacamoleException
* If an error occurs while parsing the value for the given property in
* guacamole.properties.
*/
public <Type> Collection<Type> getPropertyCollection(
GuacamoleProperty<Type> property) throws GuacamoleException;

/**
* Given a GuacamoleProperty, parses and returns the value set for that
* property in guacamole.properties, if any. If no value is found, a
* Collection is returned with the provided default value.
*
* @param <Type>
* The type that the given property is parsed into.
*
* @param property
* The property to read from guacamole.properties.
*
* @param defaultValue
* The single value to return in the Collection if no value was given
* in guacamole.properties.
*
* @return
* A sorted collection of the the parsed values of the property as read
* from guacamole.properties, or a Collection with the single default
* value provided.
*
* @throws GuacamoleException
* If an error occurs while parsing the value for the given property in
* guacamole.properties.
*/
public <Type> Collection<Type> getPropertyCollection(
GuacamoleProperty<Type> property, Type defaultValue)
throws GuacamoleException;

/**
* Given a GuacamoleProperty, parses and returns the value set for that
* property in guacamole.properties, if any. If no value is found, the
* provided Collection of default values is returned.
*
* @param <Type>
* The type that the given property is parsed into.
*
* @param property
* The property to read from guacamole.properties.
*
* @param defaultValue
* The Collection of values to return in the Collection if no value was
* given in guacamole.properties.
*
* @return
* A sorted collection of the the parsed values of the property as read
* from guacamole.properties, or a Collection with the single default
* value provided.
*
* @throws GuacamoleException
* If an error occurs while parsing the value for the given property in
* guacamole.properties.
*/
public <Type> Collection<Type> getPropertyCollection(
GuacamoleProperty<Type> property, Collection<Type> defaultValue)
throws GuacamoleException;

/**
* Given a GuacamoleProperty, parses and returns the value set for that
* property in guacamole.properties. An exception is thrown if the value
Expand All @@ -148,6 +237,27 @@ public <Type> Type getProperty(GuacamoleProperty<Type> property,
*/
public <Type> Type getRequiredProperty(GuacamoleProperty<Type> property)
throws GuacamoleException;

/**
* Given a GuacamoleProperty, parses and returns a sorted Collection of
* values for that property in guacamole.properties. An exception is thrown
* if the value is not provided.
*
* @param <Type>
* The type that the given property is parsed into.
*
* @param property
* The property to read from guacamole.properties.
*
* @return
* A sorted Collection of the property as read from guacamole.properties.
*
* @throws GuacamoleException
* If an error occurs while parsing the value for the given property in
* guacamole.properties, or if the property is not specified.
*/
public <Type> Collection<Type> getRequiredPropertyCollection(
GuacamoleProperty<Type> property) throws GuacamoleException;

/**
* Returns the connection information which should be used, by default, to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -353,6 +355,38 @@ public <Type> Type getProperty(GuacamoleProperty<Type> property,
return value;

}

@Override
public <Type> Collection<Type> getPropertyCollection(GuacamoleProperty<Type> property)
throws GuacamoleException {

return property.parseValueCollection(getPropertyValue(property.getName()));

}

@Override
public <Type> Collection<Type> getPropertyCollection(GuacamoleProperty<Type> property,
Type defaultValue) throws GuacamoleException {

Collection<Type> value = getPropertyCollection(property);
if (value == null)
return Collections.singletonList(defaultValue);

return value;

}

@Override
public <Type> Collection<Type> getPropertyCollection(GuacamoleProperty<Type> property,
Collection<Type> defaultValue) throws GuacamoleException {

Collection<Type> value = getPropertyCollection(property);
if (value == null)
return defaultValue;

return value;

}

@Override
public <Type> Type getRequiredProperty(GuacamoleProperty<Type> property)
Expand All @@ -365,6 +399,18 @@ public <Type> Type getRequiredProperty(GuacamoleProperty<Type> property)
return value;

}

@Override
public <Type> Collection<Type> getRequiredPropertyCollection(GuacamoleProperty<Type> property)
throws GuacamoleException {

Collection<Type> value = getPropertyCollection(property);
if (value == null)
throw new GuacamoleServerException("Property " + property.getName() + " is required.");

return value;

}

@Override
public Map<String, ProtocolInfo> getProtocols() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

package org.apache.guacamole.properties;

import java.util.Collection;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;

/**
* An abstract representation of a property in the guacamole.properties file,
Expand Down Expand Up @@ -49,5 +51,25 @@ public interface GuacamoleProperty<Type> {
* provided value.
*/
public Type parseValue(String value) throws GuacamoleException;

/**
* Parses the given string value into a sorted Collection of values of the
* type associated with this GuacamoelProperty.
*
* @param value
* The string value to parse.
*
* @return
* A sorted Collection of the parsed values.
*
* @throws GuacamoleException
* If an error occurs while parsing the provided value.
*/
default public Collection<Type> parseValueCollection(String value)
throws GuacamoleException {

throw new GuacamoleServerException("Collection parsing not implemented for this property type.");

}

}

0 comments on commit 841194f

Please sign in to comment.