GUACAMOLE-289: Isolate extension REST services to ".../api/ext/" and ".../api/session/ext".

This commit is contained in:
Michael Jumper
2017-04-29 13:38:52 -07:00
parent 4455cbc781
commit aa261410f4
3 changed files with 38 additions and 28 deletions

View File

@@ -43,8 +43,9 @@ public interface UserContext {
* properly annotated with JSR-311 annotations, and may serve as the root * properly annotated with JSR-311 annotations, and may serve as the root
* resource for any number of extension-specific REST resources related to * resource for any number of extension-specific REST resources related to
* an authenticated user's session. The returned resource is ultimately * an authenticated user's session. The returned resource is ultimately
* exposed at ".../api/session/data/IDENTIFIER/ext/", where IDENTIFIER is * exposed at ".../api/session/ext/IDENTIFIER/", where IDENTIFIER is the
* the identifier of the AuthenticationProvider. * identifier of the AuthenticationProvider associated with this
* UserContext.
* *
* REST resources which are NOT related to an authenticated user's session * REST resources which are NOT related to an authenticated user's session
* should instead be returned from AuthenticationProvider.getResource(). * should instead be returned from AuthenticationProvider.getResource().

View File

@@ -28,6 +28,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleResourceNotFoundException;
import org.apache.guacamole.GuacamoleSession; import org.apache.guacamole.GuacamoleSession;
import org.apache.guacamole.net.auth.UserContext; import org.apache.guacamole.net.auth.UserContext;
import org.apache.guacamole.rest.tunnel.TunnelCollectionResource; 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 * Retrieves a resource representing all tunnels associated with session
* exposed by this SessionResource. * exposed by this SessionResource.

View File

@@ -29,7 +29,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleResourceNotFoundException;
import org.apache.guacamole.net.auth.ActiveConnection; import org.apache.guacamole.net.auth.ActiveConnection;
import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup; import org.apache.guacamole.net.auth.ConnectionGroup;
@@ -254,29 +253,4 @@ public class UserContextResource {
return new SchemaResource(userContext); 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.");
}
} }