diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java b/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java index c6de0dc29..88551b353 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java @@ -38,7 +38,6 @@ import org.apache.guacamole.rest.connection.ConnectionModule; import org.apache.guacamole.rest.connectiongroup.ConnectionGroupModule; import org.apache.guacamole.rest.language.LanguageRESTService; import org.apache.guacamole.rest.patch.PatchRESTService; -import org.apache.guacamole.rest.schema.SchemaRESTService; import org.apache.guacamole.rest.tunnel.TunnelRESTService; import org.apache.guacamole.rest.user.UserModule; @@ -89,7 +88,6 @@ public class RESTServiceModule extends ServletModule { // Set up the API endpoints bind(LanguageRESTService.class); bind(PatchRESTService.class); - bind(SchemaRESTService.class); bind(TokenRESTService.class); bind(TunnelRESTService.class); diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/schema/SchemaRESTService.java b/guacamole/src/main/java/org/apache/guacamole/rest/schema/SchemaRESTService.java deleted file mode 100644 index a5d9d909b..000000000 --- a/guacamole/src/main/java/org/apache/guacamole/rest/schema/SchemaRESTService.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.guacamole.rest.schema; - -import com.google.inject.Inject; -import java.util.Collection; -import java.util.Map; -import javax.ws.rs.Consumes; -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.apache.guacamole.GuacamoleException; -import org.apache.guacamole.environment.Environment; -import org.apache.guacamole.environment.LocalEnvironment; -import org.apache.guacamole.form.Form; -import org.apache.guacamole.net.auth.UserContext; -import org.apache.guacamole.GuacamoleSession; -import org.apache.guacamole.rest.ObjectRetrievalService; -import org.apache.guacamole.rest.auth.AuthenticationService; -import org.apache.guacamole.protocols.ProtocolInfo; - -/** - * A REST service which provides access to descriptions of the properties, - * attributes, etc. of objects used within the Guacamole REST API. - * - * @author Michael Jumper - */ -@Path("/schema/{dataSource}") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class SchemaRESTService { - - /** - * A service for authenticating users from auth tokens. - */ - @Inject - private AuthenticationService authenticationService; - - /** - * Service for convenient retrieval of objects. - */ - @Inject - private ObjectRetrievalService retrievalService; - - /** - * Retrieves the possible attributes of a user object. - * - * @param authToken - * The authentication token that is used to authenticate the user - * performing the operation. - * - * @param authProviderIdentifier - * The unique identifier of the AuthenticationProvider associated with - * the UserContext dictating the available user attributes. - * - * @return - * A collection of forms which describe the possible attributes of a - * user object. - * - * @throws GuacamoleException - * If an error occurs while retrieving the possible attributes. - */ - @GET - @Path("/users/attributes") - public Collection
getUserAttributes(@QueryParam("token") String authToken, - @PathParam("dataSource") String authProviderIdentifier) - throws GuacamoleException { - - // Retrieve all possible user attributes - GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); - UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier); - return userContext.getUserAttributes(); - - } - - /** - * Retrieves the possible attributes of a connection object. - * - * @param authToken - * The authentication token that is used to authenticate the user - * performing the operation. - * - * @param authProviderIdentifier - * The unique identifier of the AuthenticationProvider associated with - * the UserContext dictating the available connection attributes. - * - * @return - * A collection of forms which describe the possible attributes of a - * connection object. - * - * @throws GuacamoleException - * If an error occurs while retrieving the possible attributes. - */ - @GET - @Path("/connections/attributes") - public Collection getConnectionAttributes(@QueryParam("token") String authToken, - @PathParam("dataSource") String authProviderIdentifier) - throws GuacamoleException { - - // Retrieve all possible connection attributes - GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); - UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier); - return userContext.getConnectionAttributes(); - - } - - /** - * Retrieves the possible attributes of a connection group object. - * - * @param authToken - * The authentication token that is used to authenticate the user - * performing the operation. - * - * @param authProviderIdentifier - * The unique identifier of the AuthenticationProvider associated with - * the UserContext dictating the available connection group - * attributes. - * - * @return - * A collection of forms which describe the possible attributes of a - * connection group object. - * - * @throws GuacamoleException - * If an error occurs while retrieving the possible attributes. - */ - @GET - @Path("/connectionGroups/attributes") - public Collection getConnectionGroupAttributes(@QueryParam("token") String authToken, - @PathParam("dataSource") String authProviderIdentifier) - throws GuacamoleException { - - // Retrieve all possible connection group attributes - GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); - UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier); - return userContext.getConnectionGroupAttributes(); - - } - - /** - * Gets a map of protocols defined in the system - protocol name to protocol. - * - * @param authToken - * The authentication token that is used to authenticate the user - * 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 - * A map of protocol information, where each key is the unique name - * associated with that protocol. - * - * @throws GuacamoleException - * If an error occurs while retrieving the available protocols. - */ - @GET - @Path("/protocols") - public Map getProtocols(@QueryParam("token") String authToken, - @PathParam("dataSource") String authProviderIdentifier) - throws GuacamoleException { - - // Verify the given auth token and auth provider identifier are valid - GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); - retrievalService.retrieveUserContext(session, authProviderIdentifier); - - // Get and return a map of all protocols. - Environment env = new LocalEnvironment(); - return env.getProtocols(); - - } - -} diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/schema/SchemaResource.java b/guacamole/src/main/java/org/apache/guacamole/rest/schema/SchemaResource.java new file mode 100644 index 000000000..f0fcc8694 --- /dev/null +++ b/guacamole/src/main/java/org/apache/guacamole/rest/schema/SchemaResource.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole.rest.schema; + +import java.util.Collection; +import java.util.Map; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +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.environment.Environment; +import org.apache.guacamole.environment.LocalEnvironment; +import org.apache.guacamole.form.Form; +import org.apache.guacamole.net.auth.UserContext; +import org.apache.guacamole.protocols.ProtocolInfo; + +/** + * A REST resource which provides access to descriptions of the properties, + * attributes, etc. of objects within a particular UserContext. + * + * @author Michael Jumper + */ +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class SchemaResource { + + /** + * The UserContext whose schema is exposed by this SchemaResource. + */ + private final UserContext userContext; + + /** + * Creates a new SchemaResource which exposes meta information describing + * the kind of data within the given UserContext. + * + * @param userContext + * The UserContext whose schema should be exposed by this + * SchemaResource. + */ + public SchemaResource(UserContext userContext) { + this.userContext = userContext; + } + + /** + * Retrieves the possible attributes of a user object. + * + * @return + * A collection of forms which describe the possible attributes of a + * user object. + * + * @throws GuacamoleException + * If an error occurs while retrieving the possible attributes. + */ + @GET + @Path("userAttributes") + public Collection getUserAttributes() throws GuacamoleException { + + // Retrieve all possible user attributes + return userContext.getUserAttributes(); + + } + + /** + * Retrieves the possible attributes of a connection object. + * + * @return + * A collection of forms which describe the possible attributes of a + * connection object. + * + * @throws GuacamoleException + * If an error occurs while retrieving the possible attributes. + */ + @GET + @Path("connectionAttributes") + public Collection getConnectionAttributes() + throws GuacamoleException { + + // Retrieve all possible connection attributes + return userContext.getConnectionAttributes(); + + } + + /** + * Retrieves the possible attributes of a connection group object. + * + * @return + * A collection of forms which describe the possible attributes of a + * connection group object. + * + * @throws GuacamoleException + * If an error occurs while retrieving the possible attributes. + */ + @GET + @Path("connectionGroupAttributes") + public Collection getConnectionGroupAttributes() + throws GuacamoleException { + + // Retrieve all possible connection group attributes + return userContext.getConnectionGroupAttributes(); + + } + + /** + * Gets a map of protocols defined in the system - protocol name to protocol. + * + * @return + * A map of protocol information, where each key is the unique name + * associated with that protocol. + * + * @throws GuacamoleException + * If an error occurs while retrieving the available protocols. + */ + @GET + @Path("protocols") + public Map getProtocols() throws GuacamoleException { + + // Get and return a map of all protocols. + Environment env = new LocalEnvironment(); + return env.getProtocols(); + + } + +} 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 81344c647..e0c88555e 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 @@ -38,6 +38,7 @@ import org.apache.guacamole.rest.activeconnection.APIActiveConnection; import org.apache.guacamole.rest.connection.APIConnection; import org.apache.guacamole.rest.connectiongroup.APIConnectionGroup; import org.apache.guacamole.rest.history.HistoryResource; +import org.apache.guacamole.rest.schema.SchemaResource; import org.apache.guacamole.rest.user.APIUser; /** @@ -183,4 +184,19 @@ public class UserContextResource { return new HistoryResource(userContext); } + /** + * Returns a new resource which represents meta information describing the + * kind of data which within the UserContext exposed by this + * UserContextResource. + * + * @return + * A new resource which represents the meta information describing the + * kind of data within the UserContext exposed by this + * UserContextResource. + */ + @Path("schema") + public SchemaResource getSchemaResource() { + return new SchemaResource(userContext); + } + } diff --git a/guacamole/src/main/webapp/app/rest/services/schemaService.js b/guacamole/src/main/webapp/app/rest/services/schemaService.js index 39d89e10a..2c874ed28 100644 --- a/guacamole/src/main/webapp/app/rest/services/schemaService.js +++ b/guacamole/src/main/webapp/app/rest/services/schemaService.js @@ -58,7 +58,7 @@ angular.module('rest').factory('schemaService', ['$injector', return $http({ cache : cacheService.schema, method : 'GET', - url : 'api/schema/' + encodeURIComponent(dataSource) + '/users/attributes', + url : 'api/data/' + encodeURIComponent(dataSource) + '/schema/userAttributes', params : httpParameters }); @@ -92,7 +92,7 @@ angular.module('rest').factory('schemaService', ['$injector', return $http({ cache : cacheService.schema, method : 'GET', - url : 'api/schema/' + encodeURIComponent(dataSource) + '/connections/attributes', + url : 'api/data/' + encodeURIComponent(dataSource) + '/schema/connectionAttributes', params : httpParameters }); @@ -126,7 +126,7 @@ angular.module('rest').factory('schemaService', ['$injector', return $http({ cache : cacheService.schema, method : 'GET', - url : 'api/schema/' + encodeURIComponent(dataSource) + '/connectionGroups/attributes', + url : 'api/data/' + encodeURIComponent(dataSource) + '/schema/connectionGroupAttributes', params : httpParameters }); @@ -157,7 +157,7 @@ angular.module('rest').factory('schemaService', ['$injector', return $http({ cache : cacheService.schema, method : 'GET', - url : 'api/schema/' + encodeURIComponent(dataSource) + '/protocols', + url : 'api/data/' + encodeURIComponent(dataSource) + '/schema/protocols', params : httpParameters });