mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	GUAC-1086: Split TunnelRequestService.createTunnel method into three methods solving separate tasks.
This commit is contained in:
		| @@ -148,33 +148,13 @@ public class TunnelRequestService { | |||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|      |  | ||||||
|     /** |     /** | ||||||
|      * Creates a new tunnel using the parameters and credentials present in |      * Reads and returns client information provided by the {@code request} parameter. | ||||||
|      * the given request. |  | ||||||
|      * |      * | ||||||
|      * @param request The request describing the tunnel to create. |      * @param request The request describing tunnel to create. | ||||||
|      * @return The created tunnel, or null if the tunnel could not be created. |      * @return GuacamoleClientInformation Object containing information about the client sending the tunnel request. | ||||||
|      * @throws GuacamoleException If an error occurs while creating the tunnel. |  | ||||||
|      */ |      */ | ||||||
|     public GuacamoleTunnel createTunnel(TunnelRequest request) |     protected GuacamoleClientInformation getClientInformation(TunnelRequest request) { | ||||||
|             throws GuacamoleException { |  | ||||||
|  |  | ||||||
|         // Get auth token and session |  | ||||||
|         final String authToken = request.getParameter("authToken"); |  | ||||||
|         GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); |  | ||||||
|  |  | ||||||
|         // Get ID of connection |  | ||||||
|         String id = request.getParameter("id"); |  | ||||||
|         TunnelRequest.IdentifierType id_type = TunnelRequest.IdentifierType.getType(id); |  | ||||||
|  |  | ||||||
|         // Do not continue if unable to determine type |  | ||||||
|         if (id_type == null) |  | ||||||
|             throw new GuacamoleClientException("Illegal identifier - unknown type."); |  | ||||||
|  |  | ||||||
|         // Remove prefix |  | ||||||
|         id = id.substring(id_type.PREFIX.length()); |  | ||||||
|  |  | ||||||
|         // Get client information |         // Get client information | ||||||
|         GuacamoleClientInformation info = new GuacamoleClientInformation(); |         GuacamoleClientInformation info = new GuacamoleClientInformation(); | ||||||
|  |  | ||||||
| @@ -203,6 +183,32 @@ public class TunnelRequestService { | |||||||
|         if (video_mimetypes != null) |         if (video_mimetypes != null) | ||||||
|             info.getVideoMimetypes().addAll(video_mimetypes); |             info.getVideoMimetypes().addAll(video_mimetypes); | ||||||
|  |  | ||||||
|  |         return info; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Creates a new socket using client information specified in the {@code info} parameter, | ||||||
|  |      * connection information from {@code request} and credentials from the {@code session} parameter. | ||||||
|  |      * | ||||||
|  |      * @param request The request describing tunnel to create. | ||||||
|  |      * @param session Current guacamole session. | ||||||
|  |      * @param info Guacamole client information. | ||||||
|  |      * @return Socket connected using the provided settings. | ||||||
|  |      * @throws GuacamoleException If an error occurs while creating the socket. | ||||||
|  |      */ | ||||||
|  |     protected GuacamoleSocket createConnectedSocket(TunnelRequest request, GuacamoleSession session, | ||||||
|  |                                                     GuacamoleClientInformation info) throws GuacamoleException { | ||||||
|  |         // Get ID of connection | ||||||
|  |         String id = request.getParameter("id"); | ||||||
|  |         TunnelRequest.IdentifierType id_type = TunnelRequest.IdentifierType.getType(id); | ||||||
|  |  | ||||||
|  |         // Do not continue if unable to determine type | ||||||
|  |         if (id_type == null) | ||||||
|  |             throw new GuacamoleClientException("Illegal identifier - unknown type."); | ||||||
|  |  | ||||||
|  |         // Remove prefix | ||||||
|  |         id = id.substring(id_type.PREFIX.length()); | ||||||
|  |  | ||||||
|         // Create connected socket from identifier |         // Create connected socket from identifier | ||||||
|         GuacamoleSocket socket; |         GuacamoleSocket socket; | ||||||
|         switch (id_type) { |         switch (id_type) { | ||||||
| @@ -256,9 +262,21 @@ public class TunnelRequestService { | |||||||
|                 throw new GuacamoleClientException("Connection not supported for provided identifier type."); |                 throw new GuacamoleClientException("Connection not supported for provided identifier type."); | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |         return socket; | ||||||
|  |     } | ||||||
|  |  | ||||||
|         // Associate socket with tunnel |  | ||||||
|         GuacamoleTunnel tunnel = new GuacamoleTunnel(socket) { |     /** | ||||||
|  |      * Creates and returns a tunnel using the specified guacd socket. | ||||||
|  |      * The tunnel is associated with a session identified | ||||||
|  |      * by the {@code authToken} parameter. | ||||||
|  |      * | ||||||
|  |      * @param socket The connected socket. | ||||||
|  |      * @param authToken Current authorization token. | ||||||
|  |      * @return The created tunnel. | ||||||
|  |      */ | ||||||
|  |     protected GuacamoleTunnel createAssociatedTunnel(GuacamoleSocket socket, final String authToken) { | ||||||
|  |         return new GuacamoleTunnel(socket) { | ||||||
|  |  | ||||||
|             @Override |             @Override | ||||||
|             public GuacamoleReader acquireReader() { |             public GuacamoleReader acquireReader() { | ||||||
| @@ -310,6 +328,32 @@ public class TunnelRequestService { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|         }; |         }; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |      | ||||||
|  |     /** | ||||||
|  |      * Creates a new tunnel using the parameters and credentials present in | ||||||
|  |      * the given request. | ||||||
|  |      *  | ||||||
|  |      * @param request The request describing the tunnel to create. | ||||||
|  |      * @return The created tunnel, or null if the tunnel could not be created. | ||||||
|  |      * @throws GuacamoleException If an error occurs while creating the tunnel. | ||||||
|  |      */ | ||||||
|  |     public GuacamoleTunnel createTunnel(TunnelRequest request) | ||||||
|  |             throws GuacamoleException { | ||||||
|  |  | ||||||
|  |         // Get auth token and session | ||||||
|  |         final String authToken = request.getParameter("authToken"); | ||||||
|  |         final GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); | ||||||
|  |  | ||||||
|  |         // Get client information | ||||||
|  |         final GuacamoleClientInformation info = getClientInformation(request); | ||||||
|  |  | ||||||
|  |         // Create connected socket from identifier | ||||||
|  |         final GuacamoleSocket socket = createConnectedSocket(request, session, info); | ||||||
|  |  | ||||||
|  |         // Associate socket with tunnel | ||||||
|  |         GuacamoleTunnel tunnel = createAssociatedTunnel(socket, authToken); | ||||||
|  |  | ||||||
|         // Notify listeners about connection |         // Notify listeners about connection | ||||||
|         if (!notifyConnect(session, tunnel)) { |         if (!notifyConnect(session, tunnel)) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user