mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53: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()); | ||||
|  | ||||
|                 } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user