mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	GUAC-919: Rename LoginRESTService to TokenRESTService and provide logout semantics. Move Angular auth stuff to own module. Actually logout user.
This commit is contained in:
		| @@ -26,7 +26,7 @@ import com.google.inject.Scopes; | ||||
| import com.google.inject.servlet.ServletModule; | ||||
| import com.sun.jersey.guice.spi.container.servlet.GuiceContainer; | ||||
| import org.codehaus.jackson.jaxrs.JacksonJsonProvider; | ||||
| import org.glyptodon.guacamole.net.basic.rest.auth.LoginRESTService; | ||||
| import org.glyptodon.guacamole.net.basic.rest.auth.TokenRESTService; | ||||
| 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; | ||||
| @@ -51,7 +51,7 @@ public class RESTServletModule extends ServletModule { | ||||
|         bind(PermissionRESTService.class); | ||||
|         bind(ProtocolRESTService.class); | ||||
|         bind(UserRESTService.class); | ||||
|         bind(LoginRESTService.class); | ||||
|         bind(TokenRESTService.class); | ||||
|          | ||||
|         // Set up the servlet and JSON mappings | ||||
|         bind(GuiceContainer.class); | ||||
|   | ||||
| @@ -131,6 +131,7 @@ public class BasicTokenSessionMap implements TokenSessionMap { | ||||
|                 if (age >= sessionTimeout) { | ||||
|                     logger.debug("Session \"{}\" has timed out.", entry.getKey()); | ||||
|                     entries.remove(); | ||||
|                     session.invalidate(); | ||||
|                 } | ||||
|  | ||||
|                 // Otherwise, no other sessions can possibly be old enough | ||||
| @@ -162,9 +163,14 @@ public class BasicTokenSessionMap implements TokenSessionMap { | ||||
|         sessionMap.put(authToken, session); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public GuacamoleSession remove(String authToken) { | ||||
|         return sessionMap.remove(authToken); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void shutdown() { | ||||
|         executor.shutdownNow(); | ||||
|     } | ||||
|      | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -24,9 +24,11 @@ package org.glyptodon.guacamole.net.basic.rest.auth; | ||||
| 
 | ||||
| import com.google.inject.Inject; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import javax.ws.rs.DELETE; | ||||
| import javax.ws.rs.FormParam; | ||||
| import javax.ws.rs.POST; | ||||
| import javax.ws.rs.Path; | ||||
| import javax.ws.rs.PathParam; | ||||
| import javax.ws.rs.Produces; | ||||
| import javax.ws.rs.core.Context; | ||||
| import javax.ws.rs.core.MediaType; | ||||
| @@ -42,16 +44,13 @@ import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| 
 | ||||
| /** | ||||
|  * A service for authenticating to the Guacamole REST API. Given valid | ||||
|  * credentials, the service will return an auth token. Invalid credentials will | ||||
|  * result in a permission error. | ||||
|  * A service for managing auth tokens via the Guacamole REST API. | ||||
|  *  | ||||
|  * @author James Muehlner | ||||
|  */ | ||||
| 
 | ||||
| @Path("/login") | ||||
| @Path("/token") | ||||
| @Produces(MediaType.APPLICATION_JSON) | ||||
| public class LoginRESTService { | ||||
| public class TokenRESTService { | ||||
|      | ||||
|     /** | ||||
|      * The authentication provider used to authenticate this user. | ||||
| @@ -74,7 +73,7 @@ public class LoginRESTService { | ||||
|     /** | ||||
|      * Logger for this class. | ||||
|      */ | ||||
|     private static final Logger logger = LoggerFactory.getLogger(LoginRESTService.class); | ||||
|     private static final Logger logger = LoggerFactory.getLogger(TokenRESTService.class); | ||||
|      | ||||
|     /** | ||||
|      * Authenticates a user, generates an auth token, associates that auth token | ||||
| @@ -88,7 +87,7 @@ public class LoginRESTService { | ||||
|      */ | ||||
|     @POST | ||||
|     @AuthProviderRESTExposure | ||||
|     public APIAuthToken login(@FormParam("username") String username, | ||||
|     public APIAuthToken createToken(@FormParam("username") String username, | ||||
|             @FormParam("password") String password,  | ||||
|             @Context HttpServletRequest request) throws GuacamoleException { | ||||
|          | ||||
| @@ -120,5 +119,24 @@ public class LoginRESTService { | ||||
|         return new APIAuthToken(authToken, username); | ||||
| 
 | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     /** | ||||
|      * Invalidates a specific auth token, effectively logging out the associated | ||||
|      * user. | ||||
|      *  | ||||
|      * @param authToken The token being invalidated. | ||||
|      */ | ||||
|     @DELETE | ||||
|     @Path("/{token}") | ||||
|     @AuthProviderRESTExposure | ||||
|     public void invalidateToken(@PathParam("token") String authToken) { | ||||
|          | ||||
|         GuacamoleSession session = tokenSessionMap.remove(authToken); | ||||
|         if (session == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No such token."); | ||||
| 
 | ||||
|         session.invalidate(); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @@ -51,6 +51,15 @@ public interface TokenSessionMap { | ||||
|      */ | ||||
|     public GuacamoleSession get(String authToken); | ||||
|  | ||||
|     /** | ||||
|      * Removes the GuacamoleSession associated with the given auth token. | ||||
|      * | ||||
|      * @param authToken The token to remove. | ||||
|      * @return The GuacamoleSession for the given auth token, if the auth token | ||||
|      *         represents a currently logged in user, null otherwise. | ||||
|      */ | ||||
|     public GuacamoleSession remove(String authToken); | ||||
|      | ||||
|     /** | ||||
|      * Shuts down this session map, disallowing future sessions and reclaiming | ||||
|      * any resources. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user