mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-189: Refactor GuacamoleProxyConfiguration to guacamole-ext.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -31,18 +29,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.
|
||||
@@ -54,30 +40,6 @@ public abstract class JDBCEnvironment extends LocalEnvironment {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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>
|
||||
</mapper>
|
||||
|
@@ -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>
|
||||
</mapper>
|
||||
|
@@ -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)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.guacamole.auth.jdbc.connection;
|
||||
package org.apache.guacamole.net.auth;
|
||||
|
||||
/**
|
||||
* Information which describes how the connection to guacd should be
|
@@ -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