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:58 UTC
[20/24] incubator-guacamole-client git commit: GUACAMOLE-5: Refactor
away ObjectRetrievalService.
GUACAMOLE-5: Refactor away ObjectRetrievalService.
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/e4ed85cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/e4ed85cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/e4ed85cf
Branch: refs/heads/master
Commit: e4ed85cfcbeebef47f68a161b52564da5a3c287f
Parents: b189f5f
Author: Michael Jumper <mj...@apache.org>
Authored: Tue Jul 12 21:38:07 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Tue Jul 12 21:38:07 2016 -0700
----------------------------------------------------------------------
.../org/apache/guacamole/GuacamoleSession.java | 39 ++++++++++
.../guacamole/rest/ObjectRetrievalService.java | 77 --------------------
.../guacamole/rest/RESTServiceModule.java | 3 -
.../guacamole/rest/session/SessionResource.java | 9 +--
.../guacamole/tunnel/TunnelRequestService.java | 9 +--
5 files changed, 41 insertions(+), 96 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e4ed85cf/guacamole/src/main/java/org/apache/guacamole/GuacamoleSession.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/GuacamoleSession.java b/guacamole/src/main/java/org/apache/guacamole/GuacamoleSession.java
index 06530c2..41832cb 100644
--- a/guacamole/src/main/java/org/apache/guacamole/GuacamoleSession.java
+++ b/guacamole/src/main/java/org/apache/guacamole/GuacamoleSession.java
@@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.guacamole.environment.Environment;
import org.apache.guacamole.net.GuacamoleTunnel;
import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.apache.guacamole.net.auth.UserContext;
import org.apache.guacamole.tunnel.StreamInterceptingTunnel;
import org.slf4j.Logger;
@@ -127,6 +128,44 @@ public class GuacamoleSession {
}
/**
+ * Returns the UserContext associated with this session that originated
+ * from the AuthenticationProvider with the given identifier. If no such
+ * UserContext exists, an exception is thrown.
+ *
+ * @param authProviderIdentifier
+ * The unique identifier of the AuthenticationProvider that created the
+ * UserContext being retrieved.
+ *
+ * @return
+ * The UserContext that was created by the AuthenticationProvider
+ * having the given identifier.
+ *
+ * @throws GuacamoleException
+ * If no such UserContext exists.
+ */
+ public UserContext getUserContext(String authProviderIdentifier)
+ throws GuacamoleException {
+
+ // Locate and return the UserContext associated with the
+ // AuthenticationProvider having the given identifier, if any
+ for (UserContext userContext : getUserContexts()) {
+
+ // Get AuthenticationProvider associated with current UserContext
+ AuthenticationProvider authProvider = userContext.getAuthenticationProvider();
+
+ // If AuthenticationProvider identifier matches, done
+ if (authProvider.getIdentifier().equals(authProviderIdentifier))
+ return userContext;
+
+ }
+
+ throw new GuacamoleResourceNotFoundException("Session not associated "
+ + "with authentication provider \"" + authProviderIdentifier + "\".");
+
+
+ }
+
+ /**
* Replaces all UserContexts associated with this session with the given
* List of UserContexts.
*
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e4ed85cf/guacamole/src/main/java/org/apache/guacamole/rest/ObjectRetrievalService.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/ObjectRetrievalService.java b/guacamole/src/main/java/org/apache/guacamole/rest/ObjectRetrievalService.java
deleted file mode 100644
index edcb2fa..0000000
--- a/guacamole/src/main/java/org/apache/guacamole/rest/ObjectRetrievalService.java
+++ /dev/null
@@ -1,77 +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;
-
-import java.util.List;
-import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.GuacamoleResourceNotFoundException;
-import org.apache.guacamole.net.auth.AuthenticationProvider;
-import org.apache.guacamole.net.auth.UserContext;
-import org.apache.guacamole.GuacamoleSession;
-
-/**
- * Provides easy access and automatic error handling for retrieval of objects.
- */
-public class ObjectRetrievalService {
-
- /**
- * Retrieves a single UserContext from the given GuacamoleSession, which
- * may contain multiple UserContexts.
- *
- * @param session
- * The GuacamoleSession to retrieve the UserContext from.
- *
- * @param authProviderIdentifier
- * The unique identifier of the AuthenticationProvider that created the
- * UserContext being retrieved. Only one UserContext per User per
- * AuthenticationProvider can exist.
- *
- * @return
- * The UserContext that was created by the AuthenticationProvider
- * having the given identifier.
- *
- * @throws GuacamoleException
- * If an error occurs while retrieving the UserContext, or if the
- * UserContext does not exist.
- */
- public UserContext retrieveUserContext(GuacamoleSession session,
- String authProviderIdentifier) throws GuacamoleException {
-
- // Get list of UserContexts
- List<UserContext> userContexts = session.getUserContexts();
-
- // Locate and return the UserContext associated with the
- // AuthenticationProvider having the given identifier, if any
- for (UserContext userContext : userContexts) {
-
- // Get AuthenticationProvider associated with current UserContext
- AuthenticationProvider authProvider = userContext.getAuthenticationProvider();
-
- // If AuthenticationProvider identifier matches, done
- if (authProvider.getIdentifier().equals(authProviderIdentifier))
- return userContext;
-
- }
-
- throw new GuacamoleResourceNotFoundException("Session not associated with authentication provider \"" + authProviderIdentifier + "\".");
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e4ed85cf/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 c386e10..2978278 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
@@ -82,9 +82,6 @@ public class RESTServiceModule extends ServletModule {
requestInjection(interceptor);
bindInterceptor(Matchers.any(), new RESTMethodMatcher(), interceptor);
- // Bind convenience services used by the REST API
- bind(ObjectRetrievalService.class);
-
// Set up the API endpoints
bind(LanguageRESTService.class);
bind(PatchRESTService.class);
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e4ed85cf/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
index 211e5d5..7c7f14f 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
@@ -30,7 +30,6 @@ 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.tunnel.TunnelCollectionResource;
/**
@@ -49,12 +48,6 @@ public class SessionResource {
private final GuacamoleSession session;
/**
- * Service for convenient retrieval of objects.
- */
- @Inject
- private ObjectRetrievalService retrievalService;
-
- /**
* Factory for creating UserContextResources which expose a given
* UserContext.
*/
@@ -95,7 +88,7 @@ public class SessionResource {
throws GuacamoleException {
// Pull UserContext defined by the given auth provider identifier
- UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
+ UserContext userContext = session.getUserContext(authProviderIdentifier);
// Return a resource exposing the retrieved UserContext
return userContextResourceFactory.create(userContext);
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e4ed85cf/guacamole/src/main/java/org/apache/guacamole/tunnel/TunnelRequestService.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/tunnel/TunnelRequestService.java b/guacamole/src/main/java/org/apache/guacamole/tunnel/TunnelRequestService.java
index 8040472..95e4bb9 100644
--- a/guacamole/src/main/java/org/apache/guacamole/tunnel/TunnelRequestService.java
+++ b/guacamole/src/main/java/org/apache/guacamole/tunnel/TunnelRequestService.java
@@ -31,7 +31,6 @@ import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.UserContext;
-import org.apache.guacamole.rest.ObjectRetrievalService;
import org.apache.guacamole.rest.auth.AuthenticationService;
import org.apache.guacamole.protocol.GuacamoleClientInformation;
import org.slf4j.Logger;
@@ -62,12 +61,6 @@ public class TunnelRequestService {
private AuthenticationService authenticationService;
/**
- * Service for convenient retrieval of objects.
- */
- @Inject
- private ObjectRetrievalService retrievalService;
-
- /**
* Reads and returns the client information provided within the given
* request.
*
@@ -327,7 +320,7 @@ public class TunnelRequestService {
GuacamoleClientInformation info = getClientInformation(request);
GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
- UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
+ UserContext userContext = session.getUserContext(authProviderIdentifier);
try {