From aa261410f4a457da99fcf49baed605697a853729 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 29 Apr 2017 13:38:52 -0700 Subject: [PATCH] GUACAMOLE-289: Isolate extension REST services to ".../api/ext/" and ".../api/session/ext". --- .../guacamole/net/auth/UserContext.java | 5 +-- .../rest/session/SessionResource.java | 35 +++++++++++++++++++ .../rest/session/UserContextResource.java | 26 -------------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/UserContext.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/UserContext.java index 7c483376a..10fd6bf5c 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/UserContext.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/UserContext.java @@ -43,8 +43,9 @@ public interface UserContext { * properly annotated with JSR-311 annotations, and may serve as the root * resource for any number of extension-specific REST resources related to * an authenticated user's session. The returned resource is ultimately - * exposed at ".../api/session/data/IDENTIFIER/ext/", where IDENTIFIER is - * the identifier of the AuthenticationProvider. + * exposed at ".../api/session/ext/IDENTIFIER/", where IDENTIFIER is the + * identifier of the AuthenticationProvider associated with this + * UserContext. * * REST resources which are NOT related to an authenticated user's session * should instead be returned from AuthenticationProvider.getResource(). diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/session/SessionResource.java b/guacamole/src/main/java/org/apache/guacamole/rest/session/SessionResource.java index 568df4f2b..606e78b4d 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/session/SessionResource.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/session/SessionResource.java @@ -28,6 +28,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.GuacamoleResourceNotFoundException; import org.apache.guacamole.GuacamoleSession; import org.apache.guacamole.net.auth.UserContext; import org.apache.guacamole.rest.tunnel.TunnelCollectionResource; @@ -101,6 +102,40 @@ public class SessionResource { } + /** + * Returns the arbitrary REST resource exposed by the UserContext + * associated with the AuthenticationProvider having the given identifier. + * + * @param authProviderIdentifier + * The unique identifier of the AuthenticationProvider associated with + * the UserContext whose arbitrary REST service is being retrieved. + * + * @return + * The arbitrary REST resource exposed by the UserContext exposed by + * this UserContextresource. + * + * @throws GuacamoleException + * If no such resource could be found, or if an error occurs while + * retrieving that resource. + */ + @Path("ext/{dataSource}") + public Object getExtensionResource( + @PathParam("dataSource") String authProviderIdentifier) + throws GuacamoleException { + + // Pull UserContext defined by the given auth provider identifier + UserContext userContext = session.getUserContext(authProviderIdentifier); + + // Pull resource from user context + Object resource = userContext.getResource(); + if (resource != null) + return resource; + + // UserContext-specific resource could not be found + throw new GuacamoleResourceNotFoundException("No such resource."); + + } + /** * Retrieves a resource representing all tunnels associated with session * exposed by this SessionResource. diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java b/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java index b2e5eaade..29b443f16 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java @@ -29,7 +29,6 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.apache.guacamole.GuacamoleException; -import org.apache.guacamole.GuacamoleResourceNotFoundException; import org.apache.guacamole.net.auth.ActiveConnection; import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.ConnectionGroup; @@ -254,29 +253,4 @@ public class UserContextResource { return new SchemaResource(userContext); } - /** - * Returns the arbitrary REST resource exposed by the UserContext exposed - * by this UserContextResource. - * - * @return - * The arbitrary REST resource exposed by the UserContext exposed by - * this UserContextresource. - * - * @throws GuacamoleException - * If no such resource could be found, or if an error occurs while - * retrieving that resource. - */ - @Path("ext") - public Object getExtensionResource() throws GuacamoleException { - - // Pull resource from user context - Object resource = userContext.getResource(); - if (resource != null) - return resource; - - // UserContext-specific resource could not be found - throw new GuacamoleResourceNotFoundException("No such resource."); - - } - }