Repository: incubator-guacamole-client Updated Branches: refs/heads/master ea5c8c546 -> d9b888e99
GUACAMOLE-189: Refactor GuacamoleProxyConfiguration to guacamole-ext. Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/31b1b42b Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/31b1b42b Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/31b1b42b Branch: refs/heads/master Commit: 31b1b42ba6bf873e3f7af0848c6c24495027a14d Parents: 152de87 Author: Michael Jumper <[email protected]> Authored: Tue Jan 24 21:38:31 2017 -0800 Committer: Michael Jumper <[email protected]> Committed: Thu May 4 21:32:23 2017 -0700 ---------------------------------------------------------------------- .../guacamole/auth/jdbc/JDBCEnvironment.java | 38 ------ .../auth/jdbc/connection/ConnectionModel.java | 2 +- .../connection/GuacamoleProxyConfiguration.java | 132 ------------------- .../auth/jdbc/connection/ModeledConnection.java | 3 +- .../tunnel/AbstractGuacamoleTunnelService.java | 2 +- .../auth/jdbc/connection/ConnectionMapper.xml | 4 +- .../auth/jdbc/connection/ConnectionMapper.xml | 4 +- .../guacamole/environment/Environment.java | 16 +++ .../guacamole/environment/LocalEnvironment.java | 32 +++++ .../net/auth/GuacamoleProxyConfiguration.java | 132 +++++++++++++++++++ .../net/auth/simple/SimpleConnection.java | 63 ++++----- 11 files changed, 221 insertions(+), 207 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java index 52aed03..dfbf0e9 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java @@ -20,8 +20,6 @@ package org.apache.guacamole.auth.jdbc; import org.apache.guacamole.GuacamoleException; -import org.apache.guacamole.auth.jdbc.connection.GuacamoleProxyConfiguration; -import org.apache.guacamole.environment.Environment; import org.apache.guacamole.environment.LocalEnvironment; import org.apache.guacamole.auth.jdbc.security.PasswordPolicy; @@ -32,18 +30,6 @@ import org.apache.guacamole.auth.jdbc.security.PasswordPolicy; public abstract class JDBCEnvironment extends LocalEnvironment { /** - * 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; - - /** * Constructs a new JDBCEnvironment using an underlying LocalEnviroment to * read properties from the file system. * @@ -55,30 +41,6 @@ public abstract class JDBCEnvironment extends LocalEnvironment { } /** - * Returns the connection information which should be used, by default, to - * connect to guacd when establishing a remote desktop connection. - * - * @return - * The connection information which should be used, by default, to - * connect to guacd. - * - * @throws GuacamoleException - * If the properties describing the connection information for guacd - * cannot be parsed. - */ - public GuacamoleProxyConfiguration getDefaultGuacamoleProxyConfiguration() - throws GuacamoleException { - - // Parse guacd hostname/port/ssl properties - return new GuacamoleProxyConfiguration( - getProperty(Environment.GUACD_HOSTNAME, DEFAULT_GUACD_HOSTNAME), - getProperty(Environment.GUACD_PORT, DEFAULT_GUACD_PORT), - getProperty(Environment.GUACD_SSL, false) - ); - - } - - /** * Returns whether a database user account is required for authentication to * succeed, even if another authentication provider has already * authenticated the user. http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java index 92346b7..44f4b3b 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -22,7 +22,7 @@ package org.apache.guacamole.auth.jdbc.connection; import java.util.HashSet; import java.util.Set; import org.apache.guacamole.auth.jdbc.base.ChildObjectModel; -import org.apache.guacamole.auth.jdbc.connection.GuacamoleProxyConfiguration.EncryptionMethod; +import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration.EncryptionMethod; /** * Object representation of a Guacamole connection, as represented in the http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/GuacamoleProxyConfiguration.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/GuacamoleProxyConfiguration.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/GuacamoleProxyConfiguration.java deleted file mode 100644 index 28d02e8..0000000 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/GuacamoleProxyConfiguration.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.guacamole.auth.jdbc.connection; - -/** - * Information which describes how the connection to guacd should be - * established. This includes the hostname and port which guacd is listening on, - * as well as the type of encryption required, if any. - * - * @author Michael Jumper - */ -public class GuacamoleProxyConfiguration { - - /** - * All possible types of encryption used by guacd. - */ - public enum EncryptionMethod { - - /** - * Unencrypted (plaintext). - */ - NONE, - - /** - * Encrypted with SSL or TLS. - */ - SSL - - } - - /** - * The hostname or address of the machine where guacd is running. - */ - private final String hostname; - - /** - * The port that guacd is listening on. - */ - private final int port; - - /** - * The type of encryption required by guacd. - */ - private final EncryptionMethod encryptionMethod; - - /** - * Creates a new GuacamoleProxyConfiguration having the given hostname, - * port, and encryption method. - * - * @param hostname - * The hostname or address of the machine where guacd is running. - * - * @param port - * The port that guacd is listening on. - * - * @param encryptionMethod - * The type of encryption required by the instance of guacd running at - * the given hostname and port. - */ - public GuacamoleProxyConfiguration(String hostname, int port, - EncryptionMethod encryptionMethod) { - this.hostname = hostname; - this.port = port; - this.encryptionMethod = encryptionMethod; - } - - /** - * Creates a new GuacamoleProxyConfiguration having the given hostname and - * port, with encryption method being restricted to either NONE or SSL. - * - * @param hostname - * The hostname or address of the machine where guacd is running. - * - * @param port - * The port that guacd is listening on. - * - * @param ssl - * true if guacd requires SSL/TLS encryption, false if communication - * with guacd should be unencrypted. - */ - public GuacamoleProxyConfiguration(String hostname, int port, boolean ssl) { - this(hostname, port, ssl ? EncryptionMethod.SSL : EncryptionMethod.NONE); - } - - /** - * Returns the hostname or address of the machine where guacd is running. - * - * @return - * The hostname or address of the machine where guacd is running. - */ - public String getHostname() { - return hostname; - } - - /** - * Returns the port that guacd is listening on. - * - * @return - * The port that guacd is listening on. - */ - public int getPort() { - return port; - } - - /** - * Returns the type of encryption required by guacd. - * - * @return - * The type of encryption required by guacd. - */ - public EncryptionMethod getEncryptionMethod() { - return encryptionMethod; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index 2de235c..bcd7b11 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -32,7 +32,6 @@ import org.apache.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService; import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.auth.jdbc.JDBCEnvironment; import org.apache.guacamole.auth.jdbc.base.ModeledChildDirectoryObject; -import org.apache.guacamole.auth.jdbc.connection.GuacamoleProxyConfiguration.EncryptionMethod; import org.apache.guacamole.form.EnumField; import org.apache.guacamole.form.Field; import org.apache.guacamole.form.Form; @@ -41,6 +40,8 @@ import org.apache.guacamole.form.TextField; import org.apache.guacamole.net.GuacamoleTunnel; import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.ConnectionRecord; +import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration; +import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration.EncryptionMethod; import org.apache.guacamole.protocol.GuacamoleClientInformation; import org.apache.guacamole.protocol.GuacamoleConfiguration; import org.slf4j.Logger; http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java index abdeaff..392d019 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java @@ -57,12 +57,12 @@ import org.apache.guacamole.token.StandardTokens; import org.apache.guacamole.token.TokenFilter; import org.mybatis.guice.transactional.Transactional; import org.apache.guacamole.auth.jdbc.connection.ConnectionParameterMapper; -import org.apache.guacamole.auth.jdbc.connection.GuacamoleProxyConfiguration; import org.apache.guacamole.auth.jdbc.sharing.connection.SharedConnectionDefinition; import org.apache.guacamole.auth.jdbc.sharingprofile.ModeledSharingProfile; import org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileParameterMapper; import org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileParameterModel; import org.apache.guacamole.auth.jdbc.user.RemoteAuthenticatedUser; +import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration; import org.apache.guacamole.protocol.FailoverGuacamoleSocket; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml index e4b5294..46f8f10 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml @@ -36,7 +36,7 @@ <result column="proxy_hostname" property="proxyHostname" jdbcType="VARCHAR"/> <result column="proxy_port" property="proxyPort" jdbcType="INTEGER"/> <result column="proxy_encryption_method" property="proxyEncryptionMethod" jdbcType="VARCHAR" - javaType="org.apache.guacamole.auth.jdbc.connection.GuacamoleProxyConfiguration$EncryptionMethod"/> + javaType="org.apache.guacamole.net.auth.GuacamoleProxyConfiguration$EncryptionMethod"/> <!-- Associated sharing profiles --> <collection property="sharingProfileIdentifiers" resultSet="sharingProfiles" ofType="java.lang.String" @@ -218,4 +218,4 @@ WHERE connection_id = #{object.objectID,jdbcType=INTEGER} </update> -</mapper> \ No newline at end of file +</mapper> http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml index aedd86b..44828fa 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml @@ -36,7 +36,7 @@ <result column="proxy_hostname" property="proxyHostname" jdbcType="VARCHAR"/> <result column="proxy_port" property="proxyPort" jdbcType="INTEGER"/> <result column="proxy_encryption_method" property="proxyEncryptionMethod" jdbcType="VARCHAR" - javaType="org.apache.guacamole.auth.jdbc.connection.GuacamoleProxyConfiguration$EncryptionMethod"/> + javaType="org.apache.guacamole.net.auth.GuacamoleProxyConfiguration$EncryptionMethod"/> <!-- Associated sharing profiles --> <collection property="sharingProfileIdentifiers" resultSet="sharingProfiles" ofType="java.lang.String" @@ -218,4 +218,4 @@ WHERE connection_id = #{object.objectID,jdbcType=INTEGER}::integer </update> -</mapper> \ No newline at end of file +</mapper> http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/guacamole-ext/src/main/java/org/apache/guacamole/environment/Environment.java ---------------------------------------------------------------------- diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/environment/Environment.java b/guacamole-ext/src/main/java/org/apache/guacamole/environment/Environment.java index 445f1ef..43f8f75 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/environment/Environment.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/environment/Environment.java @@ -22,6 +22,7 @@ package org.apache.guacamole.environment; import java.io.File; import java.util.Map; import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration; import org.apache.guacamole.properties.BooleanGuacamoleProperty; import org.apache.guacamole.properties.GuacamoleProperty; import org.apache.guacamole.properties.IntegerGuacamoleProperty; @@ -146,4 +147,19 @@ public interface Environment { public <Type> Type getRequiredProperty(GuacamoleProperty<Type> property) throws GuacamoleException; + /** + * Returns the connection information which should be used, by default, to + * connect to guacd when establishing a remote desktop connection. + * + * @return + * The connection information which should be used, by default, to + * connect to guacd. + * + * @throws GuacamoleException + * If the the connection information for guacd cannot be + * retrieved. + */ + public GuacamoleProxyConfiguration getDefaultGuacamoleProxyConfiguration() + throws GuacamoleException; + } http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/guacamole-ext/src/main/java/org/apache/guacamole/environment/LocalEnvironment.java ---------------------------------------------------------------------- diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/environment/LocalEnvironment.java b/guacamole-ext/src/main/java/org/apache/guacamole/environment/LocalEnvironment.java index 74adaea..0b7ffad 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/environment/LocalEnvironment.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/environment/LocalEnvironment.java @@ -30,6 +30,7 @@ import java.util.Properties; import org.codehaus.jackson.map.ObjectMapper; import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleServerException; +import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration; import org.apache.guacamole.properties.GuacamoleProperty; import org.apache.guacamole.protocols.ProtocolInfo; import org.slf4j.Logger; @@ -54,6 +55,24 @@ public class LocalEnvironment implements Environment { "vnc", "rdp", "ssh", "telnet"}; /** + * 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; + + /** + * Whether SSL/TLS is enabled for connections to guacd if not specified + * within guacamole.properties. + */ + private static final boolean DEFAULT_GUACD_SSL = false; + + /** * All properties read from guacamole.properties. */ private final Properties properties; @@ -313,4 +332,17 @@ public class LocalEnvironment implements Environment { return availableProtocols.get(name); } + @Override + public GuacamoleProxyConfiguration getDefaultGuacamoleProxyConfiguration() + throws GuacamoleException { + + // Parse guacd hostname/port/ssl properties + return new GuacamoleProxyConfiguration( + getProperty(Environment.GUACD_HOSTNAME, DEFAULT_GUACD_HOSTNAME), + getProperty(Environment.GUACD_PORT, DEFAULT_GUACD_PORT), + getProperty(Environment.GUACD_SSL, DEFAULT_GUACD_SSL) + ); + + } + } http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/GuacamoleProxyConfiguration.java ---------------------------------------------------------------------- diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/GuacamoleProxyConfiguration.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/GuacamoleProxyConfiguration.java new file mode 100644 index 0000000..7a24837 --- /dev/null +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/GuacamoleProxyConfiguration.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole.net.auth; + +/** + * Information which describes how the connection to guacd should be + * established. This includes the hostname and port which guacd is listening on, + * as well as the type of encryption required, if any. + * + * @author Michael Jumper + */ +public class GuacamoleProxyConfiguration { + + /** + * All possible types of encryption used by guacd. + */ + public enum EncryptionMethod { + + /** + * Unencrypted (plaintext). + */ + NONE, + + /** + * Encrypted with SSL or TLS. + */ + SSL + + } + + /** + * The hostname or address of the machine where guacd is running. + */ + private final String hostname; + + /** + * The port that guacd is listening on. + */ + private final int port; + + /** + * The type of encryption required by guacd. + */ + private final EncryptionMethod encryptionMethod; + + /** + * Creates a new GuacamoleProxyConfiguration having the given hostname, + * port, and encryption method. + * + * @param hostname + * The hostname or address of the machine where guacd is running. + * + * @param port + * The port that guacd is listening on. + * + * @param encryptionMethod + * The type of encryption required by the instance of guacd running at + * the given hostname and port. + */ + public GuacamoleProxyConfiguration(String hostname, int port, + EncryptionMethod encryptionMethod) { + this.hostname = hostname; + this.port = port; + this.encryptionMethod = encryptionMethod; + } + + /** + * Creates a new GuacamoleProxyConfiguration having the given hostname and + * port, with encryption method being restricted to either NONE or SSL. + * + * @param hostname + * The hostname or address of the machine where guacd is running. + * + * @param port + * The port that guacd is listening on. + * + * @param ssl + * true if guacd requires SSL/TLS encryption, false if communication + * with guacd should be unencrypted. + */ + public GuacamoleProxyConfiguration(String hostname, int port, boolean ssl) { + this(hostname, port, ssl ? EncryptionMethod.SSL : EncryptionMethod.NONE); + } + + /** + * Returns the hostname or address of the machine where guacd is running. + * + * @return + * The hostname or address of the machine where guacd is running. + */ + public String getHostname() { + return hostname; + } + + /** + * Returns the port that guacd is listening on. + * + * @return + * The port that guacd is listening on. + */ + public int getPort() { + return port; + } + + /** + * Returns the type of encryption required by guacd. + * + * @return + * The type of encryption required by guacd. + */ + public EncryptionMethod getEncryptionMethod() { + return encryptionMethod; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/31b1b42b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java ---------------------------------------------------------------------- diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java index fe25fcf..2251a9e 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.GuacamoleServerException; import org.apache.guacamole.environment.Environment; import org.apache.guacamole.environment.LocalEnvironment; import org.apache.guacamole.net.GuacamoleSocket; @@ -32,6 +33,7 @@ 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.net.auth.GuacamoleProxyConfiguration; import org.apache.guacamole.protocol.ConfiguredGuacamoleSocket; import org.apache.guacamole.protocol.GuacamoleClientInformation; import org.apache.guacamole.protocol.GuacamoleConfiguration; @@ -42,18 +44,6 @@ import org.apache.guacamole.protocol.GuacamoleConfiguration; 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; @@ -107,27 +97,40 @@ public class SimpleConnection extends AbstractConnection { public GuacamoleTunnel connect(GuacamoleClientInformation info) throws GuacamoleException { - Environment env = new LocalEnvironment(); - + // Retrieve proxy configuration from environment + Environment environment = new LocalEnvironment(); + GuacamoleProxyConfiguration proxyConfig = environment.getDefaultGuacamoleProxyConfiguration(); + // Get guacd connection parameters - String hostname = env.getProperty(Environment.GUACD_HOSTNAME, DEFAULT_GUACD_HOSTNAME); - int port = env.getProperty(Environment.GUACD_PORT, DEFAULT_GUACD_PORT); + String hostname = proxyConfig.getHostname(); + int port = proxyConfig.getPort(); 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 - ); + + // Determine socket type based on required encryption method + switch (proxyConfig.getEncryptionMethod()) { + + // If guacd requires SSL, use it + case SSL: + socket = new ConfiguredGuacamoleSocket( + new SSLGuacamoleSocket(hostname, port), + config, info + ); + break; + + // Connect directly via TCP if encryption is not enabled + case NONE: + socket = new ConfiguredGuacamoleSocket( + new InetGuacamoleSocket(hostname, port), + config, info + ); + break; + + // Abort if encryption method is unknown + default: + throw new GuacamoleServerException("Unimplemented encryption method."); + + } return new SimpleGuacamoleTunnel(socket);
