mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 09:03: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.GuacamoleSecurityException; | ||||||
| import net.sourceforge.guacamole.net.GuacamoleSocket; | import net.sourceforge.guacamole.net.GuacamoleSocket; | ||||||
| import net.sourceforge.guacamole.net.GuacamoleTunnel; | 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.Credentials; | ||||||
| import net.sourceforge.guacamole.net.auth.Directory; | import net.sourceforge.guacamole.net.auth.Directory; | ||||||
| import net.sourceforge.guacamole.net.auth.UserContext; | 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.TunnelConnectEvent; | ||||||
| import net.sourceforge.guacamole.net.event.listener.TunnelCloseListener; | import net.sourceforge.guacamole.net.event.listener.TunnelCloseListener; | ||||||
| import net.sourceforge.guacamole.net.event.listener.TunnelConnectListener; | 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.GuacamoleClientInformation; | ||||||
| import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; |  | ||||||
| import net.sourceforge.guacamole.servlet.GuacamoleHTTPTunnelServlet; | import net.sourceforge.guacamole.servlet.GuacamoleHTTPTunnelServlet; | ||||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | 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. |  * having the given ID. | ||||||
|  * |  * | ||||||
|  * @author Michael Jumper |  * @author Michael Jumper | ||||||
| @@ -173,19 +170,18 @@ public class BasicGuacamoleTunnelServlet extends AuthenticatingHttpServlet { | |||||||
|             // Get context |             // Get context | ||||||
|             UserContext context = getUserContext(httpSession); |             UserContext context = getUserContext(httpSession); | ||||||
|  |  | ||||||
|             // Get configuration directory |             // Get connection directory | ||||||
|             Directory<String, GuacamoleConfiguration> directory = |             Directory<String, Connection> directory = context.getConnectionDirectory(); | ||||||
|                     context.getGuacamoleConfigurationDirectory(); |  | ||||||
|                  |                  | ||||||
|             // If no configs/credentials in session, not authorized |             // If no credentials in session, not authorized | ||||||
|             if (credentials == null) |             if (credentials == null) | ||||||
|                 throw new GuacamoleSecurityException("Cannot connect - user not logged in."); |                 throw new GuacamoleSecurityException("Cannot connect - user not logged in."); | ||||||
|  |  | ||||||
|             // Get authorized config |             // Get authorized connection  | ||||||
|             GuacamoleConfiguration config = directory.get(id); |             Connection connection = directory.get(id); | ||||||
|             if (config == null) { |             if (connection == null) { | ||||||
|                 logger.warn("Configuration id={} not found.", id); |                 logger.warn("Connection id={} not found.", id); | ||||||
|                 throw new GuacamoleSecurityException("Requested configuration is not authorized."); |                 throw new GuacamoleSecurityException("Requested connection is not authorized."); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             logger.info("Successful connection from {} to \"{}\".", request.getRemoteAddr(), id); |             logger.info("Successful connection from {} to \"{}\".", request.getRemoteAddr(), id); | ||||||
| @@ -213,14 +209,8 @@ public class BasicGuacamoleTunnelServlet extends AuthenticatingHttpServlet { | |||||||
|             if (video_mimetypes != null) |             if (video_mimetypes != null) | ||||||
|                 info.getVideoMimetypes().addAll(Arrays.asList(video_mimetypes)); |                 info.getVideoMimetypes().addAll(Arrays.asList(video_mimetypes)); | ||||||
|  |  | ||||||
|             // Configure and connect socket |             // Connect socket | ||||||
|             String hostname = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME); |             GuacamoleSocket socket = connection.connect(info); | ||||||
|             int port = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_PORT); |  | ||||||
|  |  | ||||||
|             GuacamoleSocket socket = new ConfiguredGuacamoleSocket( |  | ||||||
|                     new InetGuacamoleSocket(hostname, port), |  | ||||||
|                     config, info |  | ||||||
|             ); |  | ||||||
|  |  | ||||||
|             // Associate socket with tunnel |             // Associate socket with tunnel | ||||||
|             GuacamoleTunnel tunnel = new GuacamoleTunnel(socket) { |             GuacamoleTunnel tunnel = new GuacamoleTunnel(socket) { | ||||||
|   | |||||||
| @@ -27,15 +27,15 @@ import javax.xml.stream.XMLStreamException; | |||||||
| import javax.xml.stream.XMLStreamWriter; | import javax.xml.stream.XMLStreamWriter; | ||||||
| import net.sourceforge.guacamole.GuacamoleException; | import net.sourceforge.guacamole.GuacamoleException; | ||||||
| import net.sourceforge.guacamole.GuacamoleSecurityException; | 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.Directory; | ||||||
| import net.sourceforge.guacamole.net.auth.User; | import net.sourceforge.guacamole.net.auth.User; | ||||||
| import net.sourceforge.guacamole.net.auth.UserContext; | import net.sourceforge.guacamole.net.auth.UserContext; | ||||||
| import net.sourceforge.guacamole.net.auth.permission.GuacamoleConfigurationDirectoryPermission; | import net.sourceforge.guacamole.net.auth.permission.ConnectionDirectoryPermission; | ||||||
| import net.sourceforge.guacamole.net.auth.permission.GuacamoleConfigurationPermission; | import net.sourceforge.guacamole.net.auth.permission.ConnectionPermission; | ||||||
| import net.sourceforge.guacamole.net.auth.permission.ObjectPermission; | import net.sourceforge.guacamole.net.auth.permission.ObjectPermission; | ||||||
| import net.sourceforge.guacamole.net.auth.permission.Permission; | import net.sourceforge.guacamole.net.auth.permission.Permission; | ||||||
| import net.sourceforge.guacamole.net.auth.permission.SystemPermission; | 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 |  * Simple HttpServlet which outputs XML containing a list of all authorized | ||||||
| @@ -43,7 +43,7 @@ import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; | |||||||
|  * |  * | ||||||
|  * @author Michael Jumper |  * @author Michael Jumper | ||||||
|  */ |  */ | ||||||
| public class ConfigurationList extends AuthenticatingHttpServlet { | public class ConnectionList extends AuthenticatingHttpServlet { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Checks whether the given user has permission to perform the given |      * Checks whether the given user has permission to perform the given | ||||||
| @@ -61,7 +61,7 @@ public class ConfigurationList extends AuthenticatingHttpServlet { | |||||||
| 
 | 
 | ||||||
|         // Build permission |         // Build permission | ||||||
|         Permission permission = |         Permission permission = | ||||||
|                 new GuacamoleConfigurationDirectoryPermission(type); |                 new ConnectionDirectoryPermission(type); | ||||||
| 
 | 
 | ||||||
|         try { |         try { | ||||||
|             // Return result of permission check, if possible |             // 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 user The user whose permissions should be verified. | ||||||
|      * @param type The type of operation to check for permission for. |      * @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. |      *                   would be performed upon. | ||||||
|      * @return true if permission is granted, false otherwise. |      * @return true if permission is granted, false otherwise. | ||||||
|      *  |      *  | ||||||
| @@ -92,7 +92,7 @@ public class ConfigurationList extends AuthenticatingHttpServlet { | |||||||
|     throws GuacamoleException { |     throws GuacamoleException { | ||||||
| 
 | 
 | ||||||
|         // Build permission |         // Build permission | ||||||
|         Permission permission = new GuacamoleConfigurationPermission( |         Permission permission = new ConnectionPermission( | ||||||
|             type, |             type, | ||||||
|             identifier |             identifier | ||||||
|         ); |         ); | ||||||
| @@ -120,16 +120,16 @@ public class ConfigurationList extends AuthenticatingHttpServlet { | |||||||
|         // Write XML content type |         // Write XML content type | ||||||
|         response.setHeader("Content-Type", "text/xml"); |         response.setHeader("Content-Type", "text/xml"); | ||||||
| 
 | 
 | ||||||
|         // Attempt to get configurations |         // Attempt to get connections  | ||||||
|         Directory<String, GuacamoleConfiguration> directory; |         Directory<String, Connection> directory; | ||||||
|         try { |         try { | ||||||
| 
 | 
 | ||||||
|             // Get configuration directory |             // Get connection directory | ||||||
|             directory = context.getGuacamoleConfigurationDirectory(); |             directory = context.getConnectionDirectory(); | ||||||
| 
 | 
 | ||||||
|         } |         } | ||||||
|         catch (GuacamoleException e) { |         catch (GuacamoleException e) { | ||||||
|             throw new ServletException("Unable to retrieve configurations.", e); |             throw new ServletException("Unable to retrieve connections.", e); | ||||||
|         } |         } | ||||||
|         |         | ||||||
|         // Write actual XML |         // Write actual XML | ||||||
| @@ -143,22 +143,23 @@ public class ConfigurationList extends AuthenticatingHttpServlet { | |||||||
| 
 | 
 | ||||||
|             // Begin document |             // Begin document | ||||||
|             xml.writeStartDocument(); |             xml.writeStartDocument(); | ||||||
|             xml.writeStartElement("configs"); |             xml.writeStartElement("connections"); | ||||||
|              |              | ||||||
|             // Save config create permission attribute |             // Save connection create permission attribute | ||||||
|             if (hasConfigPermission(self, SystemPermission.Type.CREATE)) |             if (hasConfigPermission(self, SystemPermission.Type.CREATE)) | ||||||
|                 xml.writeAttribute("create", "yes"); |                 xml.writeAttribute("create", "yes"); | ||||||
|              |              | ||||||
|             // For each entry, write corresponding config element |             // For each entry, write corresponding connection element | ||||||
|             for (String identifier : directory.getIdentifiers()) { |             for (String identifier : directory.getIdentifiers()) { | ||||||
| 
 | 
 | ||||||
|                 // Get config |                 // Get connection  | ||||||
|                 GuacamoleConfiguration config = directory.get(identifier); |                 Connection connection = directory.get(identifier); | ||||||
| 
 | 
 | ||||||
|                 // Write config |                 // Write connection | ||||||
|                 xml.writeEmptyElement("config"); |                 xml.writeEmptyElement("connection"); | ||||||
|                 xml.writeAttribute("id", identifier); |                 xml.writeAttribute("id", identifier); | ||||||
|                 xml.writeAttribute("protocol", config.getProtocol()); |                 xml.writeAttribute("protocol", | ||||||
|  |                         connection.getConfiguration().getProtocol()); | ||||||
| 
 | 
 | ||||||
|                 // Save update permission attribute |                 // Save update permission attribute | ||||||
|                 if (hasConfigPermission(self, ObjectPermission.Type.UPDATE, |                 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.Directory; | ||||||
| import net.sourceforge.guacamole.net.auth.User; | import net.sourceforge.guacamole.net.auth.User; | ||||||
| import net.sourceforge.guacamole.net.auth.UserContext; | import net.sourceforge.guacamole.net.auth.UserContext; | ||||||
| import net.sourceforge.guacamole.net.auth.permission.GuacamoleConfigurationDirectoryPermission; | import net.sourceforge.guacamole.net.auth.permission.ConnectionDirectoryPermission; | ||||||
| import net.sourceforge.guacamole.net.auth.permission.GuacamoleConfigurationPermission; | import net.sourceforge.guacamole.net.auth.permission.ConnectionPermission; | ||||||
| import net.sourceforge.guacamole.net.auth.permission.ObjectPermission; | import net.sourceforge.guacamole.net.auth.permission.ObjectPermission; | ||||||
| import net.sourceforge.guacamole.net.auth.permission.Permission; | import net.sourceforge.guacamole.net.auth.permission.Permission; | ||||||
| import net.sourceforge.guacamole.net.auth.permission.SystemPermission; | import net.sourceforge.guacamole.net.auth.permission.SystemPermission; | ||||||
| @@ -131,29 +131,29 @@ public class PermissionList extends AuthenticatingHttpServlet { | |||||||
|             for (Permission permission : user.getPermissions()) { |             for (Permission permission : user.getPermissions()) { | ||||||
|  |  | ||||||
|                 // Config directory permission |                 // Config directory permission | ||||||
|                 if (permission instanceof GuacamoleConfigurationDirectoryPermission) { |                 if (permission instanceof ConnectionDirectoryPermission) { | ||||||
|  |  | ||||||
|                     // Get permission |                     // Get permission | ||||||
|                     GuacamoleConfigurationDirectoryPermission gcdp = |                     ConnectionDirectoryPermission cdp = | ||||||
|                             (GuacamoleConfigurationDirectoryPermission) permission; |                             (ConnectionDirectoryPermission) permission; | ||||||
|                      |                      | ||||||
|                     // Write permission  |                     // Write permission  | ||||||
|                     xml.writeEmptyElement("configs"); |                     xml.writeEmptyElement("connections"); | ||||||
|                     xml.writeAttribute("type", toString(gcdp.getType())); |                     xml.writeAttribute("type", toString(cdp.getType())); | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 // Config permission |                 // Config permission | ||||||
|                 else if (permission instanceof GuacamoleConfigurationPermission) { |                 else if (permission instanceof ConnectionPermission) { | ||||||
|  |  | ||||||
|                     // Get permission |                     // Get permission | ||||||
|                     GuacamoleConfigurationPermission gcp = |                     ConnectionPermission cp = | ||||||
|                             (GuacamoleConfigurationPermission) permission; |                             (ConnectionPermission) permission; | ||||||
|                      |                      | ||||||
|                     // Write permission  |                     // Write permission  | ||||||
|                     xml.writeEmptyElement("config"); |                     xml.writeEmptyElement("connection"); | ||||||
|                     xml.writeAttribute("type", toString(gcp.getType())); |                     xml.writeAttribute("type", toString(cp.getType())); | ||||||
|                     xml.writeAttribute("name", gcp.getObjectIdentifier()); |                     xml.writeAttribute("name", cp.getObjectIdentifier()); | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -55,15 +55,15 @@ | |||||||
|         <url-pattern>/logout</url-pattern> |         <url-pattern>/logout</url-pattern> | ||||||
|     </servlet-mapping> |     </servlet-mapping> | ||||||
|  |  | ||||||
|     <!-- Configuration List Servlet --> |     <!-- Connection List Servlet --> | ||||||
|     <servlet> |     <servlet> | ||||||
|         <description>Configuration list servlet.</description> |         <description>Connection list servlet.</description> | ||||||
|         <servlet-name>Configs</servlet-name> |         <servlet-name>Connections</servlet-name> | ||||||
|         <servlet-class>net.sourceforge.guacamole.net.basic.ConfigurationList</servlet-class> |         <servlet-class>net.sourceforge.guacamole.net.basic.ConnectionList</servlet-class> | ||||||
|     </servlet> |     </servlet> | ||||||
|     <servlet-mapping> |     <servlet-mapping> | ||||||
|         <servlet-name>Configs</servlet-name> |         <servlet-name>Connections</servlet-name> | ||||||
|         <url-pattern>/configs</url-pattern> |         <url-pattern>/connections</url-pattern> | ||||||
|     </servlet-mapping> |     </servlet-mapping> | ||||||
|  |  | ||||||
|     <!-- User List Servlet --> |     <!-- User List Servlet --> | ||||||
|   | |||||||
| @@ -136,7 +136,6 @@ | |||||||
|             Guacamole ${project.version} |             Guacamole ${project.version} | ||||||
|         </div> |         </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/session.js"></script> | ||||||
|         <script type="text/javascript" src="scripts/history.js"></script> |         <script type="text/javascript" src="scripts/history.js"></script> | ||||||
|         <script type="text/javascript" src="scripts/root-ui.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