You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by jm...@apache.org on 2016/07/13 05:09:40 UTC

[02/24] incubator-guacamole-client git commit: GUACAMOLE-5: Add root-level resources exposing UserContexts.

GUACAMOLE-5: Add root-level resources exposing UserContexts.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/e579eae9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/e579eae9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/e579eae9

Branch: refs/heads/master
Commit: e579eae95cd93bf1defb8f64d8990a2d31e5331f
Parents: d3a9cec
Author: Michael Jumper <mj...@apache.org>
Authored: Tue Jul 12 00:15:18 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Tue Jul 12 00:15:18 2016 -0700

----------------------------------------------------------------------
 .../guacamole/rest/RESTServiceModule.java       |   7 ++
 .../guacamole/rest/session/SessionResource.java | 100 +++++++++++++++++++
 .../rest/session/UserContextResource.java       |  56 +++++++++++
 .../session/UserContextResourceFactory.java     |  45 +++++++++
 .../guacamole/rest/session/package-info.java    |  24 +++++
 5 files changed, 232 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e579eae9/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
----------------------------------------------------------------------
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 ec555e3..bc8d7b6 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
@@ -19,7 +19,10 @@
 
 package org.apache.guacamole.rest;
 
+import org.apache.guacamole.rest.session.UserContextResourceFactory;
+import org.apache.guacamole.rest.session.SessionResource;
 import com.google.inject.Scopes;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
 import com.google.inject.matcher.Matchers;
 import com.google.inject.servlet.ServletModule;
 import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
@@ -96,6 +99,10 @@ public class RESTServiceModule extends ServletModule {
         bind(TunnelRESTService.class);
         bind(UserRESTService.class);
 
+        // Root-level resources
+        bind(SessionResource.class);
+        install(new FactoryModuleBuilder().build(UserContextResourceFactory.class));
+
         // Set up the servlet and JSON mappings
         bind(GuiceContainer.class);
         bind(JacksonJsonProvider.class).in(Scopes.SINGLETON);

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e579eae9/guacamole/src/main/java/org/apache/guacamole/rest/session/SessionResource.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..7c98a65
--- /dev/null
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/session/SessionResource.java
@@ -0,0 +1,100 @@
+/*
+ * 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.session;
+
+import com.google.inject.Inject;
+import javax.ws.rs.Consumes;
+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.GuacamoleSession;
+import org.apache.guacamole.net.auth.UserContext;
+import org.apache.guacamole.rest.ObjectRetrievalService;
+import org.apache.guacamole.rest.auth.AuthenticationService;
+
+/**
+ * A REST resource which exposes all UserContexts within a Guacamole user's
+ * session.
+ *
+ * @author mjumper
+ */
+@Path("/data")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class SessionResource {
+
+    /**
+     * A service for authenticating users from auth tokens.
+     */
+    @Inject
+    private AuthenticationService authenticationService;
+
+    /**
+     * Service for convenient retrieval of objects.
+     */
+    @Inject
+    private ObjectRetrievalService retrievalService;
+
+    /**
+     * Factory for creating UserContextResources which expose a given
+     * UserContext.
+     */
+    @Inject
+    private UserContextResourceFactory userContextResourceFactory;
+
+    /**
+     * Retrieves a resource representing the UserContext associated with the
+     * AuthenticationProvider having the given identifier.
+     *
+     * @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 being retrieved.
+     *
+     * @return
+     *     A resource representing the UserContext associated with the
+     *     AuthenticationProvider having the given identifier.
+     *
+     * @throws GuacamoleException
+     *     If the authentication token or AuthenticationProvider identifier are
+     *     invalid.
+     */
+    @Path("{dataSource}")
+    public UserContextResource getUserContextResource(
+            @QueryParam("token") String authToken,
+            @PathParam("dataSource") String authProviderIdentifier)
+            throws GuacamoleException {
+
+        // Pull UserContext defined by the given auth provider identifier
+        GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
+        UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
+
+        // Return a resource exposing the retrieved UserContext
+        return userContextResourceFactory.create(userContext);
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e579eae9/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..e5dcc0c
--- /dev/null
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java
@@ -0,0 +1,56 @@
+/*
+ * 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.session;
+
+import com.google.inject.assistedinject.Assisted;
+import com.google.inject.assistedinject.AssistedInject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.apache.guacamole.net.auth.UserContext;
+
+/**
+ * A REST resource which exposes the contents of a particular UserContext.
+ *
+ * @author Michael Jumper
+ */
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class UserContextResource {
+
+    /**
+     * The UserContext being exposed through this resource.
+     */
+    private final UserContext userContext;
+
+    /**
+     * Creates a new UserContextResource which exposes the data within the
+     * given UserContext.
+     *
+     * @param userContext
+     *     The UserContext which should be exposed through this
+     *     UserContextResource.
+     */
+    @AssistedInject
+    public UserContextResource(@Assisted UserContext userContext) {
+        this.userContext = userContext;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e579eae9/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResourceFactory.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResourceFactory.java b/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResourceFactory.java
new file mode 100644
index 0000000..04e60ea
--- /dev/null
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResourceFactory.java
@@ -0,0 +1,45 @@
+/*
+ * 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.session;
+
+import org.apache.guacamole.net.auth.UserContext;
+
+/**
+ * Factory which creates resources that expose the contents of a given
+ * UserContext.
+ *
+ * @author Michael Jumper
+ */
+public interface UserContextResourceFactory {
+
+    /**
+     * Creates a new UserContextResource which exposes the contents of the
+     * given UserContext.
+     *
+     * @param userContext
+     *     The UserContext whose contents should be exposed.
+     *
+     * @return
+     *     A new UserContextResource which exposes the contents of the given
+     *     UserContext.
+     */
+    UserContextResource create(UserContext userContext);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e579eae9/guacamole/src/main/java/org/apache/guacamole/rest/session/package-info.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/session/package-info.java b/guacamole/src/main/java/org/apache/guacamole/rest/session/package-info.java
new file mode 100644
index 0000000..118ee2e
--- /dev/null
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/session/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+/**
+ * Classes which expose the absolute root of the data available to a Guacamole
+ * user's session.
+ */
+package org.apache.guacamole.rest.session;