GUAC-586: Use auth provider identifiers within schema REST service.

This commit is contained in:
Michael Jumper
2015-08-31 00:14:22 -07:00
parent ce064cfc68
commit 0f661dfec3
2 changed files with 82 additions and 18 deletions

View File

@@ -28,6 +28,7 @@ import java.util.Map;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@@ -36,7 +37,9 @@ import org.glyptodon.guacamole.environment.Environment;
import org.glyptodon.guacamole.environment.LocalEnvironment; import org.glyptodon.guacamole.environment.LocalEnvironment;
import org.glyptodon.guacamole.form.Form; import org.glyptodon.guacamole.form.Form;
import org.glyptodon.guacamole.net.auth.UserContext; import org.glyptodon.guacamole.net.auth.UserContext;
import org.glyptodon.guacamole.net.basic.GuacamoleSession;
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
import org.glyptodon.guacamole.net.basic.rest.ObjectRetrievalService;
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
import org.glyptodon.guacamole.protocols.ProtocolInfo; import org.glyptodon.guacamole.protocols.ProtocolInfo;
@@ -46,7 +49,7 @@ import org.glyptodon.guacamole.protocols.ProtocolInfo;
* *
* @author Michael Jumper * @author Michael Jumper
*/ */
@Path("/schema") @Path("/schema/{dataSource}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public class SchemaRESTService { public class SchemaRESTService {
@@ -57,6 +60,12 @@ public class SchemaRESTService {
@Inject @Inject
private AuthenticationService authenticationService; private AuthenticationService authenticationService;
/**
* Service for convenient retrieval of objects.
*/
@Inject
private ObjectRetrievalService retrievalService;
/** /**
* Retrieves the possible attributes of a user object. * Retrieves the possible attributes of a user object.
* *
@@ -64,6 +73,10 @@ public class SchemaRESTService {
* The authentication token that is used to authenticate the user * The authentication token that is used to authenticate the user
* performing the operation. * performing the operation.
* *
* @param authProviderIdentifier
* The unique identifier of the AuthenticationProvider associated with
* the UserContext dictating the available user attributes.
*
* @return * @return
* A collection of forms which describe the possible attributes of a * A collection of forms which describe the possible attributes of a
* user object. * user object.
@@ -74,10 +87,13 @@ public class SchemaRESTService {
@GET @GET
@Path("/users/attributes") @Path("/users/attributes")
@AuthProviderRESTExposure @AuthProviderRESTExposure
public Collection<Form> getUserAttributes(@QueryParam("token") String authToken) throws GuacamoleException { public Collection<Form> getUserAttributes(@QueryParam("token") String authToken,
@PathParam("dataSource") String authProviderIdentifier)
throws GuacamoleException {
// Retrieve all possible user attributes // Retrieve all possible user attributes
UserContext userContext = authenticationService.getUserContext(authToken); GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
return userContext.getUserAttributes(); return userContext.getUserAttributes();
} }
@@ -89,6 +105,10 @@ public class SchemaRESTService {
* The authentication token that is used to authenticate the user * The authentication token that is used to authenticate the user
* performing the operation. * performing the operation.
* *
* @param authProviderIdentifier
* The unique identifier of the AuthenticationProvider associated with
* the UserContext dictating the available connection attributes.
*
* @return * @return
* A collection of forms which describe the possible attributes of a * A collection of forms which describe the possible attributes of a
* connection object. * connection object.
@@ -99,10 +119,13 @@ public class SchemaRESTService {
@GET @GET
@Path("/connections/attributes") @Path("/connections/attributes")
@AuthProviderRESTExposure @AuthProviderRESTExposure
public Collection<Form> getConnectionAttributes(@QueryParam("token") String authToken) throws GuacamoleException { public Collection<Form> getConnectionAttributes(@QueryParam("token") String authToken,
@PathParam("dataSource") String authProviderIdentifier)
throws GuacamoleException {
// Retrieve all possible connection attributes // Retrieve all possible connection attributes
UserContext userContext = authenticationService.getUserContext(authToken); GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
return userContext.getConnectionAttributes(); return userContext.getConnectionAttributes();
} }
@@ -114,6 +137,11 @@ public class SchemaRESTService {
* The authentication token that is used to authenticate the user * The authentication token that is used to authenticate the user
* performing the operation. * performing the operation.
* *
* @param authProviderIdentifier
* The unique identifier of the AuthenticationProvider associated with
* the UserContext dictating the available connection group
* attributes.
*
* @return * @return
* A collection of forms which describe the possible attributes of a * A collection of forms which describe the possible attributes of a
* connection group object. * connection group object.
@@ -124,10 +152,13 @@ public class SchemaRESTService {
@GET @GET
@Path("/connectionGroups/attributes") @Path("/connectionGroups/attributes")
@AuthProviderRESTExposure @AuthProviderRESTExposure
public Collection<Form> getConnectionGroupAttributes(@QueryParam("token") String authToken) throws GuacamoleException { public Collection<Form> getConnectionGroupAttributes(@QueryParam("token") String authToken,
@PathParam("dataSource") String authProviderIdentifier)
throws GuacamoleException {
// Retrieve all possible connection group attributes // Retrieve all possible connection group attributes
UserContext userContext = authenticationService.getUserContext(authToken); GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
return userContext.getConnectionGroupAttributes(); return userContext.getConnectionGroupAttributes();
} }
@@ -139,6 +170,13 @@ public class SchemaRESTService {
* The authentication token that is used to authenticate the user * The authentication token that is used to authenticate the user
* performing the operation. * performing the operation.
* *
* @param authProviderIdentifier
* The unique identifier of the AuthenticationProvider associated with
* the UserContext dictating the protocols available. Currently, the
* UserContext actually does not dictate this, the the same set of
* protocols will be retrieved for all users, though the identifier
* given here will be validated.
*
* @return * @return
* A map of protocol information, where each key is the unique name * A map of protocol information, where each key is the unique name
* associated with that protocol. * associated with that protocol.
@@ -149,10 +187,13 @@ public class SchemaRESTService {
@GET @GET
@Path("/protocols") @Path("/protocols")
@AuthProviderRESTExposure @AuthProviderRESTExposure
public Map<String, ProtocolInfo> getProtocols(@QueryParam("token") String authToken) throws GuacamoleException { public Map<String, ProtocolInfo> getProtocols(@QueryParam("token") String authToken,
@PathParam("dataSource") String authProviderIdentifier)
throws GuacamoleException {
// Verify the given auth token is valid // Verify the given auth token and auth provider identifier are valid
authenticationService.getUserContext(authToken); GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
retrievalService.retrieveUserContext(session, authProviderIdentifier);
// Get and return a map of all protocols. // Get and return a map of all protocols.
Environment env = new LocalEnvironment(); Environment env = new LocalEnvironment();

View File

@@ -39,12 +39,18 @@ angular.module('rest').factory('schemaService', ['$injector',
* @link{Form} objects if successful. Each element of the array describes * @link{Form} objects if successful. Each element of the array describes
* a logical grouping of possible attributes. * a logical grouping of possible attributes.
* *
* @param {String} dataSource
* The unique identifier of the data source containing the users whose
* available attributes are to be retrieved. This identifier
* corresponds to an AuthenticationProvider within the Guacamole web
* application.
*
* @returns {Promise.<Form[]>} * @returns {Promise.<Form[]>}
* A promise which will resolve with an array of @link{Form} * A promise which will resolve with an array of @link{Form}
* objects, where each @link{Form} describes a logical grouping of * objects, where each @link{Form} describes a logical grouping of
* possible attributes. * possible attributes.
*/ */
service.getUserAttributes = function getUserAttributes() { service.getUserAttributes = function getUserAttributes(dataSource) {
// Build HTTP parameters set // Build HTTP parameters set
var httpParameters = { var httpParameters = {
@@ -55,7 +61,7 @@ angular.module('rest').factory('schemaService', ['$injector',
return $http({ return $http({
cache : cacheService.schema, cache : cacheService.schema,
method : 'GET', method : 'GET',
url : 'api/schema/users/attributes', url : 'api/schema/' + encodeURIComponent(dataSource) + '/users/attributes',
params : httpParameters params : httpParameters
}); });
@@ -67,12 +73,18 @@ angular.module('rest').factory('schemaService', ['$injector',
* @link{Form} objects if successful. Each element of the array describes * @link{Form} objects if successful. Each element of the array describes
* a logical grouping of possible attributes. * a logical grouping of possible attributes.
* *
* @param {String} dataSource
* The unique identifier of the data source containing the connections
* whose available attributes are to be retrieved. This identifier
* corresponds to an AuthenticationProvider within the Guacamole web
* application.
*
* @returns {Promise.<Form[]>} * @returns {Promise.<Form[]>}
* A promise which will resolve with an array of @link{Form} * A promise which will resolve with an array of @link{Form}
* objects, where each @link{Form} describes a logical grouping of * objects, where each @link{Form} describes a logical grouping of
* possible attributes. * possible attributes.
*/ */
service.getConnectionAttributes = function getConnectionAttributes() { service.getConnectionAttributes = function getConnectionAttributes(dataSource) {
// Build HTTP parameters set // Build HTTP parameters set
var httpParameters = { var httpParameters = {
@@ -83,7 +95,7 @@ angular.module('rest').factory('schemaService', ['$injector',
return $http({ return $http({
cache : cacheService.schema, cache : cacheService.schema,
method : 'GET', method : 'GET',
url : 'api/schema/connections/attributes', url : 'api/schema/' + encodeURIComponent(dataSource) + '/connections/attributes',
params : httpParameters params : httpParameters
}); });
@@ -95,12 +107,18 @@ angular.module('rest').factory('schemaService', ['$injector',
* of @link{Form} objects if successful. Each element of the array * of @link{Form} objects if successful. Each element of the array
* a logical grouping of possible attributes. * a logical grouping of possible attributes.
* *
* @param {String} dataSource
* The unique identifier of the data source containing the connection
* groups whose available attributes are to be retrieved. This
* identifier corresponds to an AuthenticationProvider within the
* Guacamole web application.
*
* @returns {Promise.<Form[]>} * @returns {Promise.<Form[]>}
* A promise which will resolve with an array of @link{Form} * A promise which will resolve with an array of @link{Form}
* objects, where each @link{Form} describes a logical grouping of * objects, where each @link{Form} describes a logical grouping of
* possible attributes. * possible attributes.
*/ */
service.getConnectionGroupAttributes = function getConnectionGroupAttributes() { service.getConnectionGroupAttributes = function getConnectionGroupAttributes(dataSource) {
// Build HTTP parameters set // Build HTTP parameters set
var httpParameters = { var httpParameters = {
@@ -111,7 +129,7 @@ angular.module('rest').factory('schemaService', ['$injector',
return $http({ return $http({
cache : cacheService.schema, cache : cacheService.schema,
method : 'GET', method : 'GET',
url : 'api/schema/connectionGroups/attributes', url : 'api/schema/' + encodeURIComponent(dataSource) + '/connectionGroups/attributes',
params : httpParameters params : httpParameters
}); });
@@ -122,11 +140,16 @@ angular.module('rest').factory('schemaService', ['$injector',
* a promise that provides a map of @link{Protocol} objects by protocol * a promise that provides a map of @link{Protocol} objects by protocol
* name if successful. * name if successful.
* *
* @param {String} dataSource
* The unique identifier of the data source defining available
* protocols. This identifier corresponds to an AuthenticationProvider
* within the Guacamole web application.
*
* @returns {Promise.<Object.<String, Protocol>>} * @returns {Promise.<Object.<String, Protocol>>}
* A promise which will resolve with a map of @link{Protocol} * A promise which will resolve with a map of @link{Protocol}
* objects by protocol name upon success. * objects by protocol name upon success.
*/ */
service.getProtocols = function getProtocols() { service.getProtocols = function getProtocols(dataSource) {
// Build HTTP parameters set // Build HTTP parameters set
var httpParameters = { var httpParameters = {
@@ -137,7 +160,7 @@ angular.module('rest').factory('schemaService', ['$injector',
return $http({ return $http({
cache : cacheService.schema, cache : cacheService.schema,
method : 'GET', method : 'GET',
url : 'api/schema/protocols', url : 'api/schema/' + encodeURIComponent(dataSource) + '/protocols',
params : httpParameters params : httpParameters
}); });