mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-30 00:23:21 +00:00 
			
		
		
		
	GUAC-1132: Add tunnel rest service stub.
This commit is contained in:
		| @@ -31,6 +31,7 @@ import org.glyptodon.guacamole.net.basic.rest.clipboard.ClipboardRESTService; | ||||
| import org.glyptodon.guacamole.net.basic.rest.connection.ConnectionRESTService; | ||||
| import org.glyptodon.guacamole.net.basic.rest.connectiongroup.ConnectionGroupRESTService; | ||||
| import org.glyptodon.guacamole.net.basic.rest.protocol.ProtocolRESTService; | ||||
| import org.glyptodon.guacamole.net.basic.rest.tunnel.TunnelRESTService; | ||||
| import org.glyptodon.guacamole.net.basic.rest.user.UserRESTService; | ||||
|  | ||||
| /** | ||||
| @@ -50,6 +51,7 @@ public class RESTServletModule extends ServletModule { | ||||
|         bind(ProtocolRESTService.class); | ||||
|         bind(UserRESTService.class); | ||||
|         bind(TokenRESTService.class); | ||||
|         bind(TunnelRESTService.class); | ||||
|          | ||||
|         // Set up the servlet and JSON mappings | ||||
|         bind(GuiceContainer.class); | ||||
|   | ||||
| @@ -0,0 +1,111 @@ | ||||
| /* | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.net.basic.rest.tunnel; | ||||
|  | ||||
| import java.util.Date; | ||||
| import org.glyptodon.guacamole.net.auth.ConnectionRecord; | ||||
|  | ||||
| /** | ||||
|  * Tunnel-related information which may be exposed through the REST endpoints. | ||||
|  *  | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class APITunnel { | ||||
|  | ||||
|     /** | ||||
|      * The date and time the connection began. | ||||
|      */ | ||||
|     private final Date startDate; | ||||
|  | ||||
|     /** | ||||
|      * The host from which the connection originated, if known. | ||||
|      */ | ||||
|     private final String remoteHost; | ||||
|      | ||||
|     /** | ||||
|      * The name of the user who used or is using the connection. | ||||
|      */ | ||||
|     private final String username; | ||||
|  | ||||
|     /** | ||||
|      * The UUID of the tunnel. | ||||
|      */ | ||||
|     private final String uuid; | ||||
|      | ||||
|     /** | ||||
|      * Creates a new APITunnel, copying the information from the given | ||||
|      * connection record. | ||||
|      * | ||||
|      * @param record | ||||
|      *     The record to copy data from. | ||||
|      */ | ||||
|     public APITunnel(ConnectionRecord record) { | ||||
|         this.startDate  = record.getStartDate(); | ||||
|         this.remoteHost = record.getRemoteHost(); | ||||
|         this.username   = record.getUsername(); | ||||
|         this.uuid       = "STUB"; // STUB | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the date and time the connection began. | ||||
|      * | ||||
|      * @return | ||||
|      *     The date and time the connection began. | ||||
|      */ | ||||
|     public Date getStartDate() { | ||||
|         return startDate; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the remote host from which this connection originated. | ||||
|      * | ||||
|      * @return | ||||
|      *     The remote host from which this connection originated. | ||||
|      */ | ||||
|     public String getRemoteHost() { | ||||
|         return remoteHost; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the name of the user who used or is using the connection at the | ||||
|      * times given by this tunnel. | ||||
|      * | ||||
|      * @return | ||||
|      *     The name of the user who used or is using the associated connection. | ||||
|      */ | ||||
|     public String getUsername() { | ||||
|         return username; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the UUID of the underlying Guacamole tunnel. Absolutely every | ||||
|      * Guacamole tunnel has an associated UUID. | ||||
|      * | ||||
|      * @return | ||||
|      *     The UUID of the underlying Guacamole tunnel. | ||||
|      */ | ||||
|     public String getUUID() { | ||||
|         return uuid; | ||||
|     } | ||||
|      | ||||
| } | ||||
| @@ -0,0 +1,125 @@ | ||||
| /* | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.net.basic.rest.tunnel; | ||||
|  | ||||
| import com.google.inject.Inject; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import javax.ws.rs.Consumes; | ||||
| import javax.ws.rs.DELETE; | ||||
| import javax.ws.rs.GET; | ||||
| import javax.ws.rs.Path; | ||||
| import javax.ws.rs.PathParam; | ||||
| import javax.ws.rs.Produces; | ||||
| import javax.ws.rs.QueryParam; | ||||
| import javax.ws.rs.core.MediaType; | ||||
| import org.glyptodon.guacamole.GuacamoleException; | ||||
| import org.glyptodon.guacamole.GuacamoleUnsupportedException; | ||||
| import org.glyptodon.guacamole.net.auth.ConnectionRecord; | ||||
| import org.glyptodon.guacamole.net.auth.UserContext; | ||||
| import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; | ||||
| import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| /** | ||||
|  * A REST Service for retrieving and managing the tunnels of active connections. | ||||
|  *  | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| @Path("/tunnels") | ||||
| @Produces(MediaType.APPLICATION_JSON) | ||||
| @Consumes(MediaType.APPLICATION_JSON) | ||||
| public class TunnelRESTService { | ||||
|  | ||||
|     /** | ||||
|      * Logger for this class. | ||||
|      */ | ||||
|     private static final Logger logger = LoggerFactory.getLogger(TunnelRESTService.class); | ||||
|  | ||||
|     /** | ||||
|      * A service for authenticating users from auth tokens. | ||||
|      */ | ||||
|     @Inject | ||||
|     private AuthenticationService authenticationService; | ||||
|      | ||||
|     /** | ||||
|      * Retrieves the tunnels of all active connections visible to the current | ||||
|      * user. | ||||
|      *  | ||||
|      * @param authToken | ||||
|      *     The authentication token that is used to authenticate the user | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @return | ||||
|      *     The tunnels of all active connections visible to the current user. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving the tunnels. | ||||
|      */ | ||||
|     @GET | ||||
|     @Path("/") | ||||
|     @AuthProviderRESTExposure | ||||
|     public List<APITunnel> getTunnels(@QueryParam("token") String authToken) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         UserContext userContext = authenticationService.getUserContext(authToken); | ||||
|  | ||||
|         // Retrieve all active tunnels | ||||
|         List<APITunnel> apiTunnels = new ArrayList<APITunnel>(); | ||||
|         for (ConnectionRecord record : userContext.getActiveConnections()) | ||||
|             apiTunnels.add(new APITunnel(record)); | ||||
|  | ||||
|         return apiTunnels; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Deletes the tunnel having the given UUID, effectively closing the | ||||
|      * tunnel and killing the associated connection. | ||||
|      *  | ||||
|      * @param authToken | ||||
|      *     The authentication token that is used to authenticate the user | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @param tunnelUUID | ||||
|      *     The UUID associated with the tunnel being deleted. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while deleting the tunnel. | ||||
|      */ | ||||
|     @DELETE | ||||
|     @Path("/{tunnelUUID}") | ||||
|     @AuthProviderRESTExposure | ||||
|     public void deleteTunnel(@QueryParam("token") String authToken, | ||||
|             @PathParam("tunnelUUID") String tunnelUUID)  | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         UserContext userContext = authenticationService.getUserContext(authToken); | ||||
|  | ||||
|         // STUB | ||||
|         throw new GuacamoleUnsupportedException("STUB"); | ||||
|          | ||||
|     } | ||||
|      | ||||
| } | ||||
		Reference in New Issue
	
	Block a user