mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 09:03:21 +00:00 
			
		
		
		
	GUACAMOLE-1: Refactor org.glyptodon package/groupId to org.apache.
This commit is contained in:
		| @@ -0,0 +1,154 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.environment; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.util.Map; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.properties.BooleanGuacamoleProperty; | ||||
| import org.apache.guacamole.properties.GuacamoleProperty; | ||||
| import org.apache.guacamole.properties.IntegerGuacamoleProperty; | ||||
| import org.apache.guacamole.properties.StringGuacamoleProperty; | ||||
| import org.apache.guacamole.protocols.ProtocolInfo; | ||||
|  | ||||
| /** | ||||
|  * The environment of an arbitrary Guacamole instance, describing available | ||||
|  * protocols, configuration parameters, and the GUACAMOLE_HOME directory. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface Environment { | ||||
|  | ||||
|     /** | ||||
|      * The hostname of the server where guacd (the Guacamole proxy server) is | ||||
|      * running. | ||||
|      */ | ||||
|     public static final StringGuacamoleProperty GUACD_HOSTNAME = new StringGuacamoleProperty() { | ||||
|  | ||||
|         @Override | ||||
|         public String getName() { return "guacd-hostname"; } | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * The port that guacd (the Guacamole proxy server) is listening on. | ||||
|      */ | ||||
|     public static final IntegerGuacamoleProperty GUACD_PORT = new IntegerGuacamoleProperty() { | ||||
|  | ||||
|         @Override | ||||
|         public String getName() { return "guacd-port"; } | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * Whether guacd requires SSL/TLS on connections. | ||||
|      */ | ||||
|     public static final BooleanGuacamoleProperty GUACD_SSL = new BooleanGuacamoleProperty() { | ||||
|  | ||||
|         @Override | ||||
|         public String getName() { return "guacd-ssl"; } | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * Returns the Guacamole home directory as determined when this Environment | ||||
|      * object was created. The Guacamole home directory is found by checking, in | ||||
|      * order: the guacamole.home system property, the GUACAMOLE_HOME environment | ||||
|      * variable, and finally the .guacamole directory in the home directory of | ||||
|      * the user running the servlet container. | ||||
|      * | ||||
|      * @return The File representing the Guacamole home directory, which may | ||||
|      *         or may not exist, and may turn out to not be a directory. | ||||
|      */ | ||||
|     public File getGuacamoleHome(); | ||||
|  | ||||
|     /** | ||||
|      * Returns a map of all available protocols, where each key is the name of | ||||
|      * that protocol as would be passed to guacd during connection. | ||||
|      * | ||||
|      * @return A map of all available protocols. | ||||
|      */ | ||||
|     public Map<String, ProtocolInfo> getProtocols(); | ||||
|  | ||||
|     /** | ||||
|      * Returns the protocol having the given name. The name must be the | ||||
|      * protocol name as would be passed to guacd during connection. | ||||
|      * | ||||
|      * @param name The name of the protocol. | ||||
|      * @return The protocol having the given name, or null if no such | ||||
|      *         protocol is registered. | ||||
|      */ | ||||
|     public ProtocolInfo getProtocol(String name); | ||||
|  | ||||
|     /** | ||||
|      * 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. | ||||
|      */ | ||||
|     public <Type> Type getProperty(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, 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. | ||||
|      */ | ||||
|     public <Type> Type getProperty(GuacamoleProperty<Type> property, | ||||
|             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 | ||||
|      * is not provided. | ||||
|      * | ||||
|      * @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, or if the property is | ||||
|      *                            not specified. | ||||
|      */ | ||||
|     public <Type> Type getRequiredProperty(GuacamoleProperty<Type> property) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,321 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.environment; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FilenameFilter; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.Properties; | ||||
| import org.codehaus.jackson.map.ObjectMapper; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.GuacamoleServerException; | ||||
| import org.apache.guacamole.properties.GuacamoleProperty; | ||||
| import org.apache.guacamole.protocols.ProtocolInfo; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| /** | ||||
|  * The environment of the locally-running Guacamole instance, describing | ||||
|  * available protocols, configuration parameters, and the GUACAMOLE_HOME | ||||
|  * directory. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class LocalEnvironment implements Environment { | ||||
|  | ||||
|     /** | ||||
|      * Logger for this class. | ||||
|      */ | ||||
|     private static final Logger logger = LoggerFactory.getLogger(LocalEnvironment.class); | ||||
|  | ||||
|     /** | ||||
|      * Array of all known protocol names. | ||||
|      */ | ||||
|     private static final String[] KNOWN_PROTOCOLS = new String[]{ | ||||
|         "vnc", "rdp", "ssh", "telnet"}; | ||||
|  | ||||
|     /** | ||||
|      * All properties read from guacamole.properties. | ||||
|      */ | ||||
|     private final Properties properties; | ||||
|  | ||||
|     /** | ||||
|      * The location of GUACAMOLE_HOME, which may not truly exist. | ||||
|      */ | ||||
|     private final File guacHome; | ||||
|  | ||||
|     /** | ||||
|      * The map of all available protocols. | ||||
|      */ | ||||
|     private final Map<String, ProtocolInfo> availableProtocols; | ||||
|  | ||||
|     /** | ||||
|      * The Jackson parser for parsing JSON files. | ||||
|      */ | ||||
|     private static final ObjectMapper mapper = new ObjectMapper(); | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Environment, initializing that environment based on the | ||||
|      * location of GUACAMOLE_HOME and the contents of guacamole.properties. | ||||
|      *  | ||||
|      * @throws GuacamoleException If an error occurs while determining the | ||||
|      *                            environment of this Guacamole instance. | ||||
|      */ | ||||
|     public LocalEnvironment() throws GuacamoleException { | ||||
|  | ||||
|         // Determine location of GUACAMOLE_HOME | ||||
|         guacHome = findGuacamoleHome(); | ||||
|  | ||||
|         // Read properties | ||||
|         properties = new Properties(); | ||||
|         try { | ||||
|  | ||||
|             InputStream stream = null; | ||||
|  | ||||
|             // If not a directory, load from classpath | ||||
|             if (!guacHome.isDirectory()) | ||||
|                 stream = LocalEnvironment.class.getResourceAsStream("/guacamole.properties"); | ||||
|  | ||||
|             // Otherwise, try to load from file | ||||
|             else { | ||||
|                 File propertiesFile = new File(guacHome, "guacamole.properties"); | ||||
|                 if (propertiesFile.exists()) | ||||
|                     stream = new FileInputStream(propertiesFile); | ||||
|             } | ||||
|  | ||||
|             // Load properties from stream, if any, always closing stream when done | ||||
|             if (stream != null) { | ||||
|                 try { properties.load(stream); } | ||||
|                 finally { stream.close(); } | ||||
|             } | ||||
|  | ||||
|             // Notify if we're proceeding without guacamole.properties | ||||
|             else | ||||
|                 logger.info("No guacamole.properties file found within GUACAMOLE_HOME or the classpath. Using defaults."); | ||||
|  | ||||
|         } | ||||
|         catch (IOException e) { | ||||
|             logger.warn("The guacamole.properties file within GUACAMOLE_HOME cannot be read: {}", e.getMessage()); | ||||
|             logger.debug("Error reading guacamole.properties.", e); | ||||
|         } | ||||
|  | ||||
|         // Read all protocols | ||||
|         availableProtocols = readProtocols(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Locates the Guacamole home directory by checking, in order: | ||||
|      * the guacamole.home system property, the GUACAMOLE_HOME environment | ||||
|      * variable, and finally the .guacamole directory in the home directory of | ||||
|      * the user running the servlet container. | ||||
|      * | ||||
|      * @return The File representing the Guacamole home directory, which may | ||||
|      *         or may not exist, and may turn out to not be a directory. | ||||
|      */ | ||||
|     private static File findGuacamoleHome() { | ||||
|  | ||||
|         // Attempt to find Guacamole home | ||||
|         File guacHome; | ||||
|  | ||||
|         // Use system property by default | ||||
|         String desiredDir = System.getProperty("guacamole.home"); | ||||
|  | ||||
|         // Failing that, try the GUACAMOLE_HOME environment variable | ||||
|         if (desiredDir == null) desiredDir = System.getenv("GUACAMOLE_HOME"); | ||||
|  | ||||
|         // If successful, use explicitly specified directory | ||||
|         if (desiredDir != null) | ||||
|             guacHome = new File(desiredDir); | ||||
|  | ||||
|         // If not explicitly specified, use ~/.guacamole | ||||
|         else | ||||
|             guacHome = new File(System.getProperty("user.home"), ".guacamole"); | ||||
|  | ||||
|         // Return discovered directory | ||||
|         return guacHome; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Parses the given JSON file, returning the parsed ProtocolInfo. The JSON | ||||
|      * format is conveniently and intentionally identical to a serialized | ||||
|      * ProtocolInfo object, which is identical to the JSON format used by the | ||||
|      * protocol REST service built into the Guacamole web application. | ||||
|      * | ||||
|      * @param input | ||||
|      *     An input stream containing JSON describing the forms and parameters | ||||
|      *     associated with a protocol supported by Guacamole. | ||||
|      * | ||||
|      * @return | ||||
|      *     A new ProtocolInfo object which contains the forms and parameters | ||||
|      *     described by the JSON file parsed. | ||||
|      * | ||||
|      * @throws IOException | ||||
|      *     If an error occurs while parsing the JSON file. | ||||
|      */ | ||||
|     private ProtocolInfo readProtocol(InputStream input) | ||||
|             throws IOException { | ||||
|         return mapper.readValue(input, ProtocolInfo.class); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Reads through all pre-defined protocols and any protocols within the | ||||
|      * "protocols" subdirectory of GUACAMOLE_HOME, returning a map containing | ||||
|      * each of these protocols. The key of each entry will be the name of that | ||||
|      * protocol, as would be passed to guacd during connection. | ||||
|      * | ||||
|      * @return | ||||
|      *     A map of all available protocols. | ||||
|      */ | ||||
|     private Map<String, ProtocolInfo> readProtocols() { | ||||
|  | ||||
|         // Map of all available protocols | ||||
|         Map<String, ProtocolInfo> protocols = new HashMap<String, ProtocolInfo>(); | ||||
|  | ||||
|         // Get protcols directory | ||||
|         File protocol_directory = new File(getGuacamoleHome(), "protocols"); | ||||
|  | ||||
|         // Read protocols from directory if it exists | ||||
|         if (protocol_directory.isDirectory()) { | ||||
|  | ||||
|             // Get all JSON files | ||||
|             File[] files = protocol_directory.listFiles( | ||||
|                 new FilenameFilter() { | ||||
|  | ||||
|                     @Override | ||||
|                     public boolean accept(File file, String string) { | ||||
|                         return string.endsWith(".json"); | ||||
|                     } | ||||
|  | ||||
|                 } | ||||
|             ); | ||||
|  | ||||
|             // Warn if directory contents are not available | ||||
|             if (files == null) { | ||||
|                 logger.error("Unable to read contents of \"{}\".", protocol_directory.getAbsolutePath()); | ||||
|                 files = new File[0]; | ||||
|             } | ||||
|              | ||||
|             // Load each protocol from each file | ||||
|             for (File file : files) { | ||||
|  | ||||
|                 try { | ||||
|  | ||||
|                     // Parse protocol | ||||
|                     FileInputStream stream = new FileInputStream(file); | ||||
|                     ProtocolInfo protocol = readProtocol(stream); | ||||
|                     stream.close(); | ||||
|  | ||||
|                     // Store protocol | ||||
|                     protocols.put(protocol.getName(), protocol); | ||||
|  | ||||
|                 } | ||||
|                 catch (IOException e) { | ||||
|                     logger.error("Unable to read connection parameter information from \"{}\": {}", file.getAbsolutePath(), e.getMessage()); | ||||
|                     logger.debug("Error reading protocol JSON.", e); | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|  | ||||
|         } | ||||
|  | ||||
|         // If known protocols are not already defined, read from classpath | ||||
|         for (String protocol : KNOWN_PROTOCOLS) { | ||||
|  | ||||
|             // If protocol not defined yet, attempt to load from classpath | ||||
|             if (!protocols.containsKey(protocol)) { | ||||
|  | ||||
|                 InputStream stream = LocalEnvironment.class.getResourceAsStream( | ||||
|                         "/org/apache/guacamole/protocols/" | ||||
|                         + protocol + ".json"); | ||||
|  | ||||
|                 // Parse JSON if available | ||||
|                 if (stream != null) { | ||||
|                     try { | ||||
|                         protocols.put(protocol, readProtocol(stream)); | ||||
|                     } | ||||
|                     catch (IOException e) { | ||||
|                         logger.error("Unable to read pre-defined connection parameter information for protocol \"{}\": {}", protocol, e.getMessage()); | ||||
|                         logger.debug("Error reading pre-defined protocol JSON.", e); | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|  | ||||
|         } | ||||
|  | ||||
|         // Protocols map now fully populated | ||||
|         return protocols; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public File getGuacamoleHome() { | ||||
|         return guacHome; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public <Type> Type getProperty(GuacamoleProperty<Type> property) throws GuacamoleException { | ||||
|         return property.parseValue(properties.getProperty(property.getName())); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public <Type> Type getProperty(GuacamoleProperty<Type> property, | ||||
|             Type defaultValue) throws GuacamoleException { | ||||
|  | ||||
|         Type value = getProperty(property); | ||||
|         if (value == null) | ||||
|             return defaultValue; | ||||
|  | ||||
|         return value; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public <Type> Type getRequiredProperty(GuacamoleProperty<Type> property) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         Type value = getProperty(property); | ||||
|         if (value == null) | ||||
|             throw new GuacamoleServerException("Property " + property.getName() + " is required."); | ||||
|  | ||||
|         return value; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Map<String, ProtocolInfo> getProtocols() { | ||||
|         return availableProtocols; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ProtocolInfo getProtocol(String name) { | ||||
|         return availableProtocols.get(name); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,53 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| import java.util.Collections; | ||||
|  | ||||
| /** | ||||
|  * Represents a field with strictly one possible value. It is assumed that the | ||||
|  * field may be blank, but that its sole non-blank value is the value provided. | ||||
|  * The provided value represents "true" while all other values, including | ||||
|  * having no associated value, represent "false". | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class BooleanField extends Field { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new BooleanField with the given name and truth value. The | ||||
|      * truth value is the value that, when assigned to this field, means that | ||||
|      * this field is "true". | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param truthValue | ||||
|      *     The value to consider "true" for this field. All other values will | ||||
|      *     be considered "false". | ||||
|      */ | ||||
|     public BooleanField(String name, String truthValue) { | ||||
|         super(name, Field.Type.BOOLEAN, Collections.singletonList(truthValue)); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,97 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| import java.text.DateFormat; | ||||
| import java.text.ParseException; | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | ||||
|  | ||||
| /** | ||||
|  * Represents a date field. The field may contain only date values which | ||||
|  * conform to a standard pattern, defined by DateField.FORMAT. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class DateField extends Field { | ||||
|  | ||||
|     /** | ||||
|      * The date format used by date fields, compatible with SimpleDateFormat. | ||||
|      */ | ||||
|     public static final String FORMAT = "yyyy-MM-dd"; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new DateField with the given name. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      */ | ||||
|     public DateField(String name) { | ||||
|         super(name, Field.Type.DATE); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Converts the given date into a string which follows the format used by | ||||
|      * date fields. | ||||
|      * | ||||
|      * @param date | ||||
|      *     The date value to format, which may be null. | ||||
|      * | ||||
|      * @return | ||||
|      *     The formatted date, or null if the provided time was null. | ||||
|      */ | ||||
|     public static String format(Date date) { | ||||
|         DateFormat dateFormat = new SimpleDateFormat(DateField.FORMAT); | ||||
|         return date == null ? null : dateFormat.format(date); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Parses the given string into a corresponding date. The string must | ||||
|      * follow the standard format used by date fields, as defined by FORMAT | ||||
|      * and as would be produced by format(). | ||||
|      * | ||||
|      * @param dateString | ||||
|      *     The date string to parse, which may be null. | ||||
|      * | ||||
|      * @return | ||||
|      *     The date corresponding to the given date string, or null if the | ||||
|      *     provided date string was null or blank. | ||||
|      * | ||||
|      * @throws ParseException | ||||
|      *     If the given date string does not conform to the standard format | ||||
|      *     used by date fields. | ||||
|      */ | ||||
|     public static Date parse(String dateString) | ||||
|             throws ParseException { | ||||
|  | ||||
|         // Return null if no date provided | ||||
|         if (dateString == null || dateString.isEmpty()) | ||||
|             return null; | ||||
|  | ||||
|         // Parse date according to format | ||||
|         DateFormat dateFormat = new SimpleDateFormat(DateField.FORMAT); | ||||
|         return dateFormat.parse(dateString); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,48 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| import java.util.Collection; | ||||
|  | ||||
| /** | ||||
|  * Represents an arbitrary field with a finite, enumerated set of possible | ||||
|  * values. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class EnumField extends Field { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new EnumField with the given name and possible values. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param options | ||||
|      *     All possible legal options for this field. | ||||
|      */ | ||||
|     public EnumField(String name, Collection<String> options) { | ||||
|         super(name, Field.Type.ENUM, options); | ||||
|     } | ||||
|  | ||||
| } | ||||
							
								
								
									
										222
									
								
								guacamole-ext/src/main/java/org/apache/guacamole/form/Field.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										222
									
								
								guacamole-ext/src/main/java/org/apache/guacamole/form/Field.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,222 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import org.codehaus.jackson.map.annotate.JsonSerialize; | ||||
|  | ||||
| /** | ||||
|  * Represents an arbitrary field, such as an HTTP parameter, the parameter of a | ||||
|  * remote desktop protocol, or an input field within a form. Fields are generic | ||||
|  * and typed dynamically through a type string, with the semantics of the field | ||||
|  * defined by the type string. The behavior of each field type is defined | ||||
|  * either through the web application itself (see FormService.js) or through | ||||
|  * extensions. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) | ||||
| public class Field { | ||||
|  | ||||
|     /** | ||||
|      * All types of fields which are available by default. Additional field | ||||
|      * types may be defined by extensions by using a unique field type name and | ||||
|      * registering that name with the form service within JavaScript. | ||||
|      * | ||||
|      * See FormService.js. | ||||
|      */ | ||||
|     public static class Type { | ||||
|  | ||||
|         /** | ||||
|          * A text field, accepting arbitrary values. | ||||
|          */ | ||||
|         public static String TEXT = "TEXT"; | ||||
|  | ||||
|         /** | ||||
|          * A username field. This field type generally behaves identically to | ||||
|          * arbitrary text fields, but has semantic differences. | ||||
|          */ | ||||
|         public static String USERNAME = "USERNAME"; | ||||
|  | ||||
|         /** | ||||
|          * A password field, whose value is sensitive and must be hidden. | ||||
|          */ | ||||
|         public static String PASSWORD = "PASSWORD"; | ||||
|  | ||||
|         /** | ||||
|          * A numeric field, whose value must contain only digits. | ||||
|          */ | ||||
|         public static String NUMERIC = "NUMERIC"; | ||||
|  | ||||
|         /** | ||||
|          * A boolean field, whose value is either blank or "true". | ||||
|          */ | ||||
|         public static String BOOLEAN = "BOOLEAN"; | ||||
|  | ||||
|         /** | ||||
|          * An enumerated field, whose legal values are fully enumerated by a | ||||
|          * provided, finite list. | ||||
|          */ | ||||
|         public static String ENUM = "ENUM"; | ||||
|  | ||||
|         /** | ||||
|          * A text field that can span more than one line. | ||||
|          */ | ||||
|         public static String MULTILINE = "MULTILINE"; | ||||
|  | ||||
|         /** | ||||
|          * A time zone field whose legal values are only valid time zone IDs, | ||||
|          * as dictated by Java within TimeZone.getAvailableIDs(). | ||||
|          */ | ||||
|         public static String TIMEZONE = "TIMEZONE"; | ||||
|  | ||||
|         /** | ||||
|          * A date field whose legal values conform to the pattern "YYYY-MM-DD", | ||||
|          * zero-padded. | ||||
|          */ | ||||
|         public static String DATE = "DATE"; | ||||
|  | ||||
|         /** | ||||
|          * A time field whose legal values conform to the pattern "HH:MM:SS", | ||||
|          * zero-padded, 24-hour. | ||||
|          */ | ||||
|         public static String TIME = "TIME"; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * The unique name that identifies this field. | ||||
|      */ | ||||
|     private String name; | ||||
|  | ||||
|     /** | ||||
|      * The type of this field. | ||||
|      */ | ||||
|     private String type; | ||||
|  | ||||
|     /** | ||||
|      * A collection of all legal values of this field. | ||||
|      */ | ||||
|     private Collection<String> options; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Parameter with no associated name or type. | ||||
|      */ | ||||
|     public Field() { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Field with the given name  and type. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param type | ||||
|      *     The type of this field. | ||||
|      */ | ||||
|     public Field(String name, String type) { | ||||
|         this.name  = name; | ||||
|         this.type  = type; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Field with the given name, type, and possible values. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param type | ||||
|      *     The type of this field. | ||||
|      * | ||||
|      * @param options | ||||
|      *     A collection of all possible valid options for this field. | ||||
|      */ | ||||
|     public Field(String name, String type, Collection<String> options) { | ||||
|         this.name    = name; | ||||
|         this.type    = type; | ||||
|         this.options = options; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the unique name associated with this field. | ||||
|      * | ||||
|      * @return | ||||
|      *     The unique name associated with this field. | ||||
|      */ | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the unique name associated with this field. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to assign to this field. | ||||
|      */ | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the type of this field. | ||||
|      * | ||||
|      * @return | ||||
|      *     The type of this field. | ||||
|      */ | ||||
|     public String getType() { | ||||
|         return type; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the type of this field. | ||||
|      * | ||||
|      * @param type | ||||
|      *     The type of this field. | ||||
|      */ | ||||
|     public void setType(String type) { | ||||
|         this.type = type; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns a mutable collection of field options. Changes to this | ||||
|      * collection directly affect the available options. | ||||
|      * | ||||
|      * @return | ||||
|      *     A mutable collection of field options, or null if the field has no | ||||
|      *     options. | ||||
|      */ | ||||
|     public Collection<String> getOptions() { | ||||
|         return options; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the options available as possible values of this field. | ||||
|      * | ||||
|      * @param options | ||||
|      *     The options to associate with this field. | ||||
|      */ | ||||
|     public void setOptions(Collection<String> options) { | ||||
|         this.options = options; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,105 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.form; | ||||
|  | ||||
| import org.codehaus.jackson.map.annotate.JsonSerialize; | ||||
|  | ||||
| /** | ||||
|  * Describes an available legal value for an enumerated field. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) | ||||
| public class FieldOption { | ||||
|  | ||||
|     /** | ||||
|      * The value that will be assigned if this option is chosen. | ||||
|      */ | ||||
|     private String value; | ||||
|  | ||||
|     /** | ||||
|      * A human-readable title describing the effect of the value. | ||||
|      */ | ||||
|     private String title; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new FieldOption with no associated value or title. | ||||
|      */ | ||||
|     public FieldOption() { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new FieldOption having the given value and title. | ||||
|      * | ||||
|      * @param value | ||||
|      *     The value to assign if this option is chosen. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this option. | ||||
|      */ | ||||
|     public FieldOption(String value, String title) { | ||||
|         this.value = value; | ||||
|         this.title = title; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the value that will be assigned if this option is chosen. | ||||
|      * | ||||
|      * @return | ||||
|      *     The value that will be assigned if this option is chosen. | ||||
|      */ | ||||
|     public String getValue() { | ||||
|         return value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the value that will be assigned if this option is chosen. | ||||
|      * | ||||
|      * @param value | ||||
|      *     The value to assign if this option is chosen. | ||||
|      */ | ||||
|     public void setValue(String value) { | ||||
|         this.value = value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the human-readable title describing the effect of this option. | ||||
|      * | ||||
|      * @return | ||||
|      *     The human-readable title describing the effect of this option. | ||||
|      */ | ||||
|     public String getTitle() { | ||||
|         return title; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the human-readable title describing the effect of this option. | ||||
|      * | ||||
|      * @param title | ||||
|      *     A human-readable title describing the effect of this option. | ||||
|      */ | ||||
|     public void setTitle(String title) { | ||||
|         this.title = title; | ||||
|     } | ||||
|  | ||||
| } | ||||
							
								
								
									
										114
									
								
								guacamole-ext/src/main/java/org/apache/guacamole/form/Form.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								guacamole-ext/src/main/java/org/apache/guacamole/form/Form.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,114 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import org.codehaus.jackson.map.annotate.JsonSerialize; | ||||
|  | ||||
| /** | ||||
|  * Information which describes logical set of fields. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) | ||||
| public class Form { | ||||
|  | ||||
|     /** | ||||
|      * The name of this form. The form name must identify the form uniquely | ||||
|      * from other forms. | ||||
|      */ | ||||
|     private String name; | ||||
|  | ||||
|     /** | ||||
|      * All fields associated with this form. | ||||
|      */ | ||||
|     private Collection<Field> fields; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Form object with no associated fields. The name is left | ||||
|      * unset as null. If no form name is provided, this form must not be used | ||||
|      * in the same context as another unnamed form. | ||||
|      */ | ||||
|     public Form() { | ||||
|         fields = new ArrayList<Field>(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Form object having the given name and containing the given | ||||
|      * fields. | ||||
|      * | ||||
|      * @param name | ||||
|      *     A name which uniquely identifies this form. | ||||
|      * | ||||
|      * @param fields | ||||
|      *     The fields to provided within the new Form. | ||||
|      */ | ||||
|     public Form(String name, Collection<Field> fields) { | ||||
|         this.name = name; | ||||
|         this.fields = fields; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns a mutable collection of the fields associated with this form. | ||||
|      * Changes to this collection affect the fields exposed to the user. | ||||
|      * | ||||
|      * @return | ||||
|      *     A mutable collection of fields. | ||||
|      */ | ||||
|     public Collection<Field> getFields() { | ||||
|         return fields; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the collection of fields associated with this form. | ||||
|      * | ||||
|      * @param fields | ||||
|      *     The collection of fields to associate with this form. | ||||
|      */ | ||||
|     public void setFields(Collection<Field> fields) { | ||||
|         this.fields = fields; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the name of this form. Form names must uniquely identify each | ||||
|      * form. | ||||
|      * | ||||
|      * @return | ||||
|      *     The name of this form, or null if the form has no name. | ||||
|      */ | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the name of this form. Form names must uniquely identify each form. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The name to assign to this form. | ||||
|      */ | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,42 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| /** | ||||
|  * Represents a field which can contain multiple lines of text. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class MultilineField extends Field { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new MultilineField with the given name. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      */ | ||||
|     public MultilineField(String name) { | ||||
|         super(name, Field.Type.MULTILINE); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,88 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| /** | ||||
|  * Represents a field which may contain only integer values. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class NumericField extends Field { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new NumericField with the given name. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      */ | ||||
|     public NumericField(String name) { | ||||
|         super(name, Field.Type.NUMERIC); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Formats the given integer in the format required by a numeric field. | ||||
|      * | ||||
|      * @param i | ||||
|      *     The integer to format, which may be null. | ||||
|      * | ||||
|      * @return | ||||
|      *     A string representation of the given integer, or null if the given | ||||
|      *     integer was null. | ||||
|      */ | ||||
|     public static String format(Integer i) { | ||||
|  | ||||
|         // Return null if no value provided | ||||
|         if (i == null) | ||||
|             return null; | ||||
|  | ||||
|         // Convert to string | ||||
|         return i.toString(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Parses the given string as an integer, where the given string is in the | ||||
|      * format required by a numeric field. | ||||
|      * | ||||
|      * @param str | ||||
|      *     The string to parse as an integer, which may be null. | ||||
|      * | ||||
|      * @return | ||||
|      *     The integer representation of the given string, or null if the given | ||||
|      *     string was null. | ||||
|      * | ||||
|      * @throws NumberFormatException | ||||
|      *     If the given string is not in a parseable format. | ||||
|      */ | ||||
|     public static Integer parse(String str) throws NumberFormatException { | ||||
|  | ||||
|         // Return null if no value provided | ||||
|         if (str == null || str.isEmpty()) | ||||
|             return null; | ||||
|  | ||||
|         // Parse as integer | ||||
|         return new Integer(str); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,43 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| /** | ||||
|  * Represents a field which contains sensitive text information related to | ||||
|  * authenticating a user. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class PasswordField extends Field { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new PasswordField with the given name. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      */ | ||||
|     public PasswordField(String name) { | ||||
|         super(name, Field.Type.PASSWORD); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,43 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| /** | ||||
|  * Represents a basic text field. The field may generally contain any data, but | ||||
|  * may not contain multiple lines. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class TextField extends Field { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new TextField with the given name. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      */ | ||||
|     public TextField(String name) { | ||||
|         super(name, Field.Type.TEXT); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,97 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| import java.text.DateFormat; | ||||
| import java.text.ParseException; | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | ||||
|  | ||||
| /** | ||||
|  * Represents a time field. The field may contain only time values which | ||||
|  * conform to a standard pattern, defined by TimeField.FORMAT. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class TimeField extends Field { | ||||
|  | ||||
|     /** | ||||
|      * The time format used by time fields, compatible with SimpleDateFormat. | ||||
|      */ | ||||
|     public static final String FORMAT = "HH:mm:ss"; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new TimeField with the given name. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      */ | ||||
|     public TimeField(String name) { | ||||
|         super(name, Field.Type.TIME); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Parses the given string into a corresponding time. The string must | ||||
|      * follow the standard format used by time fields, as defined by | ||||
|      * FORMAT and as would be produced by format(). | ||||
|      * | ||||
|      * @param timeString | ||||
|      *     The time string to parse, which may be null. | ||||
|      * | ||||
|      * @return | ||||
|      *     The time corresponding to the given time string, or null if the | ||||
|      *     provided time string was null or blank. | ||||
|      * | ||||
|      * @throws ParseException | ||||
|      *     If the given time string does not conform to the standard format | ||||
|      *     used by time fields. | ||||
|      */ | ||||
|     public static Date parse(String timeString) | ||||
|             throws ParseException { | ||||
|  | ||||
|         // Return null if no time provided | ||||
|         if (timeString == null || timeString.isEmpty()) | ||||
|             return null; | ||||
|  | ||||
|         // Parse time according to format | ||||
|         DateFormat timeFormat = new SimpleDateFormat(TimeField.FORMAT); | ||||
|         return timeFormat.parse(timeString); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Converts the given time into a string which follows the format used by | ||||
|      * time fields. | ||||
|      * | ||||
|      * @param time | ||||
|      *     The time value to format, which may be null. | ||||
|      * | ||||
|      * @return | ||||
|      *     The formatted time, or null if the provided time was null. | ||||
|      */ | ||||
|     public static String format(Date time) { | ||||
|         DateFormat timeFormat = new SimpleDateFormat(TimeField.FORMAT); | ||||
|         return time == null ? null : timeFormat.format(time); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,66 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| /** | ||||
|  * Represents a time zone field. The field may contain only valid time zone IDs, | ||||
|  * as dictated by TimeZone.getAvailableIDs(). | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class TimeZoneField extends Field { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new TimeZoneField with the given name. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      */ | ||||
|     public TimeZoneField(String name) { | ||||
|         super(name, Field.Type.TIMEZONE); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Parses the given string into a time zone ID string. As these strings are | ||||
|      * equivalent, the only transformation currently performed by this function | ||||
|      * is to ensure that a blank time zone string is parsed into null. | ||||
|      * | ||||
|      * @param timeZone | ||||
|      *     The time zone string to parse, which may be null. | ||||
|      * | ||||
|      * @return | ||||
|      *     The ID of the time zone corresponding to the given string, or null | ||||
|      *     if the given time zone string was null or blank. | ||||
|      */ | ||||
|     public static String parse(String timeZone) { | ||||
|  | ||||
|         // Return null if no time zone provided | ||||
|         if (timeZone == null || timeZone.isEmpty()) | ||||
|             return null; | ||||
|  | ||||
|         // Otherwise, assume time zone is valid | ||||
|         return timeZone; | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,43 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.form; | ||||
|  | ||||
| /** | ||||
|  * Represents a text field which will contain the uniquely-identifying name of | ||||
|  * a user. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class UsernameField extends Field { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new UsernameField with the given name. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      */ | ||||
|     public UsernameField(String name) { | ||||
|         super(name, Field.Type.USERNAME); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,27 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| /** | ||||
|  * Provides classes which describe the contents and semantics of forms which | ||||
|  * may be presented to the user. | ||||
|  */ | ||||
| package org.apache.guacamole.form; | ||||
| @@ -0,0 +1,120 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth; | ||||
|  | ||||
| import java.util.Date; | ||||
| import org.apache.guacamole.net.GuacamoleTunnel; | ||||
|  | ||||
| public abstract class AbstractActiveConnection implements ActiveConnection { | ||||
|  | ||||
|     /** | ||||
|      * The identifier of this active connection. | ||||
|      */ | ||||
|     private String identifier; | ||||
|  | ||||
|     /** | ||||
|      * The identifier of the associated connection. | ||||
|      */ | ||||
|     private String connectionIdentifier; | ||||
|  | ||||
|     /** | ||||
|      * The date and time this active connection began. | ||||
|      */ | ||||
|     private Date startDate; | ||||
|  | ||||
|     /** | ||||
|      * The remote host that initiated this connection. | ||||
|      */ | ||||
|     private String remoteHost; | ||||
|  | ||||
|     /** | ||||
|      * The username of the user that initiated this connection. | ||||
|      */ | ||||
|     private String username; | ||||
|  | ||||
|     /** | ||||
|      * The underlying GuacamoleTunnel. | ||||
|      */ | ||||
|     private GuacamoleTunnel tunnel; | ||||
|  | ||||
|     @Override | ||||
|     public String getIdentifier() { | ||||
|         return identifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setIdentifier(String identifier) { | ||||
|         this.identifier = identifier; | ||||
|     } | ||||
|   | ||||
|     @Override | ||||
|     public String getConnectionIdentifier() { | ||||
|         return connectionIdentifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setConnectionIdentifier(String connnectionIdentifier) { | ||||
|         this.connectionIdentifier = connnectionIdentifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Date getStartDate() { | ||||
|         return startDate; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setStartDate(Date startDate) { | ||||
|         this.startDate = startDate; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getRemoteHost() { | ||||
|         return remoteHost; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setRemoteHost(String remoteHost) { | ||||
|         this.remoteHost = remoteHost; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getUsername() { | ||||
|         return username; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setUsername(String username) { | ||||
|         this.username = username; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public GuacamoleTunnel getTunnel() { | ||||
|         return tunnel; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setTunnel(GuacamoleTunnel tunnel) { | ||||
|         this.tunnel = tunnel; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,73 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Basic implementation of an AuthenticatedUser which uses the username to | ||||
|  * determine equality. Username comparison is case-sensitive. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public abstract class AbstractAuthenticatedUser implements AuthenticatedUser { | ||||
|  | ||||
|     /** | ||||
|      * The name of this user. | ||||
|      */ | ||||
|     private String username; | ||||
|  | ||||
|     @Override | ||||
|     public String getIdentifier() { | ||||
|         return username; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setIdentifier(String username) { | ||||
|         this.username = username; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int hashCode() { | ||||
|         if (username == null) return 0; | ||||
|         return username.hashCode(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean equals(Object obj) { | ||||
|  | ||||
|         // Not equal if null or not a User | ||||
|         if (obj == null) return false; | ||||
|         if (!(obj instanceof AbstractAuthenticatedUser)) return false; | ||||
|  | ||||
|         // Get username | ||||
|         String objUsername = ((AbstractAuthenticatedUser) obj).username; | ||||
|  | ||||
|         // If null, equal only if this username is null | ||||
|         if (objUsername == null) return username == null; | ||||
|  | ||||
|         // Otherwise, equal only if strings are identical | ||||
|         return objUsername.equals(username); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,119 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| import org.apache.guacamole.protocol.GuacamoleConfiguration; | ||||
|  | ||||
| /** | ||||
|  * Basic implementation of a Guacamole connection. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public abstract class AbstractConnection implements Connection { | ||||
|  | ||||
|     /** | ||||
|      * The name associated with this connection. | ||||
|      */ | ||||
|     private String name; | ||||
|  | ||||
|     /** | ||||
|      * The unique identifier associated with this connection. | ||||
|      */ | ||||
|     private String identifier; | ||||
|  | ||||
|     /** | ||||
|      * The unique identifier of the parent ConnectionGroup for | ||||
|      * this Connection. | ||||
|      */ | ||||
|     private String parentIdentifier; | ||||
|  | ||||
|     /** | ||||
|      * The GuacamoleConfiguration associated with this connection. | ||||
|      */ | ||||
|     private GuacamoleConfiguration configuration; | ||||
|  | ||||
|     @Override | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getIdentifier() { | ||||
|         return identifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setIdentifier(String identifier) { | ||||
|         this.identifier = identifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getParentIdentifier() { | ||||
|         return parentIdentifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setParentIdentifier(String parentIdentifier) { | ||||
|         this.parentIdentifier = parentIdentifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public GuacamoleConfiguration getConfiguration() { | ||||
|         return configuration; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setConfiguration(GuacamoleConfiguration configuration) { | ||||
|         this.configuration = configuration; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int hashCode() { | ||||
|         if (identifier == null) return 0; | ||||
|         return identifier.hashCode(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean equals(Object obj) { | ||||
|  | ||||
|         // Not equal if null or not a Connection | ||||
|         if (obj == null) return false; | ||||
|         if (!(obj instanceof AbstractConnection)) return false; | ||||
|  | ||||
|         // Get identifier | ||||
|         String objIdentifier = ((AbstractConnection) obj).identifier; | ||||
|  | ||||
|         // If null, equal only if this identifier is null | ||||
|         if (objIdentifier == null) return identifier == null; | ||||
|  | ||||
|         // Otherwise, equal only if strings are identical | ||||
|         return objIdentifier.equals(identifier); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,117 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| /** | ||||
|  * Basic implementation of a Guacamole connection group. | ||||
|  * | ||||
|  * @author James Muehlner | ||||
|  */ | ||||
| public abstract class AbstractConnectionGroup implements ConnectionGroup { | ||||
|  | ||||
|     /** | ||||
|      * The name associated with this connection group. | ||||
|      */ | ||||
|     private String name; | ||||
|  | ||||
|     /** | ||||
|      * The unique identifier associated with this connection group. | ||||
|      */ | ||||
|     private String identifier; | ||||
|  | ||||
|     /** | ||||
|      * The unique identifier of the parent connection group for | ||||
|      * this connection group. | ||||
|      */ | ||||
|     private String parentIdentifier; | ||||
|      | ||||
|     /** | ||||
|      * The type of this connection group. | ||||
|      */ | ||||
|     private ConnectionGroup.Type type; | ||||
|      | ||||
|     @Override | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getIdentifier() { | ||||
|         return identifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setIdentifier(String identifier) { | ||||
|         this.identifier = identifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getParentIdentifier() { | ||||
|         return parentIdentifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setParentIdentifier(String parentIdentifier) { | ||||
|         this.parentIdentifier = parentIdentifier; | ||||
|     } | ||||
|      | ||||
|     @Override | ||||
|     public ConnectionGroup.Type getType() { | ||||
|         return type; | ||||
|     } | ||||
|      | ||||
|     @Override | ||||
|     public void setType(ConnectionGroup.Type type) { | ||||
|         this.type = type; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int hashCode() { | ||||
|         if (identifier == null) return 0; | ||||
|         return identifier.hashCode(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean equals(Object obj) { | ||||
|  | ||||
|         // Not equal if null or not a ConnectionGroup | ||||
|         if (obj == null) return false; | ||||
|         if (!(obj instanceof AbstractConnectionGroup)) return false; | ||||
|  | ||||
|         // Get identifier | ||||
|         String objIdentifier = ((AbstractConnectionGroup) obj).identifier; | ||||
|  | ||||
|         // If null, equal only if this identifier is null | ||||
|         if (objIdentifier == null) return identifier == null; | ||||
|  | ||||
|         // Otherwise, equal only if strings are identical | ||||
|         return objIdentifier.equals(identifier); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,90 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Basic implementation of a Guacamole user which uses the username to | ||||
|  * determine equality. Username comparison is case-sensitive. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public abstract class AbstractUser implements User { | ||||
|  | ||||
|     /** | ||||
|      * The name of this user. | ||||
|      */ | ||||
|     private String username; | ||||
|  | ||||
|     /** | ||||
|      * This user's password. Note that while this provides a means for the | ||||
|      * password to be set, the data stored in this String is not necessarily | ||||
|      * the user's actual password. It may be hashed, it may be arbitrary. | ||||
|      */ | ||||
|     private String password; | ||||
|  | ||||
|     @Override | ||||
|     public String getIdentifier() { | ||||
|         return username; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setIdentifier(String username) { | ||||
|         this.username = username; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getPassword() { | ||||
|         return password; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setPassword(String password) { | ||||
|         this.password = password; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int hashCode() { | ||||
|         if (username == null) return 0; | ||||
|         return username.hashCode(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean equals(Object obj) { | ||||
|  | ||||
|         // Not equal if null or not a User | ||||
|         if (obj == null) return false; | ||||
|         if (!(obj instanceof AbstractUser)) return false; | ||||
|  | ||||
|         // Get username | ||||
|         String objUsername = ((AbstractUser) obj).username; | ||||
|  | ||||
|         // If null, equal only if this username is null | ||||
|         if (objUsername == null) return username == null; | ||||
|  | ||||
|         // Otherwise, equal only if strings are identical | ||||
|         return objUsername.equals(username); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,128 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth; | ||||
|  | ||||
| import java.util.Date; | ||||
| import org.apache.guacamole.net.GuacamoleTunnel; | ||||
|  | ||||
| /** | ||||
|  * A pairing of username and GuacamoleTunnel representing an active usage of a | ||||
|  * particular connection. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface ActiveConnection extends Identifiable { | ||||
|  | ||||
|     /** | ||||
|      * Returns the identifier of the connection being actively used. Unlike the | ||||
|      * other information stored in this object, the connection identifier must | ||||
|      * be present and MAY NOT be null. | ||||
|      * | ||||
|      * @return | ||||
|      *     The identifier of the connection being actively used. | ||||
|      */ | ||||
|     String getConnectionIdentifier(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the identifier of the connection being actively used. | ||||
|      * | ||||
|      * @param connnectionIdentifier | ||||
|      *     The identifier of the connection being actively used. | ||||
|      */ | ||||
|     void setConnectionIdentifier(String connnectionIdentifier); | ||||
|      | ||||
|     /** | ||||
|      * Returns the date and time the connection began. | ||||
|      * | ||||
|      * @return | ||||
|      *     The date and time the connection began, or null if this | ||||
|      *     information is not available. | ||||
|      */ | ||||
|     Date getStartDate(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the date and time the connection began. | ||||
|      * | ||||
|      * @param startDate  | ||||
|      *     The date and time the connection began, or null if this | ||||
|      *     information is not available. | ||||
|      */ | ||||
|     void setStartDate(Date startDate); | ||||
|  | ||||
|     /** | ||||
|      * Returns the hostname or IP address of the remote host that initiated the | ||||
|      * connection, if known. If the hostname or IP address is not known, null | ||||
|      * is returned. | ||||
|      * | ||||
|      * @return | ||||
|      *     The hostname or IP address of the remote host, or null if this | ||||
|      *     information is not available. | ||||
|      */ | ||||
|     String getRemoteHost(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the hostname or IP address of the remote host that initiated the | ||||
|      * connection. | ||||
|      *  | ||||
|      * @param remoteHost  | ||||
|      *     The hostname or IP address of the remote host, or null if this | ||||
|      *     information is not available. | ||||
|      */ | ||||
|     void setRemoteHost(String remoteHost); | ||||
|  | ||||
|     /** | ||||
|      * Returns the name of the user who is using this connection. | ||||
|      * | ||||
|      * @return | ||||
|      *     The name of the user who is using this connection, or null if this | ||||
|      *     information is not available. | ||||
|      */ | ||||
|     String getUsername(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the name of the user who is using this connection. | ||||
|      * | ||||
|      * @param username  | ||||
|      *     The name of the user who is using this connection, or null if this | ||||
|      *     information is not available. | ||||
|      */ | ||||
|     void setUsername(String username); | ||||
|  | ||||
|     /** | ||||
|      * Returns the connected GuacamoleTunnel being used. This may be null if | ||||
|      * access to the underlying tunnel is denied. | ||||
|      * | ||||
|      * @return | ||||
|      *     The connected GuacamoleTunnel, or null if permission is denied. | ||||
|      */ | ||||
|     GuacamoleTunnel getTunnel(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the connected GuacamoleTunnel being used. | ||||
|      * | ||||
|      * @param tunnel | ||||
|      *     The connected GuacamoleTunnel, or null if permission is denied. | ||||
|      */ | ||||
|     void setTunnel(GuacamoleTunnel tunnel); | ||||
|      | ||||
| } | ||||
| @@ -0,0 +1,51 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * A user of the Guacamole web application who has been authenticated by an | ||||
|  * AuthenticationProvider. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface AuthenticatedUser extends Identifiable { | ||||
|  | ||||
|     /** | ||||
|      * Returns the AuthenticationProvider that authenticated this user. | ||||
|      * | ||||
|      * @return | ||||
|      *     The AuthenticationProvider that authenticated this user. | ||||
|      */ | ||||
|     AuthenticationProvider getAuthenticationProvider(); | ||||
|  | ||||
|     /** | ||||
|      * Returns the credentials that the user provided when they successfully | ||||
|      * authenticated. | ||||
|      * | ||||
|      * @return | ||||
|      *     The credentials provided by the user when they authenticated. | ||||
|      */ | ||||
|     Credentials getCredentials(); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,148 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
|  | ||||
| /** | ||||
|  * Provides means of authorizing users and for accessing and managing data | ||||
|  * associated with those users. Access to such data is limited according to the | ||||
|  * AuthenticationProvider implementation. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface AuthenticationProvider { | ||||
|  | ||||
|     /** | ||||
|      * Returns the identifier which uniquely and consistently identifies this | ||||
|      * AuthenticationProvider implementation. This identifier may not be null | ||||
|      * and must be unique across all AuthenticationProviders loaded by the | ||||
|      * Guacamole web application. | ||||
|      * | ||||
|      * @return | ||||
|      *     The unique identifier assigned to this AuthenticationProvider, which | ||||
|      *     may not be null. | ||||
|      */ | ||||
|     String getIdentifier(); | ||||
|  | ||||
|     /** | ||||
|      * Returns an AuthenticatedUser representing the user authenticated by the | ||||
|      * given credentials, if any. | ||||
|      * | ||||
|      * @param credentials | ||||
|      *     The credentials to use for authentication. | ||||
|      * | ||||
|      * @return | ||||
|      *     An AuthenticatedUser representing the user authenticated by the | ||||
|      *     given credentials, if any, or null if the credentials are invalid. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while authenticating the user, or if access is | ||||
|      *     temporarily, permanently, or conditionally denied, such as if the | ||||
|      *     supplied credentials are insufficient or invalid. | ||||
|      */ | ||||
|     AuthenticatedUser authenticateUser(Credentials credentials) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns a new or updated AuthenticatedUser for the given credentials | ||||
|      * already having produced the given AuthenticatedUser. Note that because | ||||
|      * this function will be called for all future requests after initial | ||||
|      * authentication, including tunnel requests, care must be taken to avoid | ||||
|      * using functions of HttpServletRequest which invalidate the entire request | ||||
|      * body, such as getParameter(). Doing otherwise may cause the | ||||
|      * GuacamoleHTTPTunnelServlet to fail. | ||||
|       * | ||||
|      * @param credentials | ||||
|      *     The credentials to use for authentication. | ||||
|      * | ||||
|      * @param authenticatedUser | ||||
|      *     An AuthenticatedUser object representing the user authenticated by | ||||
|      *     an arbitrary set of credentials. The AuthenticatedUser may come from | ||||
|      *     this AuthenticationProvider or any other installed | ||||
|      *     AuthenticationProvider. | ||||
|      * | ||||
|      * @return | ||||
|      *     An updated AuthenticatedUser representing the user authenticated by | ||||
|      *     the given credentials, if any, or null if the credentials are | ||||
|      *     invalid. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while updating the AuthenticatedUser. | ||||
|      */ | ||||
|     AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser authenticatedUser, | ||||
|             Credentials credentials) throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns the UserContext of the user authenticated by the given | ||||
|      * credentials. | ||||
|      * | ||||
|      * @param authenticatedUser | ||||
|      *     An AuthenticatedUser object representing the user authenticated by | ||||
|      *     an arbitrary set of credentials. The AuthenticatedUser may come from | ||||
|      *     this AuthenticationProvider or any other installed | ||||
|      *     AuthenticationProvider. | ||||
|      * | ||||
|      * @return | ||||
|      *     A UserContext describing the permissions, connection, connection | ||||
|      *     groups, etc. accessible or associated with the given authenticated | ||||
|      *     user, or null if this AuthenticationProvider refuses to provide any | ||||
|      *     such data. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while creating the UserContext. | ||||
|      */ | ||||
|     UserContext getUserContext(AuthenticatedUser authenticatedUser) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns a new or updated UserContext for the given AuthenticatedUser | ||||
|      * already having the given UserContext. Note that because this function | ||||
|      * will be called for all future requests after initial authentication, | ||||
|      * including tunnel requests, care must be taken to avoid using functions | ||||
|      * of HttpServletRequest which invalidate the entire request body, such as | ||||
|      * getParameter(). Doing otherwise may cause the GuacamoleHTTPTunnelServlet | ||||
|      * to fail. | ||||
|       * | ||||
|      * @param context | ||||
|      *     The existing UserContext belonging to the user in question. | ||||
|      * | ||||
|      * @param authenticatedUser | ||||
|      *     An AuthenticatedUser object representing the user authenticated by | ||||
|      *     an arbitrary set of credentials. The AuthenticatedUser may come from | ||||
|      *     this AuthenticationProvider or any other installed | ||||
|      *     AuthenticationProvider. | ||||
|      * | ||||
|      * @return | ||||
|      *     An updated UserContext describing the permissions, connection, | ||||
|      *     connection groups, etc. accessible or associated with the given | ||||
|      *     authenticated user, or null if this AuthenticationProvider refuses | ||||
|      *     to provide any such data. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while updating the UserContext. | ||||
|      */ | ||||
|     UserContext updateUserContext(UserContext context, | ||||
|             AuthenticatedUser authenticatedUser) throws GuacamoleException; | ||||
|      | ||||
| } | ||||
| @@ -0,0 +1,63 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.net.GuacamoleTunnel; | ||||
| import org.apache.guacamole.protocol.GuacamoleClientInformation; | ||||
|  | ||||
| /** | ||||
|  * An object which Guacamole can connect to. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface Connectable { | ||||
|  | ||||
|     /** | ||||
|      * Establishes a connection to guacd using the information associated with | ||||
|      * this object. The connection will be provided the given client | ||||
|      * information. | ||||
|      * | ||||
|      * @param info | ||||
|      *     Information associated with the connecting client. | ||||
|      * | ||||
|      * @return | ||||
|      *     A fully-established GuacamoleTunnel. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while connecting to guacd, or if permission to | ||||
|      *     connect is denied. | ||||
|      */ | ||||
|     public GuacamoleTunnel connect(GuacamoleClientInformation info) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns the number of active connections associated with this object. | ||||
|      * Implementations may simply return 0 if this value is not tracked. | ||||
|      * | ||||
|      * @return | ||||
|      *     The number of active connections associated with this object. | ||||
|      */ | ||||
|     public int getActiveConnections(); | ||||
|      | ||||
| } | ||||
| @@ -0,0 +1,125 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.protocol.GuacamoleConfiguration; | ||||
|  | ||||
| /** | ||||
|  * Represents a pairing of a GuacamoleConfiguration with a unique, | ||||
|  * human-readable identifier, and abstracts the connection process. The | ||||
|  * backing GuacamoleConfiguration may be intentionally obfuscated or tokenized | ||||
|  * to protect sensitive configuration information. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface Connection extends Identifiable, Connectable { | ||||
|  | ||||
|     /** | ||||
|      * Returns the name assigned to this Connection. | ||||
|      * @return The name assigned to this Connection. | ||||
|      */ | ||||
|     public String getName(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the name assigned to this Connection. | ||||
|      * | ||||
|      * @param name The name to assign. | ||||
|      */ | ||||
|     public void setName(String name); | ||||
|  | ||||
|     /** | ||||
|      * Returns the unique identifier of the parent ConnectionGroup for | ||||
|      * this Connection. | ||||
|      *  | ||||
|      * @return The unique identifier of the parent ConnectionGroup for | ||||
|      * this Connection. | ||||
|      */ | ||||
|     public String getParentIdentifier(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the unique identifier of the parent ConnectionGroup for | ||||
|      * this Connection. | ||||
|      *  | ||||
|      * @param parentIdentifier The unique identifier of the parent  | ||||
|      * ConnectionGroup for this Connection. | ||||
|      */ | ||||
|     public void setParentIdentifier(String parentIdentifier); | ||||
|  | ||||
|     /** | ||||
|      * Returns the GuacamoleConfiguration associated with this Connection. Note | ||||
|      * that because configurations may contain sensitive information, some data | ||||
|      * in this configuration may be omitted or tokenized. | ||||
|      * | ||||
|      * @return The GuacamoleConfiguration associated with this Connection. | ||||
|      */ | ||||
|     public GuacamoleConfiguration getConfiguration(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the GuacamoleConfiguration associated with this Connection. | ||||
|      * | ||||
|      * @param config The GuacamoleConfiguration to associate with this | ||||
|      *               Connection. | ||||
|      */ | ||||
|     public void setConfiguration(GuacamoleConfiguration config); | ||||
|  | ||||
|     /** | ||||
|      * Returns all attributes associated with this connection. The returned map | ||||
|      * may not be modifiable. | ||||
|      * | ||||
|      * @return | ||||
|      *     A map of all attribute identifiers to their corresponding values, | ||||
|      *     for all attributes associated with this connection, which may not be | ||||
|      *     modifiable. | ||||
|      */ | ||||
|     Map<String, String> getAttributes(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the given attributes. If an attribute within the map is not | ||||
|      * supported, it will simply be dropped. Any attributes not within the | ||||
|      * given map will be left untouched. | ||||
|      * | ||||
|      * @param attributes | ||||
|      *     A map of all attribute identifiers to their corresponding values. | ||||
|      */ | ||||
|     void setAttributes(Map<String, String> attributes); | ||||
|  | ||||
|     /** | ||||
|      * Returns a list of ConnectionRecords representing the usage history | ||||
|      * of this Connection, including any active users. ConnectionRecords | ||||
|      * in this list will be sorted in descending order of end time (active | ||||
|      * connections are first), and then in descending order of start time | ||||
|      * (newer connections are first). | ||||
|      * | ||||
|      * @return A list of ConnectionRecrods representing the usage history | ||||
|      *         of this Connection. | ||||
|      * | ||||
|      * @throws GuacamoleException If an error occurs while reading the history | ||||
|      *                            of this connection, or if permission is | ||||
|      *                            denied. | ||||
|      */ | ||||
|     public List<? extends ConnectionRecord> getHistory() throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,153 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| import java.util.Map; | ||||
| import java.util.Set; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
|  | ||||
| /** | ||||
|  * Represents a connection group, which can contain both other connection groups | ||||
|  * as well as connections. | ||||
|  * | ||||
|  * @author James Muehlner | ||||
|  */ | ||||
| public interface ConnectionGroup extends Identifiable, Connectable { | ||||
|    | ||||
|     /** | ||||
|      * All legal types of connection group. | ||||
|      */ | ||||
|     public enum Type { | ||||
|  | ||||
|         /** | ||||
|          * A connection group that purely organizes other connections or | ||||
|          * connection groups, serving only as a container. An organizational | ||||
|          * connection group is analogous to a directory or folder in a | ||||
|          * filesystem. | ||||
|          */ | ||||
|         ORGANIZATIONAL, | ||||
|  | ||||
|         /** | ||||
|          * A connection group that acts as a load balancer. A balancing | ||||
|          * connection group can be connected to in the same manner as a | ||||
|          * connection, and will transparently route to the least-used | ||||
|          * underlying connection. | ||||
|          */ | ||||
|         BALANCING | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * Returns the name assigned to this ConnectionGroup. | ||||
|      * @return The name assigned to this ConnectionGroup. | ||||
|      */ | ||||
|     public String getName(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the name assigned to this ConnectionGroup. | ||||
|      * | ||||
|      * @param name The name to assign. | ||||
|      */ | ||||
|     public void setName(String name); | ||||
|  | ||||
|     /** | ||||
|      * Returns the unique identifier of the parent ConnectionGroup for | ||||
|      * this ConnectionGroup. | ||||
|      *  | ||||
|      * @return The unique identifier of the parent ConnectionGroup for | ||||
|      * this ConnectionGroup. | ||||
|      */ | ||||
|     public String getParentIdentifier(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the unique identifier of the parent ConnectionGroup for | ||||
|      * this ConnectionGroup. | ||||
|      *  | ||||
|      * @param parentIdentifier The unique identifier of the parent  | ||||
|      * ConnectionGroup for this ConnectionGroup. | ||||
|      */ | ||||
|     public void setParentIdentifier(String parentIdentifier); | ||||
|      | ||||
|     /** | ||||
|      * Set the type of this ConnectionGroup. | ||||
|      * | ||||
|      * @param type The type of this ConnectionGroup. | ||||
|      */ | ||||
|     public void setType(Type type); | ||||
|      | ||||
|     /** | ||||
|      * Returns the type of this connection. | ||||
|      * @return the type of this connection. | ||||
|      */ | ||||
|     public Type getType(); | ||||
|  | ||||
|     /** | ||||
|      * Returns the identifiers of all readable connections that are children | ||||
|      * of this connection group. | ||||
|      * | ||||
|      * @return | ||||
|      *     The set of identifiers of all readable connections that are children | ||||
|      *     of this connection group. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving the identifiers. | ||||
|      */ | ||||
|     public Set<String> getConnectionIdentifiers() throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns the identifiers of all readable connection groups that are | ||||
|      * children of this connection group. | ||||
|      * | ||||
|      * @return | ||||
|      *     The set of identifiers of all readable connection groups that are | ||||
|      *     children of this connection group. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving the identifiers. | ||||
|      */ | ||||
|  | ||||
|     public Set<String> getConnectionGroupIdentifiers() | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns all attributes associated with this connection group. The | ||||
|      * returned map may not be modifiable. | ||||
|      * | ||||
|      * @return | ||||
|      *     A map of all attribute identifiers to their corresponding values, | ||||
|      *     for all attributes associated with this connection group, which may | ||||
|      *     not be modifiable. | ||||
|      */ | ||||
|     Map<String, String> getAttributes(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the given attributes. If an attribute within the map is not | ||||
|      * supported, it will simply be dropped. Any attributes not within the | ||||
|      * given map will be left untouched. | ||||
|      * | ||||
|      * @param attributes | ||||
|      *     A map of all attribute identifiers to their corresponding values. | ||||
|      */ | ||||
|     void setAttributes(Map<String, String> attributes); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,98 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| import java.util.Date; | ||||
|  | ||||
| /** | ||||
|  * A logging record describing when a user started and ended usage of a | ||||
|  * particular connection. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface ConnectionRecord { | ||||
|  | ||||
|     /** | ||||
|      * Returns the identifier of the connection associated with this | ||||
|      * connection record. | ||||
|      * | ||||
|      * @return | ||||
|      *     The identifier of the connection associated with this connection | ||||
|      *     record. | ||||
|      */ | ||||
|     public String getConnectionIdentifier(); | ||||
|      | ||||
|     /** | ||||
|      * Returns the name of the connection associated with this connection | ||||
|      * record. | ||||
|      * | ||||
|      * @return | ||||
|      *     The name of the connection associated with this connection record. | ||||
|      */ | ||||
|     public String getConnectionName(); | ||||
|  | ||||
|     /** | ||||
|      * Returns the date and time the connection began. | ||||
|      * | ||||
|      * @return The date and time the connection began. | ||||
|      */ | ||||
|     public Date getStartDate(); | ||||
|  | ||||
|     /** | ||||
|      * Returns the date and time the connection ended, if applicable. | ||||
|      * | ||||
|      * @return The date and time the connection ended, or null if the | ||||
|      *         connection is still running or if the end time is unknown. | ||||
|      */ | ||||
|     public Date getEndDate(); | ||||
|  | ||||
|     /** | ||||
|      * Returns the hostname or IP address of the remote host that used the | ||||
|      * connection associated with this record, if known. If the hostname or IP | ||||
|      * address is not known, null is returned. | ||||
|      * | ||||
|      * @return | ||||
|      *     The hostname or IP address of the remote host, or null if this | ||||
|      *     information is not available. | ||||
|      */ | ||||
|     public String getRemoteHost(); | ||||
|  | ||||
|     /** | ||||
|      * Returns the name of the user who used or is using the connection at the | ||||
|      * times given by this connection record. | ||||
|      * | ||||
|      * @return The name of the user who used or is using the associated | ||||
|      *         connection. | ||||
|      */ | ||||
|     public String getUsername(); | ||||
|  | ||||
|     /** | ||||
|      * Returns whether the connection associated with this record is still | ||||
|      * active. | ||||
|      * | ||||
|      * @return true if the connection associated with this record is still | ||||
|      *         active, false otherwise. | ||||
|      */ | ||||
|     public boolean isActive(); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,131 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
|  | ||||
| /** | ||||
|  * The set of all available connection records, or a subset of those records. | ||||
|  * | ||||
|  * @author James Muehlner | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface ConnectionRecordSet { | ||||
|  | ||||
|     /** | ||||
|      * All properties of connection records which can be used as sorting | ||||
|      * criteria. | ||||
|      */ | ||||
|     enum SortableProperty { | ||||
|  | ||||
|         /** | ||||
|          * The date and time when the connection associated with the | ||||
|          * connection record began. | ||||
|          */ | ||||
|         START_DATE | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * Returns all connection records within this set as a standard Collection. | ||||
|      * | ||||
|      * @return | ||||
|      *      A collection containing all connection records within this set. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *      If an error occurs while retrieving the connection records within | ||||
|      *      this set. | ||||
|      */ | ||||
|     Collection<ConnectionRecord> asCollection() throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns the subset of connection records to only those where the | ||||
|      * connection name, user identifier, or any associated date field contain | ||||
|      * the given value. This function may also affect the contents of the | ||||
|      * current ConnectionRecordSet. The contents of the current | ||||
|      * ConnectionRecordSet should NOT be relied upon after this function is | ||||
|      * called. | ||||
|      * | ||||
|      * @param value | ||||
|      *     The value which all connection records within the resulting subset | ||||
|      *     should contain within their associated connection name or user | ||||
|      *     identifier. | ||||
|      * | ||||
|      * @return | ||||
|      *     The subset of connection history records which contain the specified | ||||
|      *     value within their associated connection name or user identifier. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while restricting the current subset. | ||||
|      */ | ||||
|     ConnectionRecordSet contains(String value) throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns the subset of connection history records containing only the | ||||
|      * first <code>limit</code> records. If the subset has fewer than | ||||
|      * <code>limit</code> records, then this function has no effect. This | ||||
|      * function may also affect the contents of the current | ||||
|      * ConnectionRecordSet. The contents of the current ConnectionRecordSet | ||||
|      * should NOT be relied upon after this function is called. | ||||
|      * | ||||
|      * @param limit | ||||
|      *     The maximum number of records that the new subset should contain. | ||||
|      * | ||||
|      * @return | ||||
|      *     The subset of connection history records that containing only the | ||||
|      *     first <code>limit</code> records. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while limiting the current subset. | ||||
|      */ | ||||
|     ConnectionRecordSet limit(int limit) throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns a ConnectionRecordSet containing identically the records within | ||||
|      * this set, sorted according to the specified criteria. The sort operation | ||||
|      * performed is guaranteed to be stable with respect to any past call to | ||||
|      * sort(). This function may also affect the contents of the current | ||||
|      * ConnectionRecordSet. The contents of the current ConnectionRecordSet | ||||
|      * should NOT be relied upon after this function is called. | ||||
|      * | ||||
|      * @param property | ||||
|      *     The property by which the connection records within the resulting | ||||
|      *     set should be sorted. | ||||
|      * | ||||
|      * @param desc | ||||
|      *     Whether the records should be sorted according to the specified | ||||
|      *     property in descending order. If false, records will be sorted | ||||
|      *     according to the specified property in ascending order. | ||||
|      * | ||||
|      * @return | ||||
|      *     The ConnnectionRecordSet, sorted according to the specified | ||||
|      *     criteria. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while sorting the current subset. | ||||
|      */ | ||||
|     ConnectionRecordSet sort(SortableProperty property, boolean desc) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,139 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| import java.io.Serializable; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpSession; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Simple arbitrary set of credentials, including a username/password pair, | ||||
|  * the HttpServletRequest associated with the request for authorization | ||||
|  * (if any) and the HttpSession associated with that request. | ||||
|  * | ||||
|  * This class is used along with AuthenticationProvider to provide arbitrary | ||||
|  * HTTP-based authentication for Guacamole. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class Credentials implements Serializable { | ||||
|  | ||||
|     /** | ||||
|      * Unique identifier associated with this specific version of Credentials. | ||||
|      */ | ||||
|     private static final long serialVersionUID = 1L; | ||||
|  | ||||
|     /** | ||||
|      * An arbitrary username. | ||||
|      */ | ||||
|     private String username; | ||||
|  | ||||
|     /** | ||||
|      * An arbitrary password. | ||||
|      */ | ||||
|     private String password; | ||||
|  | ||||
|     /** | ||||
|      * The HttpServletRequest carrying additional credentials, if any. | ||||
|      */ | ||||
|     private transient HttpServletRequest request; | ||||
|  | ||||
|     /** | ||||
|      * The HttpSession carrying additional credentials, if any. | ||||
|      */ | ||||
|     private transient HttpSession session; | ||||
|  | ||||
|     /** | ||||
|      * Returns the password associated with this set of credentials. | ||||
|      * @return The password associated with this username/password pair, or | ||||
|      *         null if no password has been set. | ||||
|      */ | ||||
|     public String getPassword() { | ||||
|         return password; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the password associated with this set of credentials. | ||||
|      * @param password The password to associate with this username/password | ||||
|      *                 pair. | ||||
|      */ | ||||
|     public void setPassword(String password) { | ||||
|         this.password = password; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the username associated with this set of credentials. | ||||
|      * @return The username associated with this username/password pair, or | ||||
|      *         null if no username has been set. | ||||
|      */ | ||||
|     public String getUsername() { | ||||
|         return username; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the username associated with this set of credentials. | ||||
|      * @param username The username to associate with this username/password | ||||
|      *                 pair. | ||||
|      */ | ||||
|     public void setUsername(String username) { | ||||
|         this.username = username; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the HttpServletRequest associated with this set of credentials. | ||||
|      * @return The HttpServletRequest associated with this set of credentials, | ||||
|      *         or null if no such request exists. | ||||
|      */ | ||||
|     public HttpServletRequest getRequest() { | ||||
|         return request; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the HttpServletRequest associated with this set of credentials. | ||||
|      * @param request  The HttpServletRequest to associated with this set of | ||||
|      *                 credentials. | ||||
|      */ | ||||
|     public void setRequest(HttpServletRequest request) { | ||||
|         this.request = request; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the HttpSession associated with this set of credentials. | ||||
|      * @return The HttpSession associated with this set of credentials, or null | ||||
|      *         if no such request exists. | ||||
|      */ | ||||
|     public HttpSession getSession() { | ||||
|         return session; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the HttpSession associated with this set of credentials. | ||||
|      * @param session The HttpSession to associated with this set of | ||||
|      *                credentials. | ||||
|      */ | ||||
|     public void setSession(HttpSession session) { | ||||
|         this.session = session; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,128 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.Set; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
|  | ||||
| /** | ||||
|  * Provides access to a collection of all objects with associated identifiers, | ||||
|  * and allows user manipulation and removal. Objects returned by a Directory | ||||
|  * are not necessarily backed by the stored objects, thus updating an object | ||||
|  * always requires calling the update() function. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  * @param <ObjectType> | ||||
|  *     The type of objects stored within this Directory. | ||||
|  */ | ||||
| public interface Directory<ObjectType extends Identifiable> { | ||||
|  | ||||
|     /** | ||||
|      * Returns the object having the given identifier. Note that changes to | ||||
|      * the object returned will not necessarily affect the object stored within | ||||
|      * the Directory. To update an object stored within an | ||||
|      * Directory such that future calls to get() will return the updated | ||||
|      * object, you must call update() on the object after modification. | ||||
|      * | ||||
|      * @param identifier The identifier to use when locating the object to | ||||
|      *                   return. | ||||
|      * @return The object having the given identifier, or null if no such object | ||||
|      *         exists. | ||||
|      * | ||||
|      * @throws GuacamoleException If an error occurs while retrieving the | ||||
|      *                            object, or if permission for retrieving the | ||||
|      *                            object is denied. | ||||
|      */ | ||||
|     ObjectType get(String identifier) throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns the objects having the given identifiers. Note that changes to | ||||
|      * any object returned will not necessarily affect the object stored within | ||||
|      * the Directory. To update an object stored within a | ||||
|      * Directory such that future calls to get() will return the updated | ||||
|      * object, you must call update() on the object after modification. | ||||
|      * | ||||
|      * @param identifiers | ||||
|      *     The identifiers to use when locating the objects to return. | ||||
|      * | ||||
|      * @return | ||||
|      *     The objects having the given identifiers. If any identifiers do not | ||||
|      *     correspond to accessible objects, those identifiers will be ignored. | ||||
|      *     If no objects correspond to any of the given identifiers, the | ||||
|      *     returned collection will be empty. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving the objects, or if permission | ||||
|      *     to retrieve the requested objects is denied. | ||||
|      */ | ||||
|     Collection<ObjectType> getAll(Collection<String> identifiers) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns a Set containing all identifiers for all objects within this | ||||
|      * Directory. | ||||
|      * | ||||
|      * @return A Set of all identifiers. | ||||
|      * @throws GuacamoleException If an error occurs while retrieving | ||||
|      *                            the identifiers. | ||||
|      */ | ||||
|     Set<String> getIdentifiers() throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Adds the given object to the overall set. If a new identifier is | ||||
|      * created for the added object, that identifier will be automatically | ||||
|      * assigned via setIdentifier(). | ||||
|      * | ||||
|      * @param object | ||||
|      *     The object to add. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while adding the object, or if adding the object | ||||
|      *     is not allowed. | ||||
|      */ | ||||
|     void add(ObjectType object) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Updates the stored object with the data contained in the given object. | ||||
|      * | ||||
|      * @param object The object which will supply the data for the update. | ||||
|      * | ||||
|      * @throws GuacamoleException If an error occurs while updating the object, | ||||
|      *                            or if updating the object is not allowed. | ||||
|      */ | ||||
|     void update(ObjectType object) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Removes the object with the given identifier from the overall set. | ||||
|      * | ||||
|      * @param identifier The identifier of the object to remove. | ||||
|      * | ||||
|      * @throws GuacamoleException If an error occurs while removing the object, | ||||
|      *                            or if removing object is not allowed. | ||||
|      */ | ||||
|     void remove(String identifier) throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,52 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| /** | ||||
|  * An object which has a deterministic, unique identifier, which may not be | ||||
|  * null. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface Identifiable { | ||||
|  | ||||
|     /** | ||||
|      * Returns the unique identifier assigned to this object. All identifiable | ||||
|      * objects must have a deterministic, unique identifier which may not be | ||||
|      * null. | ||||
|      * | ||||
|      * @return | ||||
|      *     The unique identifier assigned to this object, which may not be | ||||
|      *     null. | ||||
|      */ | ||||
|     public String getIdentifier(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the identifier assigned to this object. | ||||
|      * | ||||
|      * @param identifier | ||||
|      *     The identifier to assign. | ||||
|      */ | ||||
|     public void setIdentifier(String identifier); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,144 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| import java.util.Map; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.net.auth.permission.ObjectPermissionSet; | ||||
| import org.apache.guacamole.net.auth.permission.SystemPermissionSet; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * A user of the Guacamole web application. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface User extends Identifiable { | ||||
|  | ||||
|     /** | ||||
|      * Returns this user's password. Note that the password returned may be | ||||
|      * hashed or completely arbitrary. | ||||
|      * | ||||
|      * @return A String which may (or may not) be the user's password. | ||||
|      */ | ||||
|     public String getPassword(); | ||||
|  | ||||
|     /** | ||||
|      * Sets this user's password. Note that while this function is guaranteed | ||||
|      * to change the password of this User object, there is no guarantee that | ||||
|      * getPassword() will return the value given to setPassword(). | ||||
|      * | ||||
|      * @param password The password to set. | ||||
|      */ | ||||
|     public void setPassword(String password); | ||||
|  | ||||
|     /** | ||||
|      * Returns all attributes associated with this user. The returned map may | ||||
|      * not be modifiable. | ||||
|      * | ||||
|      * @return | ||||
|      *     A map of all attribute identifiers to their corresponding values, | ||||
|      *     for all attributes associated with this user, which may not be | ||||
|      *     modifiable. | ||||
|      */ | ||||
|     Map<String, String> getAttributes(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the given attributes. If an attribute within the map is not | ||||
|      * supported, it will simply be dropped. Any attributes not within the | ||||
|      * given map will be left untouched. | ||||
|      * | ||||
|      * @param attributes | ||||
|      *     A map of all attribute identifiers to their corresponding values. | ||||
|      */ | ||||
|     void setAttributes(Map<String, String> attributes); | ||||
|  | ||||
|     /** | ||||
|      * Returns all system-level permissions given to this user. | ||||
|      * | ||||
|      * @return | ||||
|      *     A SystemPermissionSet of all system-level permissions granted to | ||||
|      *     this user. | ||||
|      * | ||||
|      * @throws GuacamoleException  | ||||
|      *     If an error occurs while retrieving permissions, or if reading all | ||||
|      *     permissions is not allowed. | ||||
|      */ | ||||
|     SystemPermissionSet getSystemPermissions() throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns all connection permissions given to this user. | ||||
|      * | ||||
|      * @return | ||||
|      *     An ObjectPermissionSet of all connection permissions granted to this | ||||
|      *     user. | ||||
|      * | ||||
|      * @throws GuacamoleException  | ||||
|      *     If an error occurs while retrieving permissions, or if reading all | ||||
|      *     permissions is not allowed. | ||||
|      */ | ||||
|     ObjectPermissionSet getConnectionPermissions() | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns all connection group permissions given to this user. | ||||
|      * | ||||
|      * @return | ||||
|      *     An ObjectPermissionSet of all connection group permissions granted | ||||
|      *     to this user. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving permissions, or if reading all | ||||
|      *     permissions is not allowed. | ||||
|      */ | ||||
|     ObjectPermissionSet getConnectionGroupPermissions() | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns all permissions given to this user regarding currently-active | ||||
|      * connections. | ||||
|      * | ||||
|      * @return | ||||
|      *     An ObjectPermissionSet of all active connection permissions granted | ||||
|      *     to this user. | ||||
|      * | ||||
|      * @throws GuacamoleException  | ||||
|      *     If an error occurs while retrieving permissions, or if reading all | ||||
|      *     permissions is not allowed. | ||||
|      */ | ||||
|     ObjectPermissionSet getActiveConnectionPermissions() | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Returns all user permissions given to this user. | ||||
|      * | ||||
|      * @return | ||||
|      *     An ObjectPermissionSet of all user permissions granted to this user. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving permissions, or if reading all | ||||
|      *     permissions is not allowed. | ||||
|      */ | ||||
|     ObjectPermissionSet getUserPermissions() throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,171 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.form.Form; | ||||
|  | ||||
| /** | ||||
|  * The context of an active user. The functions of this class enforce all | ||||
|  * permissions and act only within the rights of the associated user. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface UserContext { | ||||
|  | ||||
|     /** | ||||
|      * Returns the User whose access rights control the operations of this | ||||
|      * UserContext. | ||||
|      * | ||||
|      * @return The User whose access rights control the operations of this | ||||
|      *         UserContext. | ||||
|      */ | ||||
|     User self(); | ||||
|  | ||||
|     /** | ||||
|      * Returns the AuthenticationProvider which created this UserContext, which | ||||
|      * may not be the same AuthenticationProvider that authenticated the user | ||||
|      * associated with this UserContext. | ||||
|      * | ||||
|      * @return | ||||
|      *     The AuthenticationProvider that created this UserContext. | ||||
|      */ | ||||
|     AuthenticationProvider getAuthenticationProvider(); | ||||
|  | ||||
|     /** | ||||
|      * Retrieves a Directory which can be used to view and manipulate other | ||||
|      * users, but only as allowed by the permissions given to the user of this | ||||
|      * UserContext. | ||||
|      * | ||||
|      * @return A Directory whose operations are bound by the restrictions | ||||
|      *         of this UserContext. | ||||
|      * | ||||
|      * @throws GuacamoleException If an error occurs while creating the | ||||
|      *                            Directory. | ||||
|      */ | ||||
|     Directory<User> getUserDirectory() throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Retrieves a Directory which can be used to view and manipulate | ||||
|      * connections and their configurations, but only as allowed by the | ||||
|      * permissions given to the user. | ||||
|      * | ||||
|      * @return A Directory whose operations are bound by the permissions of  | ||||
|      *         the user. | ||||
|      * | ||||
|      * @throws GuacamoleException If an error occurs while creating the | ||||
|      *                            Directory. | ||||
|      */ | ||||
|     Directory<Connection> getConnectionDirectory() | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Retrieves a Directory which can be used to view and manipulate | ||||
|      * connection groups and their members, but only as allowed by the | ||||
|      * permissions given to the user. | ||||
|      * | ||||
|      * @return A Directory whose operations are bound by the permissions of | ||||
|      *         the user. | ||||
|      * | ||||
|      * @throws GuacamoleException If an error occurs while creating the | ||||
|      *                            Directory. | ||||
|      */ | ||||
|     Directory<ConnectionGroup> getConnectionGroupDirectory() | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Retrieves a Directory which can be used to view and manipulate | ||||
|      * active connections, but only as allowed by the permissions given to the | ||||
|      * user. | ||||
|      * | ||||
|      * @return | ||||
|      *     A Directory whose operations are bound by the permissions of the | ||||
|      *     user. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while creating the Directory. | ||||
|      */ | ||||
|     Directory<ActiveConnection> getActiveConnectionDirectory() | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Retrieves all connection records visible to current user. The resulting | ||||
|      * set of connection records can be further filtered and ordered using the | ||||
|      * methods defined on ConnectionRecordSet. | ||||
|      * | ||||
|      * @return | ||||
|      *     A set of all connection records visible to the current user. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving the connection records. | ||||
|      */ | ||||
|     ConnectionRecordSet getConnectionHistory() throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Retrieves a connection group which can be used to view and manipulate | ||||
|      * connections, but only as allowed by the permissions given to the user of  | ||||
|      * this UserContext. | ||||
|      * | ||||
|      * @return A connection group whose operations are bound by the restrictions | ||||
|      *         of this UserContext. | ||||
|      * | ||||
|      * @throws GuacamoleException If an error occurs while creating the | ||||
|      *                            Directory. | ||||
|      */ | ||||
|     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<Form> 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<Form> 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<Form> getConnectionGroupAttributes(); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,93 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.credentials; | ||||
|  | ||||
| import java.util.Arrays; | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import org.apache.guacamole.form.Field; | ||||
| import org.apache.guacamole.form.PasswordField; | ||||
| import org.apache.guacamole.form.UsernameField; | ||||
|  | ||||
| /** | ||||
|  * Information which describes a set of valid credentials. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class CredentialsInfo { | ||||
|  | ||||
|     /** | ||||
|      * All fields required for valid credentials. | ||||
|      */ | ||||
|     private final Collection<Field> fields; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new CredentialsInfo object which requires the given fields for | ||||
|      * any conforming credentials. | ||||
|      * | ||||
|      * @param fields | ||||
|      *     The fields to require. | ||||
|      */ | ||||
|     public CredentialsInfo(Collection<Field> fields) { | ||||
|         this.fields = fields; | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Returns all fields required for valid credentials as described by this | ||||
|      * object. | ||||
|      * | ||||
|      * @return | ||||
|      *     All fields required for valid credentials. | ||||
|      */ | ||||
|     public Collection<Field> getFields() { | ||||
|         return Collections.unmodifiableCollection(fields); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * CredentialsInfo object which describes empty credentials. No fields are | ||||
|      * required. | ||||
|      */ | ||||
|     public static final CredentialsInfo EMPTY = new CredentialsInfo(Collections.<Field>emptyList()); | ||||
|  | ||||
|     /** | ||||
|      * A field describing the username HTTP parameter expected by Guacamole | ||||
|      * during login, if usernames are being used. | ||||
|      */ | ||||
|     public static final Field USERNAME = new UsernameField("username"); | ||||
|  | ||||
|     /** | ||||
|      * A field describing the password HTTP parameter expected by Guacamole | ||||
|      * during login, if passwords are being used. | ||||
|      */ | ||||
|     public static final Field PASSWORD = new PasswordField("password"); | ||||
|  | ||||
|     /** | ||||
|      * CredentialsInfo object which describes standard username/password | ||||
|      * credentials. | ||||
|      */ | ||||
|     public static final CredentialsInfo USERNAME_PASSWORD = new CredentialsInfo(Arrays.asList( | ||||
|         USERNAME, | ||||
|         PASSWORD | ||||
|     )); | ||||
|      | ||||
| } | ||||
| @@ -0,0 +1,100 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.credentials; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleUnauthorizedException; | ||||
|  | ||||
| /** | ||||
|  * A security-related exception thrown when access is denied to a user because | ||||
|  * of a problem related to the provided credentials. Additional information | ||||
|  * describing the form of valid credentials is provided. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class GuacamoleCredentialsException extends GuacamoleUnauthorizedException { | ||||
|  | ||||
|     /** | ||||
|      * Information describing the form of valid credentials. | ||||
|      */ | ||||
|     private final CredentialsInfo credentialsInfo; | ||||
|      | ||||
|     /** | ||||
|      * Creates a new GuacamoleInvalidCredentialsException with the given | ||||
|      * message, cause, and associated credential information. | ||||
|      * | ||||
|      * @param message | ||||
|      *     A human readable description of the exception that occurred. | ||||
|      * | ||||
|      * @param cause | ||||
|      *     The cause of this exception. | ||||
|      * | ||||
|      * @param credentialsInfo | ||||
|      *     Information describing the form of valid credentials. | ||||
|      */ | ||||
|     public GuacamoleCredentialsException(String message, Throwable cause, | ||||
|             CredentialsInfo credentialsInfo) { | ||||
|         super(message, cause); | ||||
|         this.credentialsInfo = credentialsInfo; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new GuacamoleInvalidCredentialsException with the given | ||||
|      * message and associated credential information. | ||||
|      * | ||||
|      * @param message | ||||
|      *     A human readable description of the exception that occurred. | ||||
|      * | ||||
|      * @param credentialsInfo | ||||
|      *     Information describing the form of valid credentials. | ||||
|      */ | ||||
|     public GuacamoleCredentialsException(String message, CredentialsInfo credentialsInfo) { | ||||
|         super(message); | ||||
|         this.credentialsInfo = credentialsInfo; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new GuacamoleInvalidCredentialsException with the given cause | ||||
|      * and associated credential information. | ||||
|      * | ||||
|      * @param cause | ||||
|      *     The cause of this exception. | ||||
|      * | ||||
|      * @param credentialsInfo | ||||
|      *     Information describing the form of valid credentials. | ||||
|      */ | ||||
|     public GuacamoleCredentialsException(Throwable cause, CredentialsInfo credentialsInfo) { | ||||
|         super(cause); | ||||
|         this.credentialsInfo = credentialsInfo; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns information describing the form of valid credentials. | ||||
|      * | ||||
|      * @return | ||||
|      *     Information describing the form of valid credentials. | ||||
|      */ | ||||
|     public CredentialsInfo getCredentialsInfo() { | ||||
|         return credentialsInfo; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,82 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.credentials; | ||||
|  | ||||
| /** | ||||
|  * A security-related exception thrown when access is denied to a user because | ||||
|  * the provided credentials are not sufficient for authentication to succeed. | ||||
|  * The validity or invalidity of the given credentials is not specified, and | ||||
|  * more information is needed before a decision can be made. Additional | ||||
|  * information describing the form of valid credentials is provided. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class GuacamoleInsufficientCredentialsException extends GuacamoleCredentialsException { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new GuacamoleInsufficientCredentialsException with the given | ||||
|      * message, cause, and associated credential information. | ||||
|      * | ||||
|      * @param message | ||||
|      *     A human readable description of the exception that occurred. | ||||
|      * | ||||
|      * @param cause | ||||
|      *     The cause of this exception. | ||||
|      * | ||||
|      * @param credentialsInfo | ||||
|      *     Information describing the form of valid credentials. | ||||
|      */ | ||||
|     public GuacamoleInsufficientCredentialsException(String message, Throwable cause, | ||||
|             CredentialsInfo credentialsInfo) { | ||||
|         super(message, cause, credentialsInfo); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new GuacamoleInsufficientCredentialsException with the given | ||||
|      * message and associated credential information. | ||||
|      * | ||||
|      * @param message | ||||
|      *     A human readable description of the exception that occurred. | ||||
|      * | ||||
|      * @param credentialsInfo | ||||
|      *     Information describing the form of valid credentials. | ||||
|      */ | ||||
|     public GuacamoleInsufficientCredentialsException(String message, CredentialsInfo credentialsInfo) { | ||||
|         super(message, credentialsInfo); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new GuacamoleInsufficientCredentialsException with the given | ||||
|      * cause and associated credential information. | ||||
|      * | ||||
|      * @param cause | ||||
|      *     The cause of this exception. | ||||
|      * | ||||
|      * @param credentialsInfo | ||||
|      *     Information describing the form of valid credentials. | ||||
|      */ | ||||
|     public GuacamoleInsufficientCredentialsException(Throwable cause, CredentialsInfo credentialsInfo) { | ||||
|         super(cause, credentialsInfo); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,80 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.credentials; | ||||
|  | ||||
| /** | ||||
|  * A security-related exception thrown when access is denied to a user because | ||||
|  * the provided credentials are invalid. Additional information describing | ||||
|  * the form of valid credentials is provided. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class GuacamoleInvalidCredentialsException extends GuacamoleCredentialsException { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new GuacamoleInvalidCredentialsException with the given | ||||
|      * message, cause, and associated credential information. | ||||
|      * | ||||
|      * @param message | ||||
|      *     A human readable description of the exception that occurred. | ||||
|      * | ||||
|      * @param cause | ||||
|      *     The cause of this exception. | ||||
|      * | ||||
|      * @param credentialsInfo | ||||
|      *     Information describing the form of valid credentials. | ||||
|      */ | ||||
|     public GuacamoleInvalidCredentialsException(String message, Throwable cause, | ||||
|             CredentialsInfo credentialsInfo) { | ||||
|         super(message, cause, credentialsInfo); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new GuacamoleInvalidCredentialsException with the given | ||||
|      * message and associated credential information. | ||||
|      * | ||||
|      * @param message | ||||
|      *     A human readable description of the exception that occurred. | ||||
|      * | ||||
|      * @param credentialsInfo | ||||
|      *     Information describing the form of valid credentials. | ||||
|      */ | ||||
|     public GuacamoleInvalidCredentialsException(String message, CredentialsInfo credentialsInfo) { | ||||
|         super(message, credentialsInfo); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new GuacamoleInvalidCredentialsException with the given cause | ||||
|      * and associated credential information. | ||||
|      * | ||||
|      * @param cause | ||||
|      *     The cause of this exception. | ||||
|      * | ||||
|      * @param credentialsInfo | ||||
|      *     Information describing the form of valid credentials. | ||||
|      */ | ||||
|     public GuacamoleInvalidCredentialsException(Throwable cause, CredentialsInfo credentialsInfo) { | ||||
|         super(cause, credentialsInfo); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,28 @@ | ||||
| /* | ||||
|  * 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 can be used to extend or replace the authentication | ||||
|  * functionality of the Guacamole web application. | ||||
|  */ | ||||
| package org.apache.guacamole.net.auth; | ||||
|  | ||||
| @@ -0,0 +1,139 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth.permission; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * A permission which affects a specific object, rather than the system as a | ||||
|  * whole. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class ObjectPermission implements Permission<ObjectPermission.Type> { | ||||
|  | ||||
|     /** | ||||
|      * Specific types of object-level permissions. Each permission type is | ||||
|      * related to a specific class of object-level operation. | ||||
|      */ | ||||
|     public enum Type { | ||||
|  | ||||
|         /** | ||||
|          * Read data within an object. | ||||
|          */ | ||||
|         READ, | ||||
|  | ||||
|         /** | ||||
|          * Update data within an object. | ||||
|          */ | ||||
|         UPDATE, | ||||
|  | ||||
|         /** | ||||
|          * Delete an object. | ||||
|          */ | ||||
|         DELETE, | ||||
|  | ||||
|         /** | ||||
|          * Change who has access to an object. | ||||
|          */ | ||||
|         ADMINISTER | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * The identifier of the GuacamoleConfiguration associated with the | ||||
|      * operation affected by this permission. | ||||
|      */ | ||||
|     private final String identifier; | ||||
|  | ||||
|     /** | ||||
|      * The type of operation affected by this permission. | ||||
|      */ | ||||
|     private final Type type; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new ObjectPermission having the given type and identifier. | ||||
|      * The identifier must be the unique identifier assigned to the object | ||||
|      * associated with this permission by the AuthenticationProvider in use. | ||||
|      * | ||||
|      * @param type | ||||
|      *     The type of operation affected by this permission. | ||||
|      * | ||||
|      * @param identifier | ||||
|      *     The identifier of the object associated with the operation affected | ||||
|      *     by this permission. | ||||
|      */ | ||||
|     public ObjectPermission(Type type, String identifier) { | ||||
|  | ||||
|         this.identifier = identifier; | ||||
|         this.type = type; | ||||
|  | ||||
|     } | ||||
|  | ||||
|    /** | ||||
|      * Returns the identifier of the specific object affected by this | ||||
|      * permission. | ||||
|      * | ||||
|      * @return The identifier of the specific object affected by this | ||||
|      *         permission. | ||||
|      */ | ||||
|     public String getObjectIdentifier() { | ||||
|         return identifier; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Type getType() { | ||||
|         return type; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int hashCode() { | ||||
|         int hash = 5; | ||||
|         if (identifier != null) hash = 47 * hash + identifier.hashCode(); | ||||
|         if (type != null)       hash = 47 * hash + type.hashCode(); | ||||
|         return hash; | ||||
|     } | ||||
|  | ||||
|     @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 ObjectPermission other = (ObjectPermission) obj; | ||||
|  | ||||
|         // Not equal if different type | ||||
|         if (this.type != other.type) | ||||
|             return false; | ||||
|  | ||||
|         // 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,134 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.permission; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.Set; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * A set of permissions which affect arbitrary objects, where each object has | ||||
|  * an associated unique identifier. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface ObjectPermissionSet extends PermissionSet<ObjectPermission> { | ||||
|  | ||||
|     /** | ||||
|      * Tests whether the permission of the given type is granted for the | ||||
|      * object having the given identifier. | ||||
|      * | ||||
|      * @param permission | ||||
|      *     The permission to check. | ||||
|      * | ||||
|      * @param identifier | ||||
|      *     The identifier of the object affected by the permission being | ||||
|      *     checked. | ||||
|      * | ||||
|      * @return | ||||
|      *     true if the permission is granted, false otherwise. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while checking permissions, or if permissions | ||||
|      *     cannot be checked due to lack of permissions to do so. | ||||
|      */ | ||||
|     boolean hasPermission(ObjectPermission.Type permission, | ||||
|             String identifier) throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Adds the specified permission for the object having the given | ||||
|      * identifier. | ||||
|      * | ||||
|      * @param permission | ||||
|      *     The permission to add. | ||||
|      * | ||||
|      * @param identifier | ||||
|      *     The identifier of the object affected by the permission being | ||||
|      *     added. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while adding the permission, or if permission to | ||||
|      *     add permissions is denied. | ||||
|      */ | ||||
|     void addPermission(ObjectPermission.Type permission, | ||||
|             String identifier) throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Removes the specified permission for the object having the given | ||||
|      * identifier. | ||||
|      * | ||||
|      * @param permission | ||||
|      *     The permission to remove. | ||||
|      * | ||||
|      * @param identifier | ||||
|      *     The identifier of the object affected by the permission being | ||||
|      *     added. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while removing the permission, or if permission | ||||
|      *     to remove permissions is denied. | ||||
|      */ | ||||
|     void removePermission(ObjectPermission.Type permission, | ||||
|             String identifier) throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Tests whether this user has the specified permissions for the objects | ||||
|      * having the given identifiers. The identifier of an object is returned | ||||
|      * in a new collection if at least one of the specified permissions is | ||||
|      * granted for that object. | ||||
|      * | ||||
|      * @param permissions | ||||
|      *     The permissions to check. An identifier will be included in the | ||||
|      *     resulting collection if at least one of these permissions is granted | ||||
|      *     for the associated object | ||||
|      * | ||||
|      * @param identifiers | ||||
|      *     The identifiers of the objects affected by the permissions being | ||||
|      *     checked. | ||||
|      * | ||||
|      * @return | ||||
|      *     A collection containing the subset of identifiers for which at least | ||||
|      *     one of the specified permissions is granted. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while checking permissions, or if permissions | ||||
|      *     cannot be checked due to lack of permissions to do so. | ||||
|      */ | ||||
|     Collection<String> getAccessibleObjects( | ||||
|             Collection<ObjectPermission.Type> permissions, | ||||
|             Collection<String> identifiers) throws GuacamoleException; | ||||
|  | ||||
|     @Override | ||||
|     Set<ObjectPermission> getPermissions() | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     @Override | ||||
|     void addPermissions(Set<ObjectPermission> permissions) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     @Override | ||||
|     void removePermissions(Set<ObjectPermission> permissions) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,42 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth.permission; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * A permission which affects a specific type of operation, where all available | ||||
|  * operation types are defined by an enumeration. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  * @param <Type> The enumeration of all available operation types that this | ||||
|  *               permission can affect. | ||||
|  */ | ||||
| public interface Permission<Type extends Enum> { | ||||
|  | ||||
|     /** | ||||
|      * Returns the type of operation affected by this permission. | ||||
|      * @return The type of operation affected by this permission. | ||||
|      */ | ||||
|     public Type getType(); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,82 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.permission; | ||||
|  | ||||
| import java.util.Set; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * An arbitrary set of permissions. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  * @param <PermissionType> | ||||
|  *     The type of permission stored within this PermissionSet. | ||||
|  */ | ||||
| public interface PermissionSet<PermissionType extends Permission> { | ||||
|  | ||||
|     /** | ||||
|      * Returns a Set which contains all permissions granted within this | ||||
|      * permission set. | ||||
|      * | ||||
|      * @return | ||||
|      *     A Set containing all permissions granted within this permission set. | ||||
|      * | ||||
|      * @throws GuacamoleException  | ||||
|      *     If an error occurs while retrieving permissions, or if permissions | ||||
|      *     cannot be retrieved due to lack of permissions to do so. | ||||
|      */ | ||||
|     Set<PermissionType> getPermissions() throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Adds the specified permissions, if not already granted. If a specified | ||||
|      * permission is already granted, no operation is performed regarding that | ||||
|      * permission. | ||||
|      * | ||||
|      * @param permissions | ||||
|      *     The permissions to add. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while adding the permissions, or if permission to | ||||
|      *     add permissions is denied. | ||||
|      */ | ||||
|     void addPermissions(Set<PermissionType> permissions) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Removes each of the specified permissions, if granted. If a specified | ||||
|      * permission is not granted, no operation is performed regarding that | ||||
|      * permission. | ||||
|      * | ||||
|      * @param permissions | ||||
|      *     The permissions to remove. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while removing the permissions, or if permission | ||||
|      *     to remove permissions is denied. | ||||
|      */ | ||||
|     void removePermissions(Set<PermissionType> permissions) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,105 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth.permission; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * A permission which affects the system as a whole, rather than an individual | ||||
|  * object. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SystemPermission implements Permission<SystemPermission.Type> { | ||||
|  | ||||
|     /** | ||||
|      * Specific types of system-level permissions. Each permission type is | ||||
|      * related to a specific class of system-level operation. | ||||
|      */ | ||||
|     public enum Type { | ||||
|  | ||||
|         /** | ||||
|          * Create users. | ||||
|          */ | ||||
|         CREATE_USER, | ||||
|  | ||||
|         /** | ||||
|          * Create connections. | ||||
|          */ | ||||
|         CREATE_CONNECTION, | ||||
|  | ||||
|         /** | ||||
|          * Create connection groups. | ||||
|          */ | ||||
|         CREATE_CONNECTION_GROUP, | ||||
|  | ||||
|         /** | ||||
|          * Administer the system in general, including adding permissions | ||||
|          * which affect the system (like user creation, connection creation, | ||||
|          * and system administration). | ||||
|          */ | ||||
|         ADMINISTER | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * The type of operation affected by this permission. | ||||
|      */ | ||||
|     private Type type; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SystemPermission with the given | ||||
|      * type. | ||||
|      * | ||||
|      * @param type The type of operation controlled by this permission. | ||||
|      */ | ||||
|     public SystemPermission(Type type) { | ||||
|         this.type = type; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Type getType() { | ||||
|         return type; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int hashCode() { | ||||
|         return type.hashCode(); | ||||
|     } | ||||
|  | ||||
|     @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 SystemPermission other = (SystemPermission) obj; | ||||
|  | ||||
|         // Compare types | ||||
|         if (type != other.type) | ||||
|             return false; | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,89 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.permission; | ||||
|  | ||||
| import java.util.Set; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * A set of permissions which affects the system as a whole. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface SystemPermissionSet extends PermissionSet<SystemPermission> { | ||||
|  | ||||
|     /** | ||||
|      * Tests whether the permission of the given type is granted. | ||||
|      * | ||||
|      * @param permission | ||||
|      *     The permission to check. | ||||
|      * | ||||
|      * @return | ||||
|      *     true if the permission is granted, false otherwise. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while checking permissions, or if permissions | ||||
|      *     cannot be checked due to lack of permissions to do so. | ||||
|      */ | ||||
|     boolean hasPermission(SystemPermission.Type permission) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Adds the specified permission. | ||||
|      * | ||||
|      * @param permission | ||||
|      *     The permission to add. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while adding the permission, or if permission to | ||||
|      *     add permissions is denied. | ||||
|      */ | ||||
|     void addPermission(SystemPermission.Type permission) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * Removes the specified permission. | ||||
|      * | ||||
|      * @param permission | ||||
|      *     The permission to remove. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while removing the permission, or if permission | ||||
|      *     to remove permissions is denied. | ||||
|      */ | ||||
|     void removePermission(SystemPermission.Type permission) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     @Override | ||||
|     Set<SystemPermission> getPermissions() throws GuacamoleException; | ||||
|  | ||||
|     @Override | ||||
|     void addPermissions(Set<SystemPermission> permissions) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     @Override | ||||
|     void removePermissions(Set<SystemPermission> permissions) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,28 @@ | ||||
| /* | ||||
|  * 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 permissions a Guacamole user | ||||
|  * can be granted. | ||||
|  */ | ||||
| package org.apache.guacamole.net.auth.permission; | ||||
|  | ||||
| @@ -0,0 +1,264 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.Map; | ||||
| import java.util.UUID; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.net.auth.AbstractAuthenticatedUser; | ||||
| import org.apache.guacamole.net.auth.AuthenticationProvider; | ||||
| import org.apache.guacamole.net.auth.AuthenticatedUser; | ||||
| import org.apache.guacamole.net.auth.Credentials; | ||||
| import org.apache.guacamole.net.auth.UserContext; | ||||
| import org.apache.guacamole.protocol.GuacamoleConfiguration; | ||||
| import org.apache.guacamole.token.StandardTokens; | ||||
| import org.apache.guacamole.token.TokenFilter; | ||||
|  | ||||
| /** | ||||
|  * Provides means of retrieving a set of named GuacamoleConfigurations for a | ||||
|  * given Credentials object. This is a simple AuthenticationProvider | ||||
|  * implementation intended to be easily extended. It is useful for simple | ||||
|  * authentication situations where access to web-based administration and | ||||
|  * complex users and permissions are not required. | ||||
|  * | ||||
|  * The interface provided by SimpleAuthenticationProvider is similar to that of | ||||
|  * the AuthenticationProvider interface of older Guacamole releases. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public abstract class SimpleAuthenticationProvider | ||||
|     implements AuthenticationProvider { | ||||
|  | ||||
|     /** | ||||
|      * Given an arbitrary credentials object, returns a Map containing all | ||||
|      * configurations authorized by those credentials. The keys of this Map | ||||
|      * are Strings which uniquely identify each configuration. | ||||
|      * | ||||
|      * @param credentials The credentials to use to retrieve authorized | ||||
|      *                    configurations. | ||||
|      * @return A Map of all configurations authorized by the given credentials, | ||||
|      *         or null if the credentials given are not authorized. | ||||
|      * @throws GuacamoleException If an error occurs while retrieving | ||||
|      *                            configurations. | ||||
|      */ | ||||
|     public abstract Map<String, GuacamoleConfiguration> | ||||
|             getAuthorizedConfigurations(Credentials credentials) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
|     /** | ||||
|      * AuthenticatedUser which contains its own predefined set of authorized | ||||
|      * configurations. | ||||
|      * | ||||
|      * @author Michael Jumper | ||||
|      */ | ||||
|     private class SimpleAuthenticatedUser extends AbstractAuthenticatedUser { | ||||
|  | ||||
|         /** | ||||
|          * The credentials provided when this AuthenticatedUser was | ||||
|          * authenticated. | ||||
|          */ | ||||
|         private final Credentials credentials; | ||||
|  | ||||
|         /** | ||||
|          * The GuacamoleConfigurations that this AuthenticatedUser is | ||||
|          * authorized to use. | ||||
|          */ | ||||
|         private final Map<String, GuacamoleConfiguration> configs; | ||||
|  | ||||
|         /** | ||||
|          * Creates a new SimpleAuthenticatedUser associated with the given | ||||
|          * credentials and having access to the given Map of | ||||
|          * GuacamoleConfigurations. | ||||
|          * | ||||
|          * @param credentials | ||||
|          *     The credentials provided by the user when they authenticated. | ||||
|          * | ||||
|          * @param configs | ||||
|          *     A Map of all GuacamoleConfigurations for which this user has | ||||
|          *     access. The keys of this Map are Strings which uniquely identify | ||||
|          *     each configuration. | ||||
|          */ | ||||
|         public SimpleAuthenticatedUser(Credentials credentials, Map<String, GuacamoleConfiguration> configs) { | ||||
|  | ||||
|             // Store credentials and configurations | ||||
|             this.credentials = credentials; | ||||
|             this.configs = configs; | ||||
|  | ||||
|             // Pull username from credentials if it exists | ||||
|             String username = credentials.getUsername(); | ||||
|             if (username != null && !username.isEmpty()) | ||||
|                 setIdentifier(username); | ||||
|  | ||||
|             // Otherwise generate a random username | ||||
|             else | ||||
|                 setIdentifier(UUID.randomUUID().toString()); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         /** | ||||
|          * Returns a Map containing all GuacamoleConfigurations that this user | ||||
|          * is authorized to use. The keys of this Map are Strings which | ||||
|          * uniquely identify each configuration. | ||||
|          * | ||||
|          * @return | ||||
|          *     A Map of all configurations for which this user is authorized. | ||||
|          */ | ||||
|         public Map<String, GuacamoleConfiguration> getAuthorizedConfigurations() { | ||||
|             return configs; | ||||
|         } | ||||
|  | ||||
|         @Override | ||||
|         public AuthenticationProvider getAuthenticationProvider() { | ||||
|             return SimpleAuthenticationProvider.this; | ||||
|         } | ||||
|  | ||||
|         @Override | ||||
|         public Credentials getCredentials() { | ||||
|             return credentials; | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Given an arbitrary credentials object, returns a Map containing all | ||||
|      * configurations authorized by those credentials, filtering those | ||||
|      * configurations using a TokenFilter and the standard credential tokens | ||||
|      * (like ${GUAC_USERNAME} and ${GUAC_PASSWORD}). The keys of this Map | ||||
|      * are Strings which uniquely identify each configuration. | ||||
|      * | ||||
|      * @param credentials | ||||
|      *     The credentials to use to retrieve authorized configurations. | ||||
|      * | ||||
|      * @return | ||||
|      *     A Map of all configurations authorized by the given credentials, or | ||||
|      *     null if the credentials given are not authorized. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving configurations. | ||||
|      */ | ||||
|     private Map<String, GuacamoleConfiguration> | ||||
|             getFilteredAuthorizedConfigurations(Credentials credentials) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         // Get configurations | ||||
|         Map<String, GuacamoleConfiguration> configs = | ||||
|                 getAuthorizedConfigurations(credentials); | ||||
|  | ||||
|         // Return as unauthorized if not authorized to retrieve configs | ||||
|         if (configs == null) | ||||
|             return null; | ||||
|  | ||||
|         // Build credential TokenFilter | ||||
|         TokenFilter tokenFilter = new TokenFilter(); | ||||
|         StandardTokens.addStandardTokens(tokenFilter, credentials); | ||||
|  | ||||
|         // Filter each configuration | ||||
|         for (GuacamoleConfiguration config : configs.values()) | ||||
|             tokenFilter.filterValues(config.getParameters()); | ||||
|  | ||||
|         return configs; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Given a user who has already been authenticated, returns a Map | ||||
|      * containing all configurations for which that user is authorized, | ||||
|      * filtering those configurations using a TokenFilter and the standard | ||||
|      * credential tokens (like ${GUAC_USERNAME} and ${GUAC_PASSWORD}). The keys | ||||
|      * of this Map are Strings which uniquely identify each configuration. | ||||
|      * | ||||
|      * @param authenticatedUser | ||||
|      *     The user whose authorized configurations are to be retrieved. | ||||
|      * | ||||
|      * @return | ||||
|      *     A Map of all configurations authorized for use by the given user, or | ||||
|      *     null if the user is not authorized to use any configurations. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving configurations. | ||||
|      */ | ||||
|     private Map<String, GuacamoleConfiguration> | ||||
|             getFilteredAuthorizedConfigurations(AuthenticatedUser authenticatedUser) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         // Pull cached configurations, if any | ||||
|         if (authenticatedUser instanceof SimpleAuthenticatedUser && authenticatedUser.getAuthenticationProvider() == this) | ||||
|             return ((SimpleAuthenticatedUser) authenticatedUser).getAuthorizedConfigurations(); | ||||
|  | ||||
|         // Otherwise, pull using credentials | ||||
|         return getFilteredAuthorizedConfigurations(authenticatedUser.getCredentials()); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public AuthenticatedUser authenticateUser(final Credentials credentials) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         // Get configurations | ||||
|         Map<String, GuacamoleConfiguration> configs = | ||||
|                 getFilteredAuthorizedConfigurations(credentials); | ||||
|  | ||||
|         // Return as unauthorized if not authorized to retrieve configs | ||||
|         if (configs == null) | ||||
|             return null; | ||||
|  | ||||
|         return new SimpleAuthenticatedUser(credentials, configs); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UserContext getUserContext(AuthenticatedUser authenticatedUser) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         // Get configurations | ||||
|         Map<String, GuacamoleConfiguration> configs = | ||||
|                 getFilteredAuthorizedConfigurations(authenticatedUser); | ||||
|  | ||||
|         // Return as unauthorized if not authorized to retrieve configs | ||||
|         if (configs == null) | ||||
|             return null; | ||||
|  | ||||
|         // Return user context restricted to authorized configs | ||||
|         return new SimpleUserContext(this, authenticatedUser.getIdentifier(), configs); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser authenticatedUser, | ||||
|             Credentials credentials) throws GuacamoleException { | ||||
|  | ||||
|         // Simply return the given user, updating nothing | ||||
|         return authenticatedUser; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UserContext updateUserContext(UserContext context, | ||||
|         AuthenticatedUser authorizedUser) throws GuacamoleException { | ||||
|  | ||||
|         // Simply return the given context, updating nothing | ||||
|         return context; | ||||
|          | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,146 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.environment.Environment; | ||||
| import org.apache.guacamole.environment.LocalEnvironment; | ||||
| import org.apache.guacamole.net.GuacamoleSocket; | ||||
| import org.apache.guacamole.net.GuacamoleTunnel; | ||||
| import org.apache.guacamole.net.InetGuacamoleSocket; | ||||
| import org.apache.guacamole.net.SSLGuacamoleSocket; | ||||
| import org.apache.guacamole.net.SimpleGuacamoleTunnel; | ||||
| import org.apache.guacamole.net.auth.AbstractConnection; | ||||
| import org.apache.guacamole.net.auth.ConnectionRecord; | ||||
| import org.apache.guacamole.protocol.ConfiguredGuacamoleSocket; | ||||
| import org.apache.guacamole.protocol.GuacamoleClientInformation; | ||||
| import org.apache.guacamole.protocol.GuacamoleConfiguration; | ||||
|  | ||||
| /** | ||||
|  * An extremely basic Connection implementation. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SimpleConnection extends AbstractConnection { | ||||
|  | ||||
|     /** | ||||
|      * The hostname to use when connecting to guacd if no hostname is provided | ||||
|      * within guacamole.properties. | ||||
|      */ | ||||
|     private static final String DEFAULT_GUACD_HOSTNAME = "localhost"; | ||||
|  | ||||
|     /** | ||||
|      * The port to use when connecting to guacd if no port is provided within | ||||
|      * guacamole.properties. | ||||
|      */ | ||||
|     private static final int DEFAULT_GUACD_PORT = 4822; | ||||
|  | ||||
|     /** | ||||
|      * Backing configuration, containing all sensitive information. | ||||
|      */ | ||||
|     private GuacamoleConfiguration config; | ||||
|  | ||||
|     /** | ||||
|      * Creates a completely uninitialized SimpleConnection. | ||||
|      */ | ||||
|     public SimpleConnection() { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleConnection having the given identifier and | ||||
|      * GuacamoleConfiguration. | ||||
|      * | ||||
|      * @param name The name to associate with this connection. | ||||
|      * @param identifier The identifier to associate with this connection. | ||||
|      * @param config The configuration describing how to connect to this | ||||
|      *               connection. | ||||
|      */ | ||||
|     public SimpleConnection(String name, String identifier, | ||||
|             GuacamoleConfiguration config) { | ||||
|          | ||||
|         // Set name | ||||
|         setName(name); | ||||
|  | ||||
|         // Set identifier | ||||
|         setIdentifier(identifier); | ||||
|  | ||||
|         // Set config | ||||
|         setConfiguration(config); | ||||
|         this.config = config; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int getActiveConnections() { | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Map<String, String> getAttributes() { | ||||
|         return Collections.<String, String>emptyMap(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setAttributes(Map<String, String> attributes) { | ||||
|         // Do nothing - there are no attributes | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public GuacamoleTunnel connect(GuacamoleClientInformation info) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         Environment env = new LocalEnvironment(); | ||||
|          | ||||
|         // Get guacd connection parameters | ||||
|         String hostname = env.getProperty(Environment.GUACD_HOSTNAME, DEFAULT_GUACD_HOSTNAME); | ||||
|         int port = env.getProperty(Environment.GUACD_PORT, DEFAULT_GUACD_PORT); | ||||
|  | ||||
|         GuacamoleSocket socket; | ||||
|          | ||||
|         // If guacd requires SSL, use it | ||||
|         if (env.getProperty(Environment.GUACD_SSL, false)) | ||||
|             socket = new ConfiguredGuacamoleSocket( | ||||
|                 new SSLGuacamoleSocket(hostname, port), | ||||
|                 config, info | ||||
|             ); | ||||
|  | ||||
|         // Otherwise, just connect directly via TCP | ||||
|         else | ||||
|             socket = new ConfiguredGuacamoleSocket( | ||||
|                 new InetGuacamoleSocket(hostname, port), | ||||
|                 config, info | ||||
|             ); | ||||
|  | ||||
|         return new SimpleGuacamoleTunnel(socket); | ||||
|          | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<ConnectionRecord> getHistory() throws GuacamoleException { | ||||
|         return Collections.<ConnectionRecord>emptyList(); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,84 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import org.apache.guacamole.net.auth.Connection; | ||||
|  | ||||
| /** | ||||
|  * An extremely simple read-only implementation of a Directory of | ||||
|  * GuacamoleConfigurations which provides access to a pre-defined Map of | ||||
|  * GuacamoleConfigurations. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SimpleConnectionDirectory extends SimpleDirectory<Connection> { | ||||
|  | ||||
|     /** | ||||
|      * The Map of Connections to provide access to. | ||||
|      */ | ||||
|     private final Map<String, Connection> connections = | ||||
|             new HashMap<String, Connection>(); | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleConnectionDirectory which provides access to the | ||||
|      * connections contained within the given Map. | ||||
|      * | ||||
|      * @param connections | ||||
|      *     A Collection of all connections that should be present in this | ||||
|      *     connection directory. | ||||
|      */ | ||||
|     public SimpleConnectionDirectory(Collection<Connection> connections) { | ||||
|  | ||||
|         // Add all given connections | ||||
|         for (Connection connection : connections) | ||||
|             this.connections.put(connection.getIdentifier(), connection); | ||||
|  | ||||
|         // Use the connection map to back the underlying directory  | ||||
|         super.setObjects(this.connections); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * An internal method for modifying the Connections in this Directory. | ||||
|      * Returns the previous connection for the given identifier, if found. | ||||
|      * | ||||
|      * @param connection The connection to add or update the Directory with. | ||||
|      * @return The previous connection for the connection identifier, if found. | ||||
|      */ | ||||
|     public Connection putConnection(Connection connection) { | ||||
|         return connections.put(connection.getIdentifier(), connection); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * An internal method for removing a Connection from this Directory. | ||||
|      * @param identifier The identifier of the Connection to remove. | ||||
|      * @return The previous connection for the given identifier, if found. | ||||
|      */ | ||||
|     public Connection removeConnection(String identifier) { | ||||
|         return connections.remove(identifier); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,122 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.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.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.GuacamoleSecurityException; | ||||
| import org.apache.guacamole.net.GuacamoleTunnel; | ||||
| import org.apache.guacamole.net.auth.AbstractConnectionGroup; | ||||
| import org.apache.guacamole.net.auth.ConnectionGroup; | ||||
| import org.apache.guacamole.protocol.GuacamoleClientInformation; | ||||
|  | ||||
| /** | ||||
|  * An extremely simple read-only implementation of a ConnectionGroup which | ||||
|  * returns the connection and connection group identifiers it was constructed | ||||
|  * with. Load balancing across this connection group is not allowed. | ||||
|  *  | ||||
|  * @author James Muehlner | ||||
|  */ | ||||
| public class SimpleConnectionGroup extends AbstractConnectionGroup { | ||||
|  | ||||
|     /** | ||||
|      * The identifiers of all connections in this group. | ||||
|      */ | ||||
|     private final Set<String> connectionIdentifiers; | ||||
|  | ||||
|     /** | ||||
|      * The identifiers of all connection groups in this group. | ||||
|      */ | ||||
|     private final Set<String> connectionGroupIdentifiers; | ||||
|      | ||||
|     /** | ||||
|      * Creates a new SimpleConnectionGroup having the given name and identifier | ||||
|      * which will expose the given contents. | ||||
|      *  | ||||
|      * @param name | ||||
|      *     The name to associate with this connection group. | ||||
|      * | ||||
|      * @param identifier | ||||
|      *     The identifier to associate with this connection group. | ||||
|      * | ||||
|      * @param connectionIdentifiers | ||||
|      *     The connection identifiers to expose when requested. | ||||
|      * | ||||
|      * @param connectionGroupIdentifiers | ||||
|      *     The connection group identifiers to expose when requested. | ||||
|      */ | ||||
|     public SimpleConnectionGroup(String name, String identifier, | ||||
|             Collection<String> connectionIdentifiers,  | ||||
|             Collection<String> connectionGroupIdentifiers) { | ||||
|  | ||||
|         // Set name | ||||
|         setName(name); | ||||
|  | ||||
|         // Set identifier | ||||
|         setIdentifier(identifier); | ||||
|          | ||||
|         // Set group type | ||||
|         setType(ConnectionGroup.Type.ORGANIZATIONAL); | ||||
|  | ||||
|         // Populate contents | ||||
|         this.connectionIdentifiers = new HashSet<String>(connectionIdentifiers); | ||||
|         this.connectionGroupIdentifiers = new HashSet<String>(connectionGroupIdentifiers); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int getActiveConnections() { | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Set<String> getConnectionIdentifiers() { | ||||
|         return connectionIdentifiers; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Set<String> getConnectionGroupIdentifiers() { | ||||
|         return connectionGroupIdentifiers; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Map<String, String> getAttributes() { | ||||
|         return Collections.<String, String>emptyMap(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setAttributes(Map<String, String> attributes) { | ||||
|         // Do nothing - there are no attributes | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public GuacamoleTunnel connect(GuacamoleClientInformation info)  | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,87 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import org.apache.guacamole.net.auth.ConnectionGroup; | ||||
|  | ||||
| /** | ||||
|  * An extremely simple read-only implementation of a Directory of | ||||
|  * ConnectionGroup which provides which provides access to a pre-defined | ||||
|  * Collection of ConnectionGroups. | ||||
|  * | ||||
|  * @author James Muehlner | ||||
|  */ | ||||
| public class SimpleConnectionGroupDirectory | ||||
|     extends SimpleDirectory<ConnectionGroup> { | ||||
|  | ||||
|     /** | ||||
|      * The Map of ConnectionGroups to provide access to. | ||||
|      */ | ||||
|     private final Map<String, ConnectionGroup> connectionGroups = | ||||
|             new HashMap<String, ConnectionGroup>(); | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleConnectionGroupDirectory which contains the given | ||||
|      * groups. | ||||
|      * | ||||
|      * @param groups A Collection of all groups that should be present in this | ||||
|      *               connection group directory. | ||||
|      */ | ||||
|     public SimpleConnectionGroupDirectory(Collection<ConnectionGroup> groups) { | ||||
|  | ||||
|         // Add all given groups | ||||
|         for (ConnectionGroup group : groups) | ||||
|             connectionGroups.put(group.getIdentifier(), group); | ||||
|  | ||||
|         // Use the connection group map to back the underlying AbstractDirectory | ||||
|         super.setObjects(connectionGroups); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * An internal method for modifying the ConnectionGroups in this Directory. | ||||
|      * Returns the previous connection group for the given identifier, if found. | ||||
|      * | ||||
|      * @param connectionGroup The connection group to add or update the | ||||
|      *                        Directory with. | ||||
|      * @return The previous connection group for the connection group | ||||
|      *         identifier, if found. | ||||
|      */ | ||||
|     public ConnectionGroup putConnectionGroup(ConnectionGroup connectionGroup) { | ||||
|         return connectionGroups.put(connectionGroup.getIdentifier(), connectionGroup); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * An internal method for removing a ConnectionGroup from this Directory. | ||||
|      * | ||||
|      * @param identifier The identifier of the ConnectionGroup to remove. | ||||
|      * @return The previous connection group for the given identifier, if found. | ||||
|      */ | ||||
|     public ConnectionGroup removeConnectionGroup(String identifier) { | ||||
|         return connectionGroups.remove(identifier); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,62 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.net.auth.ConnectionRecord; | ||||
| import org.apache.guacamole.net.auth.ConnectionRecordSet; | ||||
|  | ||||
| /** | ||||
|  * An immutable and empty ConnectionRecordSet. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SimpleConnectionRecordSet implements ConnectionRecordSet { | ||||
|  | ||||
|     @Override | ||||
|     public Collection<ConnectionRecord> asCollection() | ||||
|             throws GuacamoleException { | ||||
|         return Collections.<ConnectionRecord>emptyList(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ConnectionRecordSet contains(String value) | ||||
|             throws GuacamoleException { | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ConnectionRecordSet limit(int limit) | ||||
|             throws GuacamoleException { | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ConnectionRecordSet sort(SortableProperty property, boolean desc) | ||||
|             throws GuacamoleException { | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,143 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import java.util.Map; | ||||
| import java.util.Set; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.GuacamoleSecurityException; | ||||
| import org.apache.guacamole.net.auth.Directory; | ||||
| import org.apache.guacamole.net.auth.Identifiable; | ||||
|  | ||||
| /** | ||||
|  * An extremely simple read-only implementation of a Directory which provides | ||||
|  * access to a pre-defined Map of arbitrary objects. Any changes to the Map | ||||
|  * will affect the available contents of this SimpleDirectory. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  * @param <ObjectType> | ||||
|  *     The type of objects stored within this SimpleDirectory. | ||||
|  */ | ||||
| public class SimpleDirectory<ObjectType extends Identifiable> | ||||
|         implements Directory<ObjectType> { | ||||
|  | ||||
|     /** | ||||
|      * The Map of objects to provide access to. | ||||
|      */ | ||||
|     private Map<String, ObjectType> objects = Collections.<String, ObjectType>emptyMap(); | ||||
|  | ||||
|     /** | ||||
|      * Creates a new empty SimpleDirectory which does not provide access to | ||||
|      * any objects. | ||||
|      */ | ||||
|     public SimpleDirectory() { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleDirectory which provides access to the objects | ||||
|      * contained within the given Map. | ||||
|      * | ||||
|      * @param objects | ||||
|      *     The Map of objects to provide access to. | ||||
|      */ | ||||
|     public SimpleDirectory(Map<String, ObjectType> objects) { | ||||
|         this.objects = objects; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the Map which backs this SimpleDirectory. Future function calls | ||||
|      * which retrieve objects from this SimpleDirectory will use the provided | ||||
|      * Map. | ||||
|      * | ||||
|      * @param objects | ||||
|      *     The Map of objects to provide access to. | ||||
|      */ | ||||
|     protected void setObjects(Map<String, ObjectType> objects) { | ||||
|         this.objects = objects; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the Map which currently backs this SimpleDirectory. Changes to | ||||
|      * this Map will affect future function calls that retrieve objects from | ||||
|      * this SimpleDirectory. | ||||
|      * | ||||
|      * @return | ||||
|      *     The Map of objects which currently backs this SimpleDirectory. | ||||
|      */ | ||||
|     protected Map<String, ObjectType> getObjects() { | ||||
|         return objects; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ObjectType get(String identifier) | ||||
|             throws GuacamoleException { | ||||
|         return objects.get(identifier); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<ObjectType> getAll(Collection<String> identifiers) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         // Create collection which has an appropriate initial size | ||||
|         Collection<ObjectType> foundObjects = new ArrayList<ObjectType>(identifiers.size()); | ||||
|  | ||||
|         // Populate collection with matching objects | ||||
|         for (String identifier : identifiers) { | ||||
|  | ||||
|             // Add the object which has the current identifier, if any | ||||
|             ObjectType object = objects.get(identifier); | ||||
|             if (object != null) | ||||
|                 foundObjects.add(object); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         return foundObjects; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Set<String> getIdentifiers() throws GuacamoleException { | ||||
|         return objects.keySet(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void add(ObjectType connection) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void update(ObjectType connection) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void remove(String identifier) throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,142 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import java.util.Set; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.GuacamoleSecurityException; | ||||
| import org.apache.guacamole.net.auth.permission.ObjectPermission; | ||||
| import org.apache.guacamole.net.auth.permission.ObjectPermissionSet; | ||||
|  | ||||
| /** | ||||
|  * A read-only implementation of ObjectPermissionSet which uses a backing Set | ||||
|  * of Permissions to determine which permissions are present. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SimpleObjectPermissionSet implements ObjectPermissionSet { | ||||
|  | ||||
|     /** | ||||
|      * The set of all permissions currently granted. | ||||
|      */ | ||||
|     private Set<ObjectPermission> permissions = Collections.<ObjectPermission>emptySet(); | ||||
|  | ||||
|     /** | ||||
|      * Creates a new empty SimpleObjectPermissionSet. | ||||
|      */ | ||||
|     public SimpleObjectPermissionSet() { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleObjectPermissionSet which contains the permissions | ||||
|      * within the given Set. | ||||
|      * | ||||
|      * @param permissions  | ||||
|      *     The Set of permissions this SimpleObjectPermissionSet should | ||||
|      *     contain. | ||||
|      */ | ||||
|     public SimpleObjectPermissionSet(Set<ObjectPermission> permissions) { | ||||
|         this.permissions = permissions; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the Set which backs this SimpleObjectPermissionSet. Future function | ||||
|      * calls on this SimpleObjectPermissionSet will use the provided Set. | ||||
|      * | ||||
|      * @param permissions  | ||||
|      *     The Set of permissions this SimpleObjectPermissionSet should | ||||
|      *     contain. | ||||
|      */ | ||||
|     protected void setPermissions(Set<ObjectPermission> permissions) { | ||||
|         this.permissions = permissions; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Set<ObjectPermission> getPermissions() { | ||||
|         return permissions; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean hasPermission(ObjectPermission.Type permission, | ||||
|             String identifier) throws GuacamoleException { | ||||
|  | ||||
|         ObjectPermission objectPermission = | ||||
|                 new ObjectPermission(permission, identifier); | ||||
|          | ||||
|         return permissions.contains(objectPermission); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addPermission(ObjectPermission.Type permission, | ||||
|             String identifier) throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void removePermission(ObjectPermission.Type permission, | ||||
|             String identifier) throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<String> getAccessibleObjects( | ||||
|             Collection<ObjectPermission.Type> permissionTypes, | ||||
|             Collection<String> identifiers) throws GuacamoleException { | ||||
|  | ||||
|         Collection<String> accessibleObjects = new ArrayList<String>(permissions.size()); | ||||
|  | ||||
|         // For each identifier/permission combination | ||||
|         for (String identifier : identifiers) { | ||||
|             for (ObjectPermission.Type permissionType : permissionTypes) { | ||||
|  | ||||
|                 // Add identifier if at least one requested permission is granted | ||||
|                 ObjectPermission permission = new ObjectPermission(permissionType, identifier); | ||||
|                 if (permissions.contains(permission)) { | ||||
|                     accessibleObjects.add(identifier); | ||||
|                     break; | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return accessibleObjects; | ||||
|          | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addPermissions(Set<ObjectPermission> permissions) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void removePermissions(Set<ObjectPermission> permissions) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,113 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.Collections; | ||||
| import java.util.Set; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.GuacamoleSecurityException; | ||||
| import org.apache.guacamole.net.auth.permission.SystemPermission; | ||||
| import org.apache.guacamole.net.auth.permission.SystemPermissionSet; | ||||
|  | ||||
| /** | ||||
|  * A read-only implementation of SystemPermissionSet which uses a backing Set | ||||
|  * of Permissions to determine which permissions are present. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SimpleSystemPermissionSet implements SystemPermissionSet { | ||||
|  | ||||
|     /** | ||||
|      * The set of all permissions currently granted. | ||||
|      */ | ||||
|     private Set<SystemPermission> permissions = Collections.<SystemPermission>emptySet(); | ||||
|  | ||||
|     /** | ||||
|      * Creates a new empty SimpleSystemPermissionSet. | ||||
|      */ | ||||
|     public SimpleSystemPermissionSet() { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleSystemPermissionSet which contains the permissions | ||||
|      * within the given Set. | ||||
|      * | ||||
|      * @param permissions  | ||||
|      *     The Set of permissions this SimpleSystemPermissionSet should | ||||
|      *     contain. | ||||
|      */ | ||||
|     public SimpleSystemPermissionSet(Set<SystemPermission> permissions) { | ||||
|         this.permissions = permissions; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the Set which backs this SimpleSystemPermissionSet. Future function | ||||
|      * calls on this SimpleSystemPermissionSet will use the provided Set. | ||||
|      * | ||||
|      * @param permissions  | ||||
|      *     The Set of permissions this SimpleSystemPermissionSet should | ||||
|      *     contain. | ||||
|      */ | ||||
|     protected void setPermissions(Set<SystemPermission> permissions) { | ||||
|         this.permissions = permissions; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Set<SystemPermission> getPermissions() { | ||||
|         return permissions; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean hasPermission(SystemPermission.Type permission) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         SystemPermission systemPermission = new SystemPermission(permission); | ||||
|         return permissions.contains(systemPermission); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addPermission(SystemPermission.Type permission) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void removePermission(SystemPermission.Type permission) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addPermissions(Set<SystemPermission> permissions) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void removePermissions(Set<SystemPermission> permissions) | ||||
|             throws GuacamoleException { | ||||
|         throw new GuacamoleSecurityException("Permission denied."); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,201 @@ | ||||
| /* | ||||
|  * 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.apache.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.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.net.auth.AbstractUser; | ||||
| import org.apache.guacamole.net.auth.permission.ObjectPermission; | ||||
| import org.apache.guacamole.net.auth.permission.ObjectPermissionSet; | ||||
| import org.apache.guacamole.net.auth.permission.SystemPermissionSet; | ||||
|  | ||||
| /** | ||||
|  * An extremely basic User implementation. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SimpleUser extends AbstractUser { | ||||
|  | ||||
|     /** | ||||
|      * All connection permissions granted to this user. | ||||
|      */ | ||||
|     private final Set<ObjectPermission> userPermissions = | ||||
|             new HashSet<ObjectPermission>(); | ||||
|  | ||||
|     /** | ||||
|      * All connection permissions granted to this user. | ||||
|      */ | ||||
|     private final Set<ObjectPermission> connectionPermissions = | ||||
|             new HashSet<ObjectPermission>(); | ||||
|      | ||||
|     /** | ||||
|      * All connection group permissions granted to this user. | ||||
|      */ | ||||
|     private final Set<ObjectPermission> connectionGroupPermissions = | ||||
|             new HashSet<ObjectPermission>(); | ||||
|  | ||||
|     /** | ||||
|      * Creates a completely uninitialized SimpleUser. | ||||
|      */ | ||||
|     public SimpleUser() { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleUser having the given username and no permissions. | ||||
|      * | ||||
|      * @param username | ||||
|      *     The username to assign to this SimpleUser. | ||||
|      */ | ||||
|     public SimpleUser(String username) { | ||||
|  | ||||
|         // Set username | ||||
|         setIdentifier(username); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Adds a new READ permission to the given set of permissions for each of | ||||
|      * the given identifiers. | ||||
|      * | ||||
|      * @param permissions | ||||
|      *     The set of permissions to add READ permissions to. | ||||
|      * | ||||
|      * @param identifiers | ||||
|      *     The identifiers which should each have a corresponding READ | ||||
|      *     permission added to the given set. | ||||
|      */ | ||||
|     private void addReadPermissions(Set<ObjectPermission> permissions, | ||||
|             Collection<String> identifiers) { | ||||
|  | ||||
|         // Add a READ permission to the set for each identifier given | ||||
|         for (String identifier : identifiers) { | ||||
|             permissions.add(new ObjectPermission ( | ||||
|                 ObjectPermission.Type.READ, | ||||
|                 identifier | ||||
|             )); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Creates a new SimpleUser having the given username and READ access to | ||||
|      * the connections and groups having the given identifiers. | ||||
|      * | ||||
|      * @param username | ||||
|      *     The username to assign to this SimpleUser. | ||||
|      * | ||||
|      * @param connectionIdentifiers | ||||
|      *     The identifiers of all connections this user has READ access to. | ||||
|      * | ||||
|      * @param connectionGroupIdentifiers | ||||
|      *     The identifiers of all connection groups this user has READ access | ||||
|      *     to. | ||||
|      */ | ||||
|     public SimpleUser(String username, | ||||
|             Collection<String> connectionIdentifiers, | ||||
|             Collection<String> connectionGroupIdentifiers) { | ||||
|  | ||||
|         this(username); | ||||
|  | ||||
|         // Add permissions | ||||
|         addReadPermissions(connectionPermissions,      connectionIdentifiers); | ||||
|         addReadPermissions(connectionGroupPermissions, connectionGroupIdentifiers); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleUser having the given username and READ access to | ||||
|      * the users, connections, and groups having the given identifiers. | ||||
|      * | ||||
|      * @param username | ||||
|      *     The username to assign to this SimpleUser. | ||||
|      * | ||||
|      * @param userIdentifiers | ||||
|      *     The identifiers of all users this user has READ access to. | ||||
|      * | ||||
|      * @param connectionIdentifiers | ||||
|      *     The identifiers of all connections this user has READ access to. | ||||
|      * | ||||
|      * @param connectionGroupIdentifiers | ||||
|      *     The identifiers of all connection groups this user has READ access | ||||
|      *     to. | ||||
|      */ | ||||
|     public SimpleUser(String username, | ||||
|             Collection<String> userIdentifiers, | ||||
|             Collection<String> connectionIdentifiers, | ||||
|             Collection<String> connectionGroupIdentifiers) { | ||||
|  | ||||
|         this(username); | ||||
|  | ||||
|         // Add permissions | ||||
|         addReadPermissions(userPermissions,            userIdentifiers); | ||||
|         addReadPermissions(connectionPermissions,      connectionIdentifiers); | ||||
|         addReadPermissions(connectionGroupPermissions, connectionGroupIdentifiers); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Map<String, String> getAttributes() { | ||||
|         return Collections.<String, String>emptyMap(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setAttributes(Map<String, String> attributes) { | ||||
|         // Do nothing - there are no attributes | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public SystemPermissionSet getSystemPermissions() | ||||
|             throws GuacamoleException { | ||||
|         return new SimpleSystemPermissionSet(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ObjectPermissionSet getConnectionPermissions() | ||||
|             throws GuacamoleException { | ||||
|         return new SimpleObjectPermissionSet(connectionPermissions); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ObjectPermissionSet getConnectionGroupPermissions() | ||||
|             throws GuacamoleException { | ||||
|         return new SimpleObjectPermissionSet(connectionGroupPermissions); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ObjectPermissionSet getUserPermissions() | ||||
|             throws GuacamoleException { | ||||
|         return new SimpleObjectPermissionSet(userPermissions); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ObjectPermissionSet getActiveConnectionPermissions() | ||||
|             throws GuacamoleException { | ||||
|         return new SimpleObjectPermissionSet(); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,225 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import java.util.Map; | ||||
| import java.util.UUID; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.form.Form; | ||||
| import org.apache.guacamole.net.auth.ActiveConnection; | ||||
| import org.apache.guacamole.net.auth.AuthenticationProvider; | ||||
| import org.apache.guacamole.net.auth.Connection; | ||||
| import org.apache.guacamole.net.auth.ConnectionGroup; | ||||
| import org.apache.guacamole.net.auth.ConnectionRecordSet; | ||||
| import org.apache.guacamole.net.auth.Directory; | ||||
| import org.apache.guacamole.net.auth.User; | ||||
| import org.apache.guacamole.net.auth.UserContext; | ||||
| import org.apache.guacamole.protocol.GuacamoleConfiguration; | ||||
|  | ||||
| /** | ||||
|  * An extremely simple UserContext implementation which provides access to | ||||
|  * a defined and restricted set of GuacamoleConfigurations. Access to | ||||
|  * querying or modifying either users or permissions is denied. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SimpleUserContext implements UserContext { | ||||
|  | ||||
|     /** | ||||
|      * The unique identifier of the root connection group. | ||||
|      */ | ||||
|     private static final String ROOT_IDENTIFIER = "ROOT"; | ||||
|  | ||||
|     /** | ||||
|      * The AuthenticationProvider that created this UserContext. | ||||
|      */ | ||||
|     private final AuthenticationProvider authProvider; | ||||
|  | ||||
|     /** | ||||
|      * Reference to the user whose permissions dictate the configurations | ||||
|      * accessible within this UserContext. | ||||
|      */ | ||||
|     private final User self; | ||||
|  | ||||
|     /** | ||||
|      * The Directory with access only to the User associated with this | ||||
|      * UserContext. | ||||
|      */ | ||||
|     private final Directory<User> userDirectory; | ||||
|  | ||||
|     /** | ||||
|      * The Directory with access only to the root group associated with this | ||||
|      * UserContext. | ||||
|      */ | ||||
|     private final Directory<ConnectionGroup> connectionGroupDirectory; | ||||
|  | ||||
|     /** | ||||
|      * The Directory with access to all connections within the root group | ||||
|      * associated with this UserContext. | ||||
|      */ | ||||
|     private final Directory<Connection> connectionDirectory; | ||||
|  | ||||
|     /** | ||||
|      * The root connection group. | ||||
|      */ | ||||
|     private final ConnectionGroup rootGroup; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleUserContext which provides access to only those | ||||
|      * configurations within the given Map. The username is assigned | ||||
|      * arbitrarily. | ||||
|      * | ||||
|      * @param authProvider | ||||
|      *     The AuthenticationProvider creating this UserContext. | ||||
|      * | ||||
|      * @param configs | ||||
|      *     A Map of all configurations for which the user associated with this | ||||
|      *     UserContext has read access. | ||||
|      */ | ||||
|     public SimpleUserContext(AuthenticationProvider authProvider, | ||||
|             Map<String, GuacamoleConfiguration> configs) { | ||||
|         this(authProvider, UUID.randomUUID().toString(), configs); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleUserContext for the user with the given username | ||||
|      * which provides access to only those configurations within the given Map. | ||||
|      * | ||||
|      * @param authProvider | ||||
|      *     The AuthenticationProvider creating this UserContext. | ||||
|      * | ||||
|      * @param username | ||||
|      *     The username of the user associated with this UserContext. | ||||
|      * | ||||
|      * @param configs | ||||
|      *     A Map of all configurations for which the user associated with | ||||
|      *     this UserContext has read access. | ||||
|      */ | ||||
|     public SimpleUserContext(AuthenticationProvider authProvider, | ||||
|             String username, Map<String, GuacamoleConfiguration> configs) { | ||||
|  | ||||
|         Collection<String> connectionIdentifiers = new ArrayList<String>(configs.size()); | ||||
|         Collection<String> connectionGroupIdentifiers = Collections.singleton(ROOT_IDENTIFIER); | ||||
|          | ||||
|         // Produce collection of connections from given configs | ||||
|         Collection<Connection> connections = new ArrayList<Connection>(configs.size()); | ||||
|         for (Map.Entry<String, GuacamoleConfiguration> configEntry : configs.entrySet()) { | ||||
|  | ||||
|             // Get connection identifier and configuration | ||||
|             String identifier = configEntry.getKey(); | ||||
|             GuacamoleConfiguration config = configEntry.getValue(); | ||||
|  | ||||
|             // Add as simple connection | ||||
|             Connection connection = new SimpleConnection(identifier, identifier, config); | ||||
|             connection.setParentIdentifier(ROOT_IDENTIFIER); | ||||
|             connections.add(connection); | ||||
|  | ||||
|             // Add identifier to overall set of identifiers | ||||
|             connectionIdentifiers.add(identifier); | ||||
|              | ||||
|         } | ||||
|          | ||||
|         // Add root group that contains only the given configurations | ||||
|         this.rootGroup = new SimpleConnectionGroup( | ||||
|             ROOT_IDENTIFIER, ROOT_IDENTIFIER, | ||||
|             connectionIdentifiers, Collections.<String>emptyList() | ||||
|         ); | ||||
|  | ||||
|         // Build new user from credentials | ||||
|         this.self = new SimpleUser(username, connectionIdentifiers, | ||||
|                 connectionGroupIdentifiers); | ||||
|  | ||||
|         // Create directories for new user | ||||
|         this.userDirectory = new SimpleUserDirectory(self); | ||||
|         this.connectionDirectory = new SimpleConnectionDirectory(connections); | ||||
|         this.connectionGroupDirectory = new SimpleConnectionGroupDirectory(Collections.singleton(this.rootGroup)); | ||||
|  | ||||
|         // Associate provided AuthenticationProvider | ||||
|         this.authProvider = authProvider; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public User self() { | ||||
|         return self; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public AuthenticationProvider getAuthenticationProvider() { | ||||
|         return authProvider; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Directory<User> getUserDirectory() | ||||
|             throws GuacamoleException { | ||||
|         return userDirectory; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Directory<Connection> getConnectionDirectory() | ||||
|             throws GuacamoleException { | ||||
|         return connectionDirectory; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Directory<ConnectionGroup> getConnectionGroupDirectory() | ||||
|             throws GuacamoleException { | ||||
|         return connectionGroupDirectory; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ConnectionGroup getRootConnectionGroup() throws GuacamoleException { | ||||
|         return rootGroup; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Directory<ActiveConnection> getActiveConnectionDirectory() | ||||
|             throws GuacamoleException { | ||||
|         return new SimpleDirectory<ActiveConnection>(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ConnectionRecordSet getConnectionHistory() | ||||
|             throws GuacamoleException { | ||||
|         return new SimpleConnectionRecordSet(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<Form> getUserAttributes() { | ||||
|         return Collections.<Form>emptyList(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<Form> getConnectionAttributes() { | ||||
|         return Collections.<Form>emptyList(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<Form> getConnectionGroupAttributes() { | ||||
|         return Collections.<Form>emptyList(); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,46 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| import java.util.Collections; | ||||
| import org.apache.guacamole.net.auth.User; | ||||
|  | ||||
| /** | ||||
|  * An extremely simple read-only implementation of a Directory of Users which | ||||
|  * provides access to a single pre-defined User. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class SimpleUserDirectory extends SimpleDirectory<User> { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new SimpleUserDirectory which provides access to the single | ||||
|      * user provided. | ||||
|      * | ||||
|      * @param user The user to provide access to. | ||||
|      */ | ||||
|     public SimpleUserDirectory(User user) { | ||||
|         super(Collections.singletonMap(user.getIdentifier(), user)); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,29 @@ | ||||
| /* | ||||
|  * 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 a basic AuthenticationProvider base class that can be used to create | ||||
|  * simple AuthenticationProviders in the same way allowed by the old | ||||
|  * authentication API. | ||||
|  */ | ||||
| package org.apache.guacamole.net.auth.simple; | ||||
|  | ||||
| @@ -0,0 +1,56 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event; | ||||
|  | ||||
| import org.apache.guacamole.net.auth.Credentials; | ||||
|  | ||||
| /** | ||||
|  * An event which is triggered whenever a user's credentials fail to be | ||||
|  * authenticated. The credentials that failed to be authenticated are included | ||||
|  * within this event, and can be retrieved using getCredentials(). | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class AuthenticationFailureEvent implements CredentialEvent { | ||||
|  | ||||
|     /** | ||||
|      * The credentials which failed authentication. | ||||
|      */ | ||||
|     private Credentials credentials; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new AuthenticationFailureEvent which represents the failure | ||||
|      * to authenticate the given credentials. | ||||
|      * | ||||
|      * @param credentials The credentials which failed authentication. | ||||
|      */ | ||||
|     public AuthenticationFailureEvent(Credentials credentials) { | ||||
|         this.credentials = credentials; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Credentials getCredentials() { | ||||
|         return credentials; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,71 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event; | ||||
|  | ||||
| import org.apache.guacamole.net.auth.Credentials; | ||||
| import org.apache.guacamole.net.auth.UserContext; | ||||
|  | ||||
| /** | ||||
|  * An event which is triggered whenever a user's credentials pass | ||||
|  * authentication. The credentials that passed authentication are included | ||||
|  * within this event, and can be retrieved using getCredentials(). | ||||
|  *  | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class AuthenticationSuccessEvent implements UserEvent, CredentialEvent { | ||||
|  | ||||
|     /** | ||||
|      * The UserContext associated with the request that is connecting the | ||||
|      * tunnel, if any. | ||||
|      */ | ||||
|     private UserContext context; | ||||
|  | ||||
|     /** | ||||
|      * The credentials which passed authentication. | ||||
|      */ | ||||
|     private Credentials credentials; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new AuthenticationSuccessEvent which represents a successful | ||||
|      * authentication attempt with the given credentials. | ||||
|      * | ||||
|      * @param context The UserContext created as a result of successful | ||||
|      *                authentication. | ||||
|      * @param credentials The credentials which passed authentication. | ||||
|      */ | ||||
|     public AuthenticationSuccessEvent(UserContext context, Credentials credentials) { | ||||
|         this.context = context; | ||||
|         this.credentials = credentials; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UserContext getUserContext() { | ||||
|         return context; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Credentials getCredentials() { | ||||
|         return credentials; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,43 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event; | ||||
|  | ||||
| import org.apache.guacamole.net.auth.Credentials; | ||||
|  | ||||
| /** | ||||
|  * Abstract basis for events which may have associated user credentials when | ||||
|  * triggered. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface CredentialEvent { | ||||
|  | ||||
|     /** | ||||
|      * Returns the current credentials of the user triggering the event, if any. | ||||
|      * | ||||
|      * @return The current credentials of the user triggering the event, if | ||||
|      *         any, or null if no credentials are associated with the event. | ||||
|      */ | ||||
|     Credentials getCredentials(); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,88 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event; | ||||
|  | ||||
| import org.apache.guacamole.net.GuacamoleTunnel; | ||||
| import org.apache.guacamole.net.auth.Credentials; | ||||
| import org.apache.guacamole.net.auth.UserContext; | ||||
|  | ||||
| /** | ||||
|  * An event which is triggered whenever a tunnel is being closed. The tunnel | ||||
|  * being closed can be accessed through getTunnel(), and the UserContext | ||||
|  * associated with the request which is closing the tunnel can be retrieved | ||||
|  * with getUserContext(). | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class TunnelCloseEvent implements UserEvent, CredentialEvent, TunnelEvent { | ||||
|  | ||||
|     /** | ||||
|      * The UserContext associated with the request that is closing the | ||||
|      * tunnel, if any. | ||||
|      */ | ||||
|     private UserContext context; | ||||
|  | ||||
|     /** | ||||
|      * The credentials associated with the request that connected the | ||||
|      * tunnel, if any. | ||||
|      */ | ||||
|     private Credentials credentials; | ||||
|  | ||||
|     /** | ||||
|      * The tunnel being closed. | ||||
|      */ | ||||
|     private GuacamoleTunnel tunnel; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new TunnelCloseEvent which represents the closing of the | ||||
|      * given tunnel via a request associated with the given credentials. | ||||
|      * | ||||
|      * @param context The UserContext associated with the request closing  | ||||
|      *                the tunnel. | ||||
|      * @param credentials The credentials associated with the request that  | ||||
|      *                    connected the tunnel. | ||||
|      * @param tunnel The tunnel being closed. | ||||
|      */ | ||||
|     public TunnelCloseEvent(UserContext context, Credentials credentials, | ||||
|             GuacamoleTunnel tunnel) { | ||||
|         this.context = context; | ||||
|         this.credentials = credentials; | ||||
|         this.tunnel = tunnel; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UserContext getUserContext() { | ||||
|         return context; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Credentials getCredentials() { | ||||
|         return credentials; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public GuacamoleTunnel getTunnel() { | ||||
|         return tunnel; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,88 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event; | ||||
|  | ||||
| import org.apache.guacamole.net.GuacamoleTunnel; | ||||
| import org.apache.guacamole.net.auth.Credentials; | ||||
| import org.apache.guacamole.net.auth.UserContext; | ||||
|  | ||||
| /** | ||||
|  * An event which is triggered whenever a tunnel is being connected. The tunnel | ||||
|  * being connected can be accessed through getTunnel(), and the UserContext | ||||
|  * associated with the request which is connecting the tunnel can be retrieved | ||||
|  * with getUserContext(). | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class TunnelConnectEvent implements UserEvent, CredentialEvent, TunnelEvent { | ||||
|  | ||||
|     /** | ||||
|      * The UserContext associated with the request that is connecting the | ||||
|      * tunnel, if any. | ||||
|      */ | ||||
|     private UserContext context; | ||||
|  | ||||
|     /** | ||||
|      * The credentials associated with the request that is connecting the | ||||
|      * tunnel, if any. | ||||
|      */ | ||||
|     private Credentials credentials; | ||||
|  | ||||
|     /** | ||||
|      * The tunnel being connected. | ||||
|      */ | ||||
|     private GuacamoleTunnel tunnel; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new TunnelConnectEvent which represents the connecting of the | ||||
|      * given tunnel via a request associated with the given credentials. | ||||
|      * | ||||
|      * @param context The UserContext associated with the request connecting | ||||
|      *                the tunnel. | ||||
|      * @param credentials The credentials associated with the request connecting | ||||
|      *                    the tunnel. | ||||
|      * @param tunnel The tunnel being connected. | ||||
|      */ | ||||
|     public TunnelConnectEvent(UserContext context, Credentials credentials, | ||||
|             GuacamoleTunnel tunnel) { | ||||
|         this.context = context; | ||||
|         this.credentials = credentials; | ||||
|         this.tunnel = tunnel; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UserContext getUserContext() { | ||||
|         return context; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Credentials getCredentials() { | ||||
|         return credentials; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public GuacamoleTunnel getTunnel() { | ||||
|         return tunnel; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,42 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event; | ||||
|  | ||||
| import org.apache.guacamole.net.GuacamoleTunnel; | ||||
|  | ||||
| /** | ||||
|  * Abstract basis for events associated with tunnels. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface TunnelEvent { | ||||
|  | ||||
|     /** | ||||
|      * Returns the tunnel associated with this event, if any. | ||||
|      * | ||||
|      * @return The tunnel associated with this event, if any, or null if no | ||||
|      *         tunnel is associated with this event. | ||||
|      */ | ||||
|     GuacamoleTunnel getTunnel(); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,43 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event; | ||||
|  | ||||
| import org.apache.guacamole.net.auth.UserContext; | ||||
|  | ||||
| /** | ||||
|  * Abstract basis for events which may have an associated UserContext when | ||||
|  * triggered. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface UserEvent { | ||||
|  | ||||
|     /** | ||||
|      * Returns the current UserContext of the user triggering the event, if any. | ||||
|      * | ||||
|      * @return The current UserContext of the user triggering the event, if | ||||
|      *         any, or null if no UserContext is associated with the event. | ||||
|      */ | ||||
|     UserContext getUserContext(); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,51 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event.listener; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.net.event.AuthenticationFailureEvent; | ||||
|  | ||||
| /** | ||||
|  * A listener whose authenticationFailed() hook will fire immediately | ||||
|  * after a user's authentication attempt fails. Note that this hook cannot | ||||
|  * be used to cancel the authentication failure. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface AuthenticationFailureListener  { | ||||
|  | ||||
|     /** | ||||
|      * Event hook which fires immediately after a user's authentication attempt | ||||
|      * fails. | ||||
|      * | ||||
|      * @param e The AuthenticationFailureEvent describing the authentication | ||||
|      *          failure that just occurred. | ||||
|      * @throws GuacamoleException If an error occurs while handling the | ||||
|      *                            authentication failure event. Note that | ||||
|      *                            throwing an exception will NOT cause the | ||||
|      *                            authentication failure to be canceled. | ||||
|      */ | ||||
|     void authenticationFailed(AuthenticationFailureEvent e) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,56 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event.listener; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.net.event.AuthenticationSuccessEvent; | ||||
|  | ||||
| /** | ||||
|  * A listener whose hooks will fire immediately before and after a user's | ||||
|  * authentication attempt succeeds. If a user successfully authenticates, | ||||
|  * the authenticationSucceeded() hook has the opportunity to cancel the | ||||
|  * authentication and force it to fail. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface AuthenticationSuccessListener { | ||||
|  | ||||
|     /** | ||||
|      * Event hook which fires immediately after a user's authentication attempt | ||||
|      * succeeds. The return value of this hook dictates whether the | ||||
|      * successful authentication attempt is canceled. | ||||
|      * | ||||
|      * @param e The AuthenticationFailureEvent describing the authentication | ||||
|      *          failure that just occurred. | ||||
|      * @return true if the successful authentication attempt should be | ||||
|      *         allowed, or false if the attempt should be denied, causing | ||||
|      *         the attempt to effectively fail. | ||||
|      * @throws GuacamoleException If an error occurs while handling the | ||||
|      *                            authentication success event. Throwing an | ||||
|      *                            exception will also cancel the authentication | ||||
|      *                            success. | ||||
|      */ | ||||
|     boolean authenticationSucceeded(AuthenticationSuccessEvent e) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,53 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event.listener; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.net.event.TunnelCloseEvent; | ||||
|  | ||||
| /** | ||||
|  * A listener whose tunnelClosed() hook will fire immediately after an | ||||
|  * existing tunnel is closed. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface TunnelCloseListener { | ||||
|  | ||||
|     /** | ||||
|      * Event hook which fires immediately after an existing tunnel is closed. | ||||
|      * The return value of this hook dictates whether the tunnel is allowed to | ||||
|      * be closed. | ||||
|      * | ||||
|      * @param e The TunnelCloseEvent describing the tunnel being closed and | ||||
|      *          any associated credentials. | ||||
|      * @return true if the tunnel should be allowed to be closed, or false | ||||
|      *         if the attempt should be denied, causing the attempt to | ||||
|      *         effectively fail. | ||||
|      * @throws GuacamoleException If an error occurs while handling the | ||||
|      *                            tunnel close event. Throwing an exception | ||||
|      *                            will also stop the tunnel from being closed. | ||||
|      */ | ||||
|     boolean tunnelClosed(TunnelCloseEvent e) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,54 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.net.event.listener; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.net.event.TunnelConnectEvent; | ||||
|  | ||||
| /** | ||||
|  * A listener whose tunnelConnected() hook will fire immediately after a new | ||||
|  * tunnel is connected. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public interface TunnelConnectListener { | ||||
|  | ||||
|    /** | ||||
|      * Event hook which fires immediately after a new tunnel is connected. | ||||
|      * The return value of this hook dictates whether the tunnel is made visible | ||||
|      * to the session. | ||||
|      * | ||||
|      * @param e The TunnelConnectEvent describing the tunnel being connected and | ||||
|      *          any associated credentials. | ||||
|      * @return true if the tunnel should be allowed to be connected, or false | ||||
|      *         if the attempt should be denied, causing the attempt to | ||||
|      *         effectively fail. | ||||
|      * @throws GuacamoleException If an error occurs while handling the | ||||
|      *                            tunnel connect event. Throwing an exception | ||||
|      *                            will also stop the tunnel from being made | ||||
|      *                            visible to the session. | ||||
|      */ | ||||
|     boolean tunnelConnected(TunnelConnectEvent e) | ||||
|             throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,31 @@ | ||||
| /* | ||||
|  * 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 for hooking into various events that take place as | ||||
|  * users log into and use the Guacamole web application. These event | ||||
|  * hooks can be used to take action upon occurrence of an event and, | ||||
|  * in some cases, prevent the web application from allowing the | ||||
|  * event to continue for the user that triggered it. | ||||
|  */ | ||||
| package org.apache.guacamole.net.event.listener; | ||||
|  | ||||
| @@ -0,0 +1,32 @@ | ||||
| /* | ||||
|  * 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 for storing information about events that are | ||||
|  * triggered when users log into and use the Guacamole web application. | ||||
|  * These event classes are most useful when used with hooks implemented | ||||
|  * using listener classes. | ||||
|  * | ||||
|  * @see org.apache.guacamole.net.event.listener | ||||
|  */ | ||||
| package org.apache.guacamole.net.event; | ||||
|  | ||||
| @@ -0,0 +1,57 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.properties; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.GuacamoleServerException; | ||||
|  | ||||
| /** | ||||
|  * A GuacamoleProperty whose value is an boolean. Legal true values are "true", | ||||
|  * or "false". Case does not matter. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public abstract class BooleanGuacamoleProperty implements GuacamoleProperty<Boolean> { | ||||
|  | ||||
|     @Override | ||||
|     public Boolean parseValue(String value) throws GuacamoleException { | ||||
|  | ||||
|         // If no property provided, return null. | ||||
|         if (value == null) | ||||
|             return null; | ||||
|  | ||||
|         // If "true", return true | ||||
|         if (value.equalsIgnoreCase("true")) | ||||
|             return true; | ||||
|  | ||||
|         // If "false", return false | ||||
|         if (value.equalsIgnoreCase("false")) | ||||
|             return false; | ||||
|  | ||||
|         // Otherwise, fail | ||||
|         throw new GuacamoleServerException("Property \"" + getName() | ||||
|                 + "\" must be either \"true\" or \"false\"."); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,46 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.properties; | ||||
|  | ||||
| import java.io.File; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
|  | ||||
| /** | ||||
|  * A GuacamoleProperty whose value is a filename. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public abstract class FileGuacamoleProperty implements GuacamoleProperty<File> { | ||||
|  | ||||
|     @Override | ||||
|     public File parseValue(String value) throws GuacamoleException { | ||||
|  | ||||
|         // If no property provided, return null. | ||||
|         if (value == null) | ||||
|             return null; | ||||
|  | ||||
|         return new File(value); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,85 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.properties; | ||||
|  | ||||
| import java.io.File; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| /** | ||||
|  * Abstract representation of the Guacamole configuration directory. | ||||
|  * | ||||
|  * @deprecated | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class GuacamoleHome { | ||||
|  | ||||
|     /** | ||||
|      * Logger for this class. | ||||
|      */ | ||||
|     private static final Logger logger = LoggerFactory.getLogger(GuacamoleHome.class); | ||||
|  | ||||
|     static { | ||||
|         // Warn about deprecation | ||||
|         logger.warn("GuacamoleHome is deprecated. Please use Environment instead."); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * GuacamoleHome is a utility class and cannot be instantiated. | ||||
|      */ | ||||
|     private GuacamoleHome() {} | ||||
|  | ||||
|     /** | ||||
|      * Returns the Guacamole home directory by checking, in order: | ||||
|      * the guacamole.home system property, the GUACAMOLE_HOME environment | ||||
|      * variable, and finally the .guacamole directory in the home directory of | ||||
|      * the user running the servlet container. | ||||
|      * | ||||
|      * @return The File representing the Guacamole home directory, which may | ||||
|      *         or may not exist, and may turn out to not be a directory. | ||||
|      */ | ||||
|     public static File getDirectory() { | ||||
|  | ||||
|         // Attempt to find Guacamole home | ||||
|         File guacHome; | ||||
|  | ||||
|         // Use system property by default | ||||
|         String desiredDir = System.getProperty("guacamole.home"); | ||||
|  | ||||
|         // Failing that, try the GUACAMOLE_HOME environment variable | ||||
|         if (desiredDir == null) desiredDir = System.getenv("GUACAMOLE_HOME"); | ||||
|  | ||||
|         // If successful, use explicitly specified directory | ||||
|         if (desiredDir != null) | ||||
|             guacHome = new File(desiredDir); | ||||
|  | ||||
|         // If not explicitly specified, use ~/.guacamole | ||||
|         else | ||||
|             guacHome = new File(System.getProperty("user.home"), ".guacamole"); | ||||
|  | ||||
|         // Return discovered directory | ||||
|         return guacHome; | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,218 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.properties; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.util.Properties; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.GuacamoleServerException; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| /** | ||||
|  * Simple utility class for reading properties from the guacamole.properties | ||||
|  * file. The guacamole.properties file is preferably located in the servlet | ||||
|  * container's user's home directory, in a subdirectory called .guacamole, or | ||||
|  * in the directory set by the system property: guacamole.home. | ||||
|  * | ||||
|  * If none of those locations are possible, guacamole.properties will also | ||||
|  * be read from the root of the classpath. | ||||
|  * | ||||
|  * @deprecated | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class GuacamoleProperties { | ||||
|  | ||||
|     /** | ||||
|      * Logger for this class. | ||||
|      */ | ||||
|     private static final Logger logger = LoggerFactory.getLogger(GuacamoleProperties.class); | ||||
|  | ||||
|     static { | ||||
|         // Warn about deprecation | ||||
|         logger.warn("GuacamoleProperties is deprecated. Please use Environment instead."); | ||||
|     } | ||||
|   | ||||
|     /** | ||||
|      * GuacamoleProperties is a utility class and cannot be instantiated. | ||||
|      */ | ||||
|     private GuacamoleProperties() {} | ||||
|  | ||||
|     /** | ||||
|      * The hostname of the server where guacd (the Guacamole proxy server) is | ||||
|      * running. | ||||
|      */ | ||||
|     public static final StringGuacamoleProperty GUACD_HOSTNAME = new StringGuacamoleProperty() { | ||||
|  | ||||
|         @Override | ||||
|         public String getName() { return "guacd-hostname"; } | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * The port that guacd (the Guacamole proxy server) is listening on. | ||||
|      */ | ||||
|     public static final IntegerGuacamoleProperty GUACD_PORT = new IntegerGuacamoleProperty() { | ||||
|  | ||||
|         @Override | ||||
|         public String getName() { return "guacd-port"; } | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * Whether guacd requires SSL/TLS on connections. | ||||
|      */ | ||||
|     public static final BooleanGuacamoleProperty GUACD_SSL = new BooleanGuacamoleProperty() { | ||||
|  | ||||
|         @Override | ||||
|         public String getName() { return "guacd-ssl"; } | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * All properties read from guacamole.properties when this class was first | ||||
|      * used. | ||||
|      */ | ||||
|     private static final Properties properties; | ||||
|  | ||||
|     /** | ||||
|      * Any error encountered when reading guacamole.properties was last | ||||
|      * attempted. | ||||
|      */ | ||||
|     private static GuacamoleException exception; | ||||
|  | ||||
|     static { | ||||
|  | ||||
|         properties = new Properties(); | ||||
|  | ||||
|         try { | ||||
|  | ||||
|             // Attempt to find Guacamole home | ||||
|             File guacHome = GuacamoleHome.getDirectory(); | ||||
|  | ||||
|             InputStream stream; | ||||
|  | ||||
|             // If not a directory, load from classpath | ||||
|             if (!guacHome.isDirectory()) { | ||||
|  | ||||
|                 // Read from classpath | ||||
|                 stream = GuacamoleProperties.class.getResourceAsStream("/guacamole.properties"); | ||||
|                 if (stream == null) | ||||
|                     throw new IOException( | ||||
|                         "guacamole.properties not loaded from " + guacHome | ||||
|                       + " (not a directory), and guacamole.properties could" | ||||
|                       + " not be found as a resource in the classpath."); | ||||
|  | ||||
|             } | ||||
|  | ||||
|             // Otherwise, try to load from file | ||||
|             else | ||||
|                 stream = new FileInputStream(new File(guacHome, "guacamole.properties")); | ||||
|  | ||||
|             // Load properties, always close stream | ||||
|             try { properties.load(stream); } | ||||
|             finally { stream.close(); } | ||||
|  | ||||
|         } | ||||
|         catch (IOException e) { | ||||
|             exception = new GuacamoleServerException("Error reading guacamole.properties", e); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 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. | ||||
|      */ | ||||
|     public static <Type> Type getProperty(GuacamoleProperty<Type> property) throws GuacamoleException { | ||||
|  | ||||
|         if (exception != null) | ||||
|             throw exception; | ||||
|  | ||||
|         return property.parseValue(properties.getProperty(property.getName())); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Given a GuacamoleProperty, parses and returns the value set for that | ||||
|      * 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. | ||||
|      */ | ||||
|     public static <Type> Type getProperty(GuacamoleProperty<Type> property, | ||||
|             Type defaultValue) throws GuacamoleException { | ||||
|  | ||||
|         Type value = getProperty(property); | ||||
|         if (value == null) | ||||
|             return defaultValue; | ||||
|  | ||||
|         return value; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Given a GuacamoleProperty, parses and returns the value set 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 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, or if the property is | ||||
|      *                            not specified. | ||||
|      */ | ||||
|     public static <Type> Type getRequiredProperty(GuacamoleProperty<Type> property) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         Type value = getProperty(property); | ||||
|         if (value == null) | ||||
|             throw new GuacamoleServerException("Property " + property.getName() + " is required."); | ||||
|  | ||||
|         return value; | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,56 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.properties; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
|  | ||||
| /** | ||||
|  * An abstract representation of a property in the guacamole.properties file, | ||||
|  * which parses into a specific type. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  * @param <Type> The type this GuacamoleProperty will parse into. | ||||
|  */ | ||||
| public interface GuacamoleProperty<Type> { | ||||
|  | ||||
|     /** | ||||
|      * Returns the name of the property in guacamole.properties that this | ||||
|      * GuacamoleProperty will parse. | ||||
|      * | ||||
|      * @return The name of the property in guacamole.properties that this | ||||
|      *         GuacamoleProperty will parse. | ||||
|      */ | ||||
|     public String getName(); | ||||
|  | ||||
|     /** | ||||
|      * Parses the given string value into the type associated with this | ||||
|      * GuacamoleProperty. | ||||
|      * | ||||
|      * @param value The string value to parse. | ||||
|      * @return The parsed value. | ||||
|      * @throws GuacamoleException If an error occurs while parsing the | ||||
|      *                            provided value. | ||||
|      */ | ||||
|     public Type parseValue(String value) throws GuacamoleException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,52 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.properties; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.GuacamoleServerException; | ||||
|  | ||||
| /** | ||||
|  * A GuacamoleProperty whose value is an integer. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public abstract class IntegerGuacamoleProperty implements GuacamoleProperty<Integer> { | ||||
|  | ||||
|     @Override | ||||
|     public Integer parseValue(String value) throws GuacamoleException { | ||||
|  | ||||
|         // If no property provided, return null. | ||||
|         if (value == null) | ||||
|             return null; | ||||
|  | ||||
|         try { | ||||
|             Integer integer = new Integer(value); | ||||
|             return integer; | ||||
|         } | ||||
|         catch (NumberFormatException e) { | ||||
|             throw new GuacamoleServerException("Property \"" + getName() + "\" must be an integer.", e); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,52 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.properties; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.GuacamoleServerException; | ||||
|  | ||||
| /** | ||||
|  * A GuacamoleProperty whose value is an long. | ||||
|  * | ||||
|  * @author James Muehlner | ||||
|  */ | ||||
| public abstract class LongGuacamoleProperty implements GuacamoleProperty<Long> { | ||||
|  | ||||
|     @Override | ||||
|     public Long parseValue(String value) throws GuacamoleException { | ||||
|  | ||||
|         // If no property provided, return null. | ||||
|         if (value == null) | ||||
|             return null; | ||||
|  | ||||
|         try { | ||||
|             Long longValue = new Long(value); | ||||
|             return longValue; | ||||
|         } | ||||
|         catch (NumberFormatException e) { | ||||
|             throw new GuacamoleServerException("Property \"" + getName() + "\" must be an long.", e); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,39 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.properties; | ||||
|  | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
|  | ||||
| /** | ||||
|  * A GuacamoleProperty whose value is a simple string. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public abstract class StringGuacamoleProperty implements GuacamoleProperty<String> { | ||||
|  | ||||
|     @Override | ||||
|     public String parseValue(String value) throws GuacamoleException { | ||||
|         return value; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,28 @@ | ||||
| /* | ||||
|  * 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 for reading properties from the web-application-wide | ||||
|  * guacamole.properties file. | ||||
|  */ | ||||
| package org.apache.guacamole.properties; | ||||
|  | ||||
| @@ -0,0 +1,122 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.protocols; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import org.apache.guacamole.form.Form; | ||||
|  | ||||
| /** | ||||
|  * Describes a protocol and all forms associated with it, as required by | ||||
|  * a protocol plugin for guacd. This class allows known forms for a | ||||
|  * protocol to be exposed to the user as friendly fields. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class ProtocolInfo { | ||||
|  | ||||
|     /** | ||||
|      * The unique name associated with this protocol. | ||||
|      */ | ||||
|     private String name; | ||||
|  | ||||
|     /** | ||||
|      * A collection of all associated protocol forms. | ||||
|      */ | ||||
|     private Collection<Form> forms; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new ProtocolInfo with no associated name or forms. | ||||
|      */ | ||||
|     public ProtocolInfo() { | ||||
|         this.forms = new ArrayList<Form>(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new ProtocolInfo having the given name, but without any forms. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name associated with the protocol. | ||||
|      */ | ||||
|     public ProtocolInfo(String name) { | ||||
|         this.name  = name; | ||||
|         this.forms = new ArrayList<Form>(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new ProtocolInfo having the given name and forms. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name associated with the protocol. | ||||
|      * | ||||
|      * @param forms | ||||
|      *     The forms to associate with the protocol. | ||||
|      */ | ||||
|     public ProtocolInfo(String name, Collection<Form> forms) { | ||||
|         this.name  = name; | ||||
|         this.forms = forms; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the unique name of this protocol. The protocol name is the | ||||
|      * value required by the corresponding protocol plugin for guacd. | ||||
|      * | ||||
|      * @return The unique name of this protocol. | ||||
|      */ | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the unique name of this protocol. The protocol name is the value | ||||
|      * required by the corresponding protocol plugin for guacd. | ||||
|      * | ||||
|      * @param name The unique name of this protocol. | ||||
|      */ | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns a mutable collection of the protocol forms associated with | ||||
|      * this protocol. Changes to this collection affect the forms exposed | ||||
|      * to the user. | ||||
|      * | ||||
|      * @return A mutable collection of protocol forms. | ||||
|      */ | ||||
|     public Collection<Form> getForms() { | ||||
|         return forms; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the collection of protocol forms associated with this | ||||
|      * protocol. | ||||
|      * | ||||
|      * @param forms | ||||
|      *     The collection of forms to associate with this protocol. | ||||
|      */ | ||||
|     public void setForms(Collection<Form> forms) { | ||||
|         this.forms = forms; | ||||
|     } | ||||
|      | ||||
| } | ||||
| @@ -0,0 +1,126 @@ | ||||
| /* | ||||
|  * Copyright (C) 2016 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.apache.guacamole.token; | ||||
|  | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | ||||
| import org.apache.guacamole.net.auth.Credentials; | ||||
|  | ||||
| /** | ||||
|  * Utility class which provides access to standardized token names, as well as | ||||
|  * facilities for generating those tokens from common objects. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class StandardTokens { | ||||
|  | ||||
|     /** | ||||
|      * The name of the username token added via addStandardTokens(). | ||||
|      */ | ||||
|     public static final String USERNAME_TOKEN = "GUAC_USERNAME"; | ||||
|  | ||||
|     /** | ||||
|      * The name of the password token added via addStandardTokens(). | ||||
|      */ | ||||
|     public static final String PASSWORD_TOKEN = "GUAC_PASSWORD"; | ||||
|  | ||||
|     /** | ||||
|      * The name of the date token (server-local time) added via | ||||
|      * addStandardTokens(). | ||||
|      */ | ||||
|     public static final String DATE_TOKEN = "GUAC_DATE"; | ||||
|  | ||||
|     /** | ||||
|      * The name of the time token (server-local time) added via | ||||
|      * addStandardTokens(). | ||||
|      */ | ||||
|     public static final String TIME_TOKEN = "GUAC_TIME"; | ||||
|  | ||||
|     /** | ||||
|      * The date format that should be used for the date token. This format must | ||||
|      * be compatible with Java's SimpleDateFormat. | ||||
|      */ | ||||
|     private static final String DATE_FORMAT = "yyyyMMdd"; | ||||
|  | ||||
|     /** | ||||
|      * The date format that should be used for the time token. This format must | ||||
|      * be compatible with Java's SimpleDateFormat. | ||||
|      */ | ||||
|     private static final String TIME_FORMAT = "HHmmss"; | ||||
|  | ||||
|     /** | ||||
|      * This utility class should not be instantiated. | ||||
|      */ | ||||
|     private StandardTokens() {} | ||||
|  | ||||
|     /** | ||||
|      * Adds tokens which are standardized by guacamole-ext to the given | ||||
|      * TokenFilter and which do not require a corresponding Credentials object. | ||||
|      * These the server date and time (GUAC_DATE and GUAC_TIME respectively). | ||||
|      * | ||||
|      * @param filter | ||||
|      *     The TokenFilter to add standard tokens to. | ||||
|      */ | ||||
|     public static void addStandardTokens(TokenFilter filter) { | ||||
|  | ||||
|         // Add date/time tokens (server-local time) | ||||
|         Date currentTime = new Date(); | ||||
|         filter.setToken(DATE_TOKEN, new SimpleDateFormat(DATE_FORMAT).format(currentTime)); | ||||
|         filter.setToken(TIME_TOKEN, new SimpleDateFormat(TIME_FORMAT).format(currentTime)); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Adds tokens which are standardized by guacamole-ext to the given | ||||
|      * TokenFilter using the values from the given Credentials object. These | ||||
|      * standardized tokens include the current username (GUAC_USERNAME), | ||||
|      * password (GUAC_PASSWORD), and the server date and time (GUAC_DATE and | ||||
|      * GUAC_TIME respectively). If either the username or password are not set | ||||
|      * within the given credentials, the corresponding token(s) will remain | ||||
|      * unset. | ||||
|      * | ||||
|      * @param filter | ||||
|      *     The TokenFilter to add standard tokens to. | ||||
|      * | ||||
|      * @param credentials | ||||
|      *     The Credentials to use when populating the GUAC_USERNAME and | ||||
|      *     GUAC_PASSWORD tokens. | ||||
|      */ | ||||
|     public static void addStandardTokens(TokenFilter filter, Credentials credentials) { | ||||
|  | ||||
|         // Add username token | ||||
|         String username = credentials.getUsername(); | ||||
|         if (username != null) | ||||
|             filter.setToken(USERNAME_TOKEN, username); | ||||
|  | ||||
|         // Add password token | ||||
|         String password = credentials.getPassword(); | ||||
|         if (password != null) | ||||
|             filter.setToken(PASSWORD_TOKEN, password); | ||||
|  | ||||
|         // Add any tokens which do not require credentials | ||||
|         addStandardTokens(filter); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,234 @@ | ||||
| /* | ||||
|  * 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.apache.guacamole.token; | ||||
|  | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.regex.Matcher; | ||||
| import java.util.regex.Pattern; | ||||
|  | ||||
| /** | ||||
|  * Filtering object which replaces tokens of the form "${TOKEN_NAME}" with | ||||
|  * their corresponding values. Unknown tokens are not replaced. If TOKEN_NAME | ||||
|  * is a valid token, the literal value "${TOKEN_NAME}" can be included by using | ||||
|  * "$${TOKEN_NAME}". | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class TokenFilter { | ||||
|  | ||||
|     /** | ||||
|      * Regular expression which matches individual tokens, with additional | ||||
|      * capturing groups for convenient retrieval of leading text, the possible | ||||
|      * escape character preceding the token, the name of the token, and the | ||||
|      * entire token itself. | ||||
|      */ | ||||
|     private final Pattern tokenPattern = Pattern.compile("(.*?)(^|.)(\\$\\{([A-Za-z0-9_]*)\\})"); | ||||
|  | ||||
|     /** | ||||
|      * The index of the capturing group within tokenPattern which matches | ||||
|      * non-token text preceding a possible token. | ||||
|      */ | ||||
|     private static final int LEADING_TEXT_GROUP = 1; | ||||
|  | ||||
|     /** | ||||
|      * The index of the capturing group within tokenPattern which matches the | ||||
|      * character immediately preceding a possible token, possibly denoting that | ||||
|      * the token should instead be interpreted as a literal. | ||||
|      */ | ||||
|     private static final int ESCAPE_CHAR_GROUP = 2; | ||||
|  | ||||
|     /** | ||||
|      * The index of the capturing group within tokenPattern which matches the | ||||
|      * entire token, including the leading "${" and terminating "}" strings. | ||||
|      */ | ||||
|     private static final int TOKEN_GROUP = 3; | ||||
|  | ||||
|     /** | ||||
|      * The index of the capturing group within tokenPattern which matches only | ||||
|      * the token name contained within the "${" and "}" strings. | ||||
|      */ | ||||
|     private static final int TOKEN_NAME_GROUP = 4; | ||||
|      | ||||
|     /** | ||||
|      * The values of all known tokens. | ||||
|      */ | ||||
|     private final Map<String, String> tokenValues = new HashMap<String, String>(); | ||||
|  | ||||
|     /** | ||||
|      * Sets the token having the given name to the given value. Any existing | ||||
|      * value for that token is replaced. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The name of the token to set. | ||||
|      * | ||||
|      * @param value | ||||
|      *     The value to set the token to. | ||||
|      */ | ||||
|     public void setToken(String name, String value) { | ||||
|         tokenValues.put(name, value); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the value of the token with the given name, or null if no such | ||||
|      * token has been set. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The name of the token to return. | ||||
|      *  | ||||
|      * @return | ||||
|      *     The value of the token with the given name, or null if no such | ||||
|      *     token exists. | ||||
|      */ | ||||
|     public String getToken(String name) { | ||||
|         return tokenValues.get(name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Removes the value of the token with the given name. If no such token | ||||
|      * exists, this function has no effect. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The name of the token whose value should be removed. | ||||
|      */ | ||||
|     public void unsetToken(String name) { | ||||
|         tokenValues.remove(name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns a map of all tokens, with each key being a token name, and each | ||||
|      * value being the corresponding token value. Changes to this map will | ||||
|      * directly affect the tokens associated with this filter. | ||||
|      * | ||||
|      * @return | ||||
|      *     A map of all token names and their corresponding values. | ||||
|      */ | ||||
|     public Map<String, String> getTokens() { | ||||
|         return tokenValues; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Replaces all current token values with the contents of the given map, | ||||
|      * where each map key represents a token name, and each map value | ||||
|      * represents a token value. | ||||
|      * | ||||
|      * @param tokens | ||||
|      *     A map containing the token names and corresponding values to | ||||
|      *     assign. | ||||
|      */ | ||||
|     public void setTokens(Map<String, String> tokens) { | ||||
|         tokenValues.clear(); | ||||
|         tokenValues.putAll(tokens); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Filters the given string, replacing any tokens with their corresponding | ||||
|      * values. | ||||
|      * | ||||
|      * @param input | ||||
|      *     The string to filter. | ||||
|      * | ||||
|      * @return | ||||
|      *     A copy of the input string, with any tokens replaced with their | ||||
|      *     corresponding values. | ||||
|      */ | ||||
|     public String filter(String input) { | ||||
|  | ||||
|         StringBuilder output = new StringBuilder(); | ||||
|         Matcher tokenMatcher = tokenPattern.matcher(input); | ||||
|  | ||||
|         // Track last regex match | ||||
|         int endOfLastMatch = 0; | ||||
|  | ||||
|         // For each possible token | ||||
|         while (tokenMatcher.find()) { | ||||
|  | ||||
|             // Pull possible leading text and first char before possible token | ||||
|             String literal = tokenMatcher.group(LEADING_TEXT_GROUP); | ||||
|             String escape = tokenMatcher.group(ESCAPE_CHAR_GROUP); | ||||
|  | ||||
|             // Append leading non-token text | ||||
|             output.append(literal); | ||||
|  | ||||
|             // If char before token is '$', the token itself is escaped | ||||
|             if ("$".equals(escape)) { | ||||
|                 String notToken = tokenMatcher.group(TOKEN_GROUP); | ||||
|                 output.append(notToken); | ||||
|             } | ||||
|  | ||||
|             // If char is not '$', interpret as a token | ||||
|             else { | ||||
|  | ||||
|                 // The char before the token, if any, is a literal | ||||
|                 output.append(escape); | ||||
|  | ||||
|                 // Pull token value | ||||
|                 String tokenName = tokenMatcher.group(TOKEN_NAME_GROUP); | ||||
|                 String tokenValue = getToken(tokenName); | ||||
|  | ||||
|                 // If token is unknown, interpret as literal | ||||
|                 if (tokenValue == null) { | ||||
|                     String notToken = tokenMatcher.group(TOKEN_GROUP); | ||||
|                     output.append(notToken); | ||||
|                 } | ||||
|  | ||||
|                 // Otherwise, substitute value | ||||
|                 else | ||||
|                     output.append(tokenValue); | ||||
|  | ||||
|             } | ||||
|  | ||||
|             // Update last regex match | ||||
|             endOfLastMatch = tokenMatcher.end(); | ||||
|              | ||||
|         } | ||||
|  | ||||
|         // Append any remaining non-token text | ||||
|         output.append(input.substring(endOfLastMatch)); | ||||
|          | ||||
|         return output.toString(); | ||||
|         | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Given an arbitrary map containing String values, replace each non-null | ||||
|      * value with the corresponding filtered value. | ||||
|      * | ||||
|      * @param map | ||||
|      *     The map whose values should be filtered. | ||||
|      */ | ||||
|     public void filterValues(Map<?, String> map) { | ||||
|  | ||||
|         // For each map entry | ||||
|         for (Map.Entry<?, String> entry : map.entrySet()) { | ||||
|  | ||||
|             // If value is non-null, filter value through this TokenFilter | ||||
|             String value = entry.getValue(); | ||||
|             if (value != null) | ||||
|                 entry.setValue(filter(value)); | ||||
|              | ||||
|         } | ||||
|          | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,205 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.xml; | ||||
|  | ||||
| import java.util.Deque; | ||||
| import java.util.LinkedList; | ||||
| import org.xml.sax.Attributes; | ||||
| import org.xml.sax.SAXException; | ||||
| import org.xml.sax.helpers.DefaultHandler; | ||||
|  | ||||
| /** | ||||
|  * A simple ContentHandler implementation which digests SAX document events and | ||||
|  * produces simpler tag-level events, maintaining its own stack for the | ||||
|  * convenience of the tag handlers. | ||||
|  * | ||||
|  * @author Mike Jumper | ||||
|  */ | ||||
| public class DocumentHandler extends DefaultHandler { | ||||
|  | ||||
|     /** | ||||
|      * The name of the root element of the document. | ||||
|      */ | ||||
|     private String rootElementName; | ||||
|  | ||||
|     /** | ||||
|      * The handler which will be used to handle element events for the root | ||||
|      * element of the document. | ||||
|      */ | ||||
|     private TagHandler root; | ||||
|  | ||||
|     /** | ||||
|      * The stack of all states applicable to the current parser state. Each | ||||
|      * element of the stack references the TagHandler for the element being | ||||
|      * parsed at that level of the document, where the current element is | ||||
|      * last in the stack, and the root element is first. | ||||
|      */ | ||||
|     private Deque<DocumentHandlerState> stack = | ||||
|             new LinkedList<DocumentHandlerState>(); | ||||
|  | ||||
|     /** | ||||
|      * Creates a new DocumentHandler which will use the given TagHandler | ||||
|      * to handle the root element. | ||||
|      * | ||||
|      * @param rootElementName The name of the root element of the document | ||||
|      *                        being handled. | ||||
|      * @param root The TagHandler to use for the root element. | ||||
|      */ | ||||
|     public DocumentHandler(String rootElementName, TagHandler root) { | ||||
|         this.root = root; | ||||
|         this.rootElementName = rootElementName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the current element state. The current element state is the | ||||
|      * state of the element the parser is currently within. | ||||
|      * | ||||
|      * @return The current element state. | ||||
|      */ | ||||
|     private DocumentHandlerState getCurrentState() { | ||||
|  | ||||
|         // If no state, return null | ||||
|         if (stack.isEmpty()) | ||||
|             return null; | ||||
|  | ||||
|         return stack.getLast(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void startElement(String uri, String localName, String qName, | ||||
|         Attributes attributes) throws SAXException { | ||||
|  | ||||
|         // Get current state | ||||
|         DocumentHandlerState current = getCurrentState(); | ||||
|  | ||||
|         // Handler for tag just read | ||||
|         TagHandler handler; | ||||
|  | ||||
|         // If no stack, use root handler | ||||
|         if (current == null) { | ||||
|  | ||||
|             // Validate element name | ||||
|             if (!localName.equals(rootElementName)) | ||||
|                 throw new SAXException("Root element must be '" + rootElementName + "'"); | ||||
|  | ||||
|             handler = root; | ||||
|         } | ||||
|  | ||||
|         // Otherwise, get handler from parent | ||||
|         else { | ||||
|             TagHandler parent_handler = current.getTagHandler(); | ||||
|             handler = parent_handler.childElement(localName); | ||||
|         } | ||||
|  | ||||
|         // If no handler returned, the element was not expected | ||||
|         if (handler == null) | ||||
|             throw new SAXException("Unexpected element: '" + localName + "'"); | ||||
|  | ||||
|         // Initialize handler | ||||
|         handler.init(attributes); | ||||
|  | ||||
|         // Append new element state to stack | ||||
|         stack.addLast(new DocumentHandlerState(handler)); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void endElement(String uri, String localName, String qName) | ||||
|             throws SAXException { | ||||
|  | ||||
|         // Pop last element from stack | ||||
|         DocumentHandlerState completed = stack.removeLast(); | ||||
|  | ||||
|         // Finish element by sending text content | ||||
|         completed.getTagHandler().complete( | ||||
|                 completed.getTextContent().toString()); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void characters(char[] ch, int start, int length) | ||||
|             throws SAXException { | ||||
|  | ||||
|         // Get current state | ||||
|         DocumentHandlerState current = getCurrentState(); | ||||
|         if (current == null) | ||||
|             throw new SAXException("Character data not allowed outside XML document."); | ||||
|          | ||||
|         // Append received chunk to text content | ||||
|         current.getTextContent().append(ch, start, length); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * The current state of the DocumentHandler. | ||||
|      */ | ||||
|     private static class DocumentHandlerState { | ||||
|  | ||||
|         /** | ||||
|          * The current text content of the current element being parsed. | ||||
|          */ | ||||
|         private StringBuilder textContent = new StringBuilder(); | ||||
|  | ||||
|         /** | ||||
|          * The TagHandler which must handle document events related to the | ||||
|          * element currently being parsed. | ||||
|          */ | ||||
|         private TagHandler tagHandler; | ||||
|  | ||||
|         /** | ||||
|          * Creates a new DocumentHandlerState which will maintain the state | ||||
|          * of parsing of the current element, as well as contain the TagHandler | ||||
|          * which will receive events related to that element. | ||||
|          * | ||||
|          * @param tagHandler The TagHandler which should receive any events | ||||
|          *                   related to the element being parsed. | ||||
|          */ | ||||
|         public DocumentHandlerState(TagHandler tagHandler) { | ||||
|             this.tagHandler = tagHandler; | ||||
|         } | ||||
|  | ||||
|         /** | ||||
|          * Returns the mutable StringBuilder which contains the current text | ||||
|          * content of the element being parsed. | ||||
|          * | ||||
|          * @return The mutable StringBuilder which contains the current text | ||||
|          *         content of the element being parsed. | ||||
|          */ | ||||
|         public StringBuilder getTextContent() { | ||||
|             return textContent; | ||||
|         } | ||||
|  | ||||
|         /** | ||||
|          * Returns the TagHandler which must handle any events relating to the | ||||
|          * element being parsed. | ||||
|          * | ||||
|          * @return The TagHandler which must handle any events relating to the | ||||
|          *         element being parsed. | ||||
|          */ | ||||
|         public TagHandler getTagHandler() { | ||||
|             return tagHandler; | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,70 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| package org.apache.guacamole.xml; | ||||
|  | ||||
| import org.xml.sax.Attributes; | ||||
| import org.xml.sax.SAXException; | ||||
|  | ||||
| /** | ||||
|  * A simple element-level event handler for events triggered by the | ||||
|  * SAX-driven DocumentHandler parser. | ||||
|  * | ||||
|  * @author Mike Jumper | ||||
|  */ | ||||
| public interface TagHandler { | ||||
|  | ||||
|     /** | ||||
|      * Called when a child element of the current element is parsed. | ||||
|      * | ||||
|      * @param localName The local name of the child element seen. | ||||
|      * @return The TagHandler which should handle all element-level events | ||||
|      *         related to the child element. | ||||
|      * @throws SAXException If the child element being parsed was not expected, | ||||
|      *                      or some other error prevents a proper TagHandler | ||||
|      *                      from being constructed for the child element. | ||||
|      */ | ||||
|     public TagHandler childElement(String localName) | ||||
|             throws SAXException; | ||||
|  | ||||
|     /** | ||||
|      * Called when the element corresponding to this TagHandler is first seen, | ||||
|      * just after an instance is created. | ||||
|      * | ||||
|      * @param attributes The attributes of the element seen. | ||||
|      * @throws SAXException If an error prevents a the TagHandler from being | ||||
|      *                      from being initialized. | ||||
|      */ | ||||
|     public void init(Attributes attributes) throws SAXException; | ||||
|  | ||||
|     /** | ||||
|      * Called when this element, and all child elements, have been fully parsed, | ||||
|      * and the entire text content of this element (if any) is available. | ||||
|      * | ||||
|      * @param textContent The full text content of this element, if any. | ||||
|      * @throws SAXException If the text content received is not valid for any | ||||
|      *                      reason, or the child elements parsed are not | ||||
|      *                      correct. | ||||
|      */ | ||||
|     public void complete(String textContent) throws SAXException; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,28 @@ | ||||
| /* | ||||
|  * 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. | ||||
|  */ | ||||
|  | ||||
| /** | ||||
|  * Classes driving the SAX-based XML parser used by the Guacamole web | ||||
|  * application. | ||||
|  */ | ||||
| package org.apache.guacamole.xml; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user