From ae96de95a602c0aec7d7b9cb45feaf095c11f640 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 20 Apr 2015 12:56:22 -0700 Subject: [PATCH] GUAC-1161: Add CredentialsInfo and credential-specific exceptions, --- .../net/auth/credentials/CredentialsInfo.java | 79 ++++++++++++++ .../GuacamoleCredentialsException.java | 100 ++++++++++++++++++ ...amoleInsufficientCredentialsException.java | 82 ++++++++++++++ .../GuacamoleInvalidCredentialsException.java | 80 ++++++++++++++ 4 files changed, 341 insertions(+) create mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/CredentialsInfo.java create mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleCredentialsException.java create mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleInsufficientCredentialsException.java create mode 100644 guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleInvalidCredentialsException.java diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/CredentialsInfo.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/CredentialsInfo.java new file mode 100644 index 000000000..91a415fba --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/CredentialsInfo.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2015 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.glyptodon.guacamole.net.auth.credentials; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import org.glyptodon.guacamole.form.Parameter; + +/** + * Information which describes a set of valid credentials. + * + * @author Michael Jumper + */ +public class CredentialsInfo { + + /** + * All parameters required for valid credentials. + */ + private final Collection parameters; + + /** + * Creates a new CredentialsInfo object which requires the given parameters + * for any conforming credentials. + * + * @param parameters + * The parameters to require. + */ + public CredentialsInfo(Collection parameters) { + this.parameters = parameters; + } + + /** + * Returns all parameters required for valid credentials as described by + * this object. + * + * @return + * All parameters required for valid credentials. + */ + public Collection getParameters() { + return Collections.unmodifiableCollection(parameters); + } + + /** + * CredentialsInfo object which describes empty credentials. No parameters + * are required. + */ + public static final CredentialsInfo EMPTY = new CredentialsInfo(Collections.EMPTY_LIST); + + /** + * CredentialsInfo object which describes standard username/password + * credentials. + */ + public static final CredentialsInfo USERNAME_PASSWORD = new CredentialsInfo(Arrays.asList( + new Parameter("username", "username", Parameter.Type.USERNAME), + new Parameter("password", "password", Parameter.Type.PASSWORD) + )); + +} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleCredentialsException.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleCredentialsException.java new file mode 100644 index 000000000..55fffea34 --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleCredentialsException.java @@ -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.glyptodon.guacamole.net.auth.credentials; + +import org.glyptodon.guacamole.GuacamoleSecurityException; + +/** + * 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 GuacamoleSecurityException { + + /** + * 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; + } + +} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleInsufficientCredentialsException.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleInsufficientCredentialsException.java new file mode 100644 index 000000000..ea8675a3b --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleInsufficientCredentialsException.java @@ -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.glyptodon.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); + } + +} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleInvalidCredentialsException.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleInvalidCredentialsException.java new file mode 100644 index 000000000..903b82bef --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/GuacamoleInvalidCredentialsException.java @@ -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.glyptodon.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); + } + +}