mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 17:13:21 +00:00 
			
		
		
		
	GUAC-1176: Generalize form fields by removing the value property. Add type-specific convenience classes for each field.
This commit is contained in:
		| @@ -0,0 +1,58 @@ | ||||
| /* | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.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, title, 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 title | ||||
|      *     The human-readable title 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 title, String truthValue) { | ||||
|         super(name, title, Field.Type.BOOLEAN, Collections.singletonList( | ||||
|             new FieldOption(truthValue, truthValue) | ||||
|         )); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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.glyptodon.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, title, and possible values. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this field. | ||||
|      * | ||||
|      * @param options | ||||
|      *     All possible legal options for this field. | ||||
|      */ | ||||
|     public EnumField(String name, String title, Collection<FieldOption> options) { | ||||
|         super(name, title, Field.Type.ENUM, options); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,5 +1,5 @@ | ||||
| /* | ||||
|  * Copyright (C) 2013 Glyptodon LLC | ||||
|  * 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 | ||||
| @@ -27,7 +27,11 @@ 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. | ||||
|  * 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 | ||||
|  */ | ||||
| @@ -94,13 +98,7 @@ public class Field { | ||||
|     private String type; | ||||
|  | ||||
|     /** | ||||
|      * The value of this field, when checked. This is only applicable to | ||||
|      * BOOLEAN fields. | ||||
|      */ | ||||
|     private String value; | ||||
|  | ||||
|     /** | ||||
|      * A collection of all associated field options. | ||||
|      * A collection of all legal values of this field. | ||||
|      */ | ||||
|     private Collection<FieldOption> options; | ||||
|  | ||||
| @@ -111,7 +109,7 @@ public class Field { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Parameter with the given name, title, and type. | ||||
|      * Creates a new Field with the given name, title, and type. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
| @@ -123,13 +121,14 @@ public class Field { | ||||
|      *     The type of this field. | ||||
|      */ | ||||
|     public Field(String name, String title, String type) { | ||||
|         this.name    = name; | ||||
|         this.title   = title; | ||||
|         this.type    = type; | ||||
|         this.name  = name; | ||||
|         this.title = title; | ||||
|         this.type  = type; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new ENUM Parameter with the given name, title, and options. | ||||
|      * Creates a new Field with the given name, title, type, and possible | ||||
|      * values. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
| @@ -137,13 +136,17 @@ public class Field { | ||||
|      * @param title | ||||
|      *     The human-readable title 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 title, Collection<FieldOption> options) { | ||||
|     public Field(String name, String title, String type, | ||||
|             Collection<FieldOption> options) { | ||||
|         this.name    = name; | ||||
|         this.title   = title; | ||||
|         this.type    = Type.ENUM; | ||||
|         this.type    = type; | ||||
|         this.options = options; | ||||
|     } | ||||
|  | ||||
| @@ -188,28 +191,6 @@ public class Field { | ||||
|         this.title = title; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the value that should be assigned to this field if enabled. This | ||||
|      * is only applicable to BOOLEAN fields. | ||||
|      * | ||||
|      * @return | ||||
|      *     The value that should be assigned to this field if enabled. | ||||
|      */ | ||||
|     public String getValue() { | ||||
|         return value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the value that should be assigned to this field if enabled. This is | ||||
|      * only applicable to BOOLEAN fields. | ||||
|      * | ||||
|      * @param value | ||||
|      *     The value that should be assigned to this field if enabled. | ||||
|      */ | ||||
|     public void setValue(String value) { | ||||
|         this.value = value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the type of this field. | ||||
|      * | ||||
| @@ -232,8 +213,7 @@ public class Field { | ||||
|  | ||||
|     /** | ||||
|      * Returns a mutable collection of field options. Changes to this | ||||
|      * collection directly affect the available options. This is only | ||||
|      * applicable to ENUM fields. | ||||
|      * collection directly affect the available options. | ||||
|      * | ||||
|      * @return | ||||
|      *     A mutable collection of field options, or null if the field has no | ||||
| @@ -244,8 +224,7 @@ public class Field { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the options available as possible values of this field. This is | ||||
|      * only applicable to ENUM fields. | ||||
|      * Sets the options available as possible values of this field. | ||||
|      * | ||||
|      * @param options | ||||
|      *     The options to associate with this field. | ||||
|   | ||||
| @@ -0,0 +1,45 @@ | ||||
| /* | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.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 and title. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this field. | ||||
|      */ | ||||
|     public MultilineField(String name, String title) { | ||||
|         super(name, title, Field.Type.MULTILINE); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,45 @@ | ||||
| /* | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.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 and title. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this field. | ||||
|      */ | ||||
|     public NumericField(String name, String title) { | ||||
|         super(name, title, Field.Type.NUMERIC); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,46 @@ | ||||
| /* | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.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 and title. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this field. | ||||
|      */ | ||||
|     public PasswordField(String name, String title) { | ||||
|         super(name, title, Field.Type.PASSWORD); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,46 @@ | ||||
| /* | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.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 and title. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this field. | ||||
|      */ | ||||
|     public TextField(String name, String title) { | ||||
|         super(name, title, Field.Type.TEXT); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,46 @@ | ||||
| /* | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.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 and title. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this field. | ||||
|      */ | ||||
|     public UsernameField(String name, String title) { | ||||
|         super(name, title, Field.Type.USERNAME); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -26,6 +26,8 @@ import java.util.Arrays; | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import org.glyptodon.guacamole.form.Field; | ||||
| import org.glyptodon.guacamole.form.PasswordField; | ||||
| import org.glyptodon.guacamole.form.UsernameField; | ||||
|  | ||||
| /** | ||||
|  * Information which describes a set of valid credentials. | ||||
| @@ -71,13 +73,13 @@ public class CredentialsInfo { | ||||
|      * A field describing the username HTTP parameter expected by Guacamole | ||||
|      * during login, if usernames are being used. | ||||
|      */ | ||||
|     public static final Field USERNAME = new Field("username", "username", Field.Type.USERNAME); | ||||
|     public static final Field USERNAME = new UsernameField("username", "username"); | ||||
|  | ||||
|     /** | ||||
|      * A field describing the password HTTP parameter expected by Guacamole | ||||
|      * during login, if passwords are being used. | ||||
|      */ | ||||
|     public static final Field PASSWORD = new Field("password", "password", Field.Type.PASSWORD); | ||||
|     public static final Field PASSWORD = new PasswordField("password", "password"); | ||||
|  | ||||
|     /** | ||||
|      * CredentialsInfo object which describes standard username/password | ||||
|   | ||||
		Reference in New Issue
	
	Block a user