mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
Java-side refactor to support new concept of Connections. Still need JavaScript refactor.
This commit is contained in:
@@ -29,7 +29,7 @@ import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleSecurityException;
|
||||
import net.sourceforge.guacamole.net.GuacamoleSocket;
|
||||
import net.sourceforge.guacamole.net.GuacamoleTunnel;
|
||||
import net.sourceforge.guacamole.net.InetGuacamoleSocket;
|
||||
import net.sourceforge.guacamole.net.auth.Connection;
|
||||
import net.sourceforge.guacamole.net.auth.Credentials;
|
||||
import net.sourceforge.guacamole.net.auth.Directory;
|
||||
import net.sourceforge.guacamole.net.auth.UserContext;
|
||||
@@ -38,16 +38,13 @@ import net.sourceforge.guacamole.net.event.TunnelCloseEvent;
|
||||
import net.sourceforge.guacamole.net.event.TunnelConnectEvent;
|
||||
import net.sourceforge.guacamole.net.event.listener.TunnelCloseListener;
|
||||
import net.sourceforge.guacamole.net.event.listener.TunnelConnectListener;
|
||||
import net.sourceforge.guacamole.properties.GuacamoleProperties;
|
||||
import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleClientInformation;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||
import net.sourceforge.guacamole.servlet.GuacamoleHTTPTunnelServlet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Connects users to a tunnel associated with the authorized configuration
|
||||
* Connects users to a tunnel associated with the authorized connection
|
||||
* having the given ID.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
@@ -173,19 +170,18 @@ public class BasicGuacamoleTunnelServlet extends AuthenticatingHttpServlet {
|
||||
// Get context
|
||||
UserContext context = getUserContext(httpSession);
|
||||
|
||||
// Get configuration directory
|
||||
Directory<String, GuacamoleConfiguration> directory =
|
||||
context.getGuacamoleConfigurationDirectory();
|
||||
// Get connection directory
|
||||
Directory<String, Connection> directory = context.getConnectionDirectory();
|
||||
|
||||
// If no configs/credentials in session, not authorized
|
||||
// If no credentials in session, not authorized
|
||||
if (credentials == null)
|
||||
throw new GuacamoleSecurityException("Cannot connect - user not logged in.");
|
||||
|
||||
// Get authorized config
|
||||
GuacamoleConfiguration config = directory.get(id);
|
||||
if (config == null) {
|
||||
logger.warn("Configuration id={} not found.", id);
|
||||
throw new GuacamoleSecurityException("Requested configuration is not authorized.");
|
||||
// Get authorized connection
|
||||
Connection connection = directory.get(id);
|
||||
if (connection == null) {
|
||||
logger.warn("Connection id={} not found.", id);
|
||||
throw new GuacamoleSecurityException("Requested connection is not authorized.");
|
||||
}
|
||||
|
||||
logger.info("Successful connection from {} to \"{}\".", request.getRemoteAddr(), id);
|
||||
@@ -213,14 +209,8 @@ public class BasicGuacamoleTunnelServlet extends AuthenticatingHttpServlet {
|
||||
if (video_mimetypes != null)
|
||||
info.getVideoMimetypes().addAll(Arrays.asList(video_mimetypes));
|
||||
|
||||
// Configure and connect socket
|
||||
String hostname = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME);
|
||||
int port = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_PORT);
|
||||
|
||||
GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
|
||||
new InetGuacamoleSocket(hostname, port),
|
||||
config, info
|
||||
);
|
||||
// Connect socket
|
||||
GuacamoleSocket socket = connection.connect(info);
|
||||
|
||||
// Associate socket with tunnel
|
||||
GuacamoleTunnel tunnel = new GuacamoleTunnel(socket) {
|
||||
|
@@ -27,15 +27,15 @@ import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleSecurityException;
|
||||
import net.sourceforge.guacamole.net.auth.Connection;
|
||||
import net.sourceforge.guacamole.net.auth.Directory;
|
||||
import net.sourceforge.guacamole.net.auth.User;
|
||||
import net.sourceforge.guacamole.net.auth.UserContext;
|
||||
import net.sourceforge.guacamole.net.auth.permission.GuacamoleConfigurationDirectoryPermission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.GuacamoleConfigurationPermission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.ConnectionDirectoryPermission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.ConnectionPermission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.ObjectPermission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.Permission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.SystemPermission;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||
|
||||
/**
|
||||
* Simple HttpServlet which outputs XML containing a list of all authorized
|
||||
@@ -43,7 +43,7 @@ import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ConfigurationList extends AuthenticatingHttpServlet {
|
||||
public class ConnectionList extends AuthenticatingHttpServlet {
|
||||
|
||||
/**
|
||||
* Checks whether the given user has permission to perform the given
|
||||
@@ -61,7 +61,7 @@ public class ConfigurationList extends AuthenticatingHttpServlet {
|
||||
|
||||
// Build permission
|
||||
Permission permission =
|
||||
new GuacamoleConfigurationDirectoryPermission(type);
|
||||
new ConnectionDirectoryPermission(type);
|
||||
|
||||
try {
|
||||
// Return result of permission check, if possible
|
||||
@@ -81,7 +81,7 @@ public class ConfigurationList extends AuthenticatingHttpServlet {
|
||||
*
|
||||
* @param user The user whose permissions should be verified.
|
||||
* @param type The type of operation to check for permission for.
|
||||
* @param identifier The identifier of the configuration the operation
|
||||
* @param identifier The identifier of the connection the operation
|
||||
* would be performed upon.
|
||||
* @return true if permission is granted, false otherwise.
|
||||
*
|
||||
@@ -92,7 +92,7 @@ public class ConfigurationList extends AuthenticatingHttpServlet {
|
||||
throws GuacamoleException {
|
||||
|
||||
// Build permission
|
||||
Permission permission = new GuacamoleConfigurationPermission(
|
||||
Permission permission = new ConnectionPermission(
|
||||
type,
|
||||
identifier
|
||||
);
|
||||
@@ -120,16 +120,16 @@ public class ConfigurationList extends AuthenticatingHttpServlet {
|
||||
// Write XML content type
|
||||
response.setHeader("Content-Type", "text/xml");
|
||||
|
||||
// Attempt to get configurations
|
||||
Directory<String, GuacamoleConfiguration> directory;
|
||||
// Attempt to get connections
|
||||
Directory<String, Connection> directory;
|
||||
try {
|
||||
|
||||
// Get configuration directory
|
||||
directory = context.getGuacamoleConfigurationDirectory();
|
||||
// Get connection directory
|
||||
directory = context.getConnectionDirectory();
|
||||
|
||||
}
|
||||
catch (GuacamoleException e) {
|
||||
throw new ServletException("Unable to retrieve configurations.", e);
|
||||
throw new ServletException("Unable to retrieve connections.", e);
|
||||
}
|
||||
|
||||
// Write actual XML
|
||||
@@ -143,22 +143,23 @@ public class ConfigurationList extends AuthenticatingHttpServlet {
|
||||
|
||||
// Begin document
|
||||
xml.writeStartDocument();
|
||||
xml.writeStartElement("configs");
|
||||
xml.writeStartElement("connections");
|
||||
|
||||
// Save config create permission attribute
|
||||
// Save connection create permission attribute
|
||||
if (hasConfigPermission(self, SystemPermission.Type.CREATE))
|
||||
xml.writeAttribute("create", "yes");
|
||||
|
||||
// For each entry, write corresponding config element
|
||||
// For each entry, write corresponding connection element
|
||||
for (String identifier : directory.getIdentifiers()) {
|
||||
|
||||
// Get config
|
||||
GuacamoleConfiguration config = directory.get(identifier);
|
||||
// Get connection
|
||||
Connection connection = directory.get(identifier);
|
||||
|
||||
// Write config
|
||||
xml.writeEmptyElement("config");
|
||||
// Write connection
|
||||
xml.writeEmptyElement("connection");
|
||||
xml.writeAttribute("id", identifier);
|
||||
xml.writeAttribute("protocol", config.getProtocol());
|
||||
xml.writeAttribute("protocol",
|
||||
connection.getConfiguration().getProtocol());
|
||||
|
||||
// Save update permission attribute
|
||||
if (hasConfigPermission(self, ObjectPermission.Type.UPDATE,
|
@@ -30,8 +30,8 @@ import net.sourceforge.guacamole.GuacamoleSecurityException;
|
||||
import net.sourceforge.guacamole.net.auth.Directory;
|
||||
import net.sourceforge.guacamole.net.auth.User;
|
||||
import net.sourceforge.guacamole.net.auth.UserContext;
|
||||
import net.sourceforge.guacamole.net.auth.permission.GuacamoleConfigurationDirectoryPermission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.GuacamoleConfigurationPermission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.ConnectionDirectoryPermission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.ConnectionPermission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.ObjectPermission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.Permission;
|
||||
import net.sourceforge.guacamole.net.auth.permission.SystemPermission;
|
||||
@@ -131,29 +131,29 @@ public class PermissionList extends AuthenticatingHttpServlet {
|
||||
for (Permission permission : user.getPermissions()) {
|
||||
|
||||
// Config directory permission
|
||||
if (permission instanceof GuacamoleConfigurationDirectoryPermission) {
|
||||
if (permission instanceof ConnectionDirectoryPermission) {
|
||||
|
||||
// Get permission
|
||||
GuacamoleConfigurationDirectoryPermission gcdp =
|
||||
(GuacamoleConfigurationDirectoryPermission) permission;
|
||||
ConnectionDirectoryPermission cdp =
|
||||
(ConnectionDirectoryPermission) permission;
|
||||
|
||||
// Write permission
|
||||
xml.writeEmptyElement("configs");
|
||||
xml.writeAttribute("type", toString(gcdp.getType()));
|
||||
xml.writeEmptyElement("connections");
|
||||
xml.writeAttribute("type", toString(cdp.getType()));
|
||||
|
||||
}
|
||||
|
||||
// Config permission
|
||||
else if (permission instanceof GuacamoleConfigurationPermission) {
|
||||
else if (permission instanceof ConnectionPermission) {
|
||||
|
||||
// Get permission
|
||||
GuacamoleConfigurationPermission gcp =
|
||||
(GuacamoleConfigurationPermission) permission;
|
||||
ConnectionPermission cp =
|
||||
(ConnectionPermission) permission;
|
||||
|
||||
// Write permission
|
||||
xml.writeEmptyElement("config");
|
||||
xml.writeAttribute("type", toString(gcp.getType()));
|
||||
xml.writeAttribute("name", gcp.getObjectIdentifier());
|
||||
xml.writeEmptyElement("connection");
|
||||
xml.writeAttribute("type", toString(cp.getType()));
|
||||
xml.writeAttribute("name", cp.getObjectIdentifier());
|
||||
|
||||
}
|
||||
|
||||
|
@@ -55,15 +55,15 @@
|
||||
<url-pattern>/logout</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Configuration List Servlet -->
|
||||
<!-- Connection List Servlet -->
|
||||
<servlet>
|
||||
<description>Configuration list servlet.</description>
|
||||
<servlet-name>Configs</servlet-name>
|
||||
<servlet-class>net.sourceforge.guacamole.net.basic.ConfigurationList</servlet-class>
|
||||
<description>Connection list servlet.</description>
|
||||
<servlet-name>Connections</servlet-name>
|
||||
<servlet-class>net.sourceforge.guacamole.net.basic.ConnectionList</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Configs</servlet-name>
|
||||
<url-pattern>/configs</url-pattern>
|
||||
<servlet-name>Connections</servlet-name>
|
||||
<url-pattern>/connections</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- User List Servlet -->
|
||||
|
@@ -136,7 +136,6 @@
|
||||
Guacamole ${project.version}
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="scripts/connections.js"></script>
|
||||
<script type="text/javascript" src="scripts/session.js"></script>
|
||||
<script type="text/javascript" src="scripts/history.js"></script>
|
||||
<script type="text/javascript" src="scripts/root-ui.js"></script>
|
||||
|
@@ -1,53 +0,0 @@
|
||||
|
||||
/*
|
||||
* Guacamole - Clientless Remote Desktop
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
function Config(protocol, id) {
|
||||
this.protocol = protocol;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
function getConfigList(parameters) {
|
||||
|
||||
// Construct request URL
|
||||
var configs_url = "configs";
|
||||
if (parameters) configs_url += "?" + parameters;
|
||||
|
||||
// Get config list
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", configs_url, false);
|
||||
xhr.send(null);
|
||||
|
||||
// If fail, throw error
|
||||
if (xhr.status != 200)
|
||||
throw new Error(xhr.statusText);
|
||||
|
||||
// Otherwise, get list
|
||||
var configs = new Array();
|
||||
|
||||
var configElements = xhr.responseXML.getElementsByTagName("config");
|
||||
for (var i=0; i<configElements.length; i++) {
|
||||
configs.push(new Config(
|
||||
configElements[i].getAttribute("protocol"),
|
||||
configElements[i].getAttribute("id")
|
||||
));
|
||||
}
|
||||
|
||||
return configs;
|
||||
|
||||
}
|
Reference in New Issue
Block a user