mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 09:03:21 +00:00 
			
		
		
		
	GUACAMOLE-189: Refactor GuacamoleProxyConfiguration to guacamole-ext.
This commit is contained in:
		| @@ -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; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
| @@ -53,6 +54,24 @@ public class LocalEnvironment implements Environment { | ||||
|     private static final String[] KNOWN_PROTOCOLS = new String[]{ | ||||
|         "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. | ||||
|      */ | ||||
| @@ -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) | ||||
|         ); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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; | ||||
| @@ -41,18 +43,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. | ||||
|      */ | ||||
| @@ -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); | ||||
|          | ||||
|   | ||||
		Reference in New Issue
	
	Block a user