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/30 02:08:23 UTC

[1/4] incubator-guacamole-client git commit: GUACAMOLE-5: Use singleton Guice Injector via common base class.

Repository: incubator-guacamole-client
Updated Branches:
  refs/heads/master b1a8a4d85 -> 872aac375


GUACAMOLE-5: Use singleton Guice Injector via common base class.


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/60000253
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/60000253
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/60000253

Branch: refs/heads/master
Commit: 600002531e3f7b166fd02f8c5c88056204d5ab17
Parents: b1a8a4d
Author: Michael Jumper <mj...@apache.org>
Authored: Thu Jul 28 11:20:19 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Fri Jul 29 18:46:57 2016 -0700

----------------------------------------------------------------------
 .../auth/jdbc/JDBCAuthenticationProvider.java   | 101 +++++++++++++++++++
 .../auth/jdbc/JDBCInjectorProvider.java         |  90 +++++++++++++++++
 .../auth/mysql/MySQLAuthenticationProvider.java |  78 +-------------
 .../auth/mysql/MySQLInjectorProvider.java       |  51 ++++++++++
 .../PostgreSQLAuthenticationProvider.java       |  85 +---------------
 .../postgresql/PostgreSQLInjectorProvider.java  |  51 ++++++++++
 6 files changed, 301 insertions(+), 155 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/60000253/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProvider.java
new file mode 100644
index 0000000..ebacd13
--- /dev/null
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProvider.java
@@ -0,0 +1,101 @@
+/*
+ * 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.auth.jdbc;
+
+import com.google.inject.Injector;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.UserContext;
+import org.apache.guacamole.auth.jdbc.user.AuthenticationProviderService;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+
+/**
+ * Provides a base implementation of an AuthenticationProvider which is backed
+ * by an arbitrary underlying database. It is up to the subclass implementation
+ * to configure the underlying database appropriately via Guice.
+ *
+ * @author James Muehlner
+ * @author Michael Jumper
+ */
+public abstract class JDBCAuthenticationProvider implements AuthenticationProvider {
+
+    /**
+     * Provider of the singleton Injector instance which will manage the object
+     * graph of this authentication provider.
+     */
+    private final JDBCInjectorProvider injectorProvider;
+
+    /**
+     * Creates a new AuthenticationProvider that is backed by an arbitrary
+     * underlying database.
+     *
+     * @param injectorProvider
+     *     A JDBCInjectorProvider instance which provides singleton instances
+     *     of a Guice Injector, pre-configured to set up all injections and
+     *     access to the underlying database via MyBatis.
+     */
+    public JDBCAuthenticationProvider(JDBCInjectorProvider injectorProvider) {
+        this.injectorProvider = injectorProvider;
+    }
+
+    @Override
+    public AuthenticatedUser authenticateUser(Credentials credentials)
+            throws GuacamoleException {
+
+        Injector injector = injectorProvider.get();
+
+        // Create AuthenticatedUser based on credentials, if valid
+        AuthenticationProviderService authProviderService = injector.getInstance(AuthenticationProviderService.class);
+        return authProviderService.authenticateUser(this, credentials);
+
+    }
+
+    @Override
+    public AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
+
+        // No need to update authenticated users
+        return authenticatedUser;
+
+    }
+
+    @Override
+    public UserContext getUserContext(AuthenticatedUser authenticatedUser)
+            throws GuacamoleException {
+
+        Injector injector = injectorProvider.get();
+
+        // Create UserContext based on credentials, if valid
+        AuthenticationProviderService authProviderService = injector.getInstance(AuthenticationProviderService.class);
+        return authProviderService.getUserContext(authenticatedUser);
+
+    }
+
+    @Override
+    public UserContext updateUserContext(UserContext context,
+            AuthenticatedUser authenticatedUser) throws GuacamoleException {
+
+        // No need to update the context
+        return context;
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/60000253/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCInjectorProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCInjectorProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCInjectorProvider.java
new file mode 100644
index 0000000..839616e
--- /dev/null
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCInjectorProvider.java
@@ -0,0 +1,90 @@
+/*
+ * 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.auth.jdbc;
+
+import com.google.inject.Injector;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.guacamole.GuacamoleException;
+
+/**
+ * A caching provider of singleton Guice Injector instances. The first call to
+ * get() will return a new instance of the Guice Injector, while all subsequent
+ * calls will return that same instance. It is up to implementations of this
+ * class to define how the Guice Injector will be created through defining the
+ * create() function.
+ *
+ * IMPORTANT: Because the Injector returned by get() is cached statically, only
+ * ONE implementation of this class may be used within any individual
+ * classloader. Within the context of the JDBC extension, as long as each built
+ * extension only provides one subclass of this class, things should work
+ * properly, as each extension is given its own classloader by Guacamole.
+ *
+ * @author Michael Jumper
+ */
+public abstract class JDBCInjectorProvider {
+
+    /**
+     * An AtomicReference wrapping the cached Guice Injector. If the Injector
+     * has not yet been created, null will be wrapped instead.
+     */
+    private static final AtomicReference<Injector> injector = new AtomicReference<Injector>(null);
+
+    /**
+     * Creates a new instance of the Guice Injector which should be used
+     * across the entire JDBC authentication extension. This function will
+     * generally only be called once, but multiple invocations are possible if
+     * get() is invoked several times concurrently prior to the Injector being
+     * cached.
+     *
+     * @return
+     * @throws GuacamoleException
+     */
+    protected abstract Injector create() throws GuacamoleException;
+
+    /**
+     * Returns a common, singleton instance of a Guice Injector, configured for
+     * the injections required by the JDBC authentication extension. The result
+     * of the first call to this function will be cached statically within this
+     * class, and will be returned for all subsequent calls.
+     *
+     * @return
+     *     A singleton instance of the Guice Injector used across the entire
+     *     JDBC authentication extension.
+     *
+     * @throws GuacamoleException
+     *     If the Injector cannot be created due to an error.
+     */
+    public Injector get() throws GuacamoleException {
+
+        // Return existing Injector if already created
+        Injector value = injector.get();
+        if (value != null)
+            return value;
+
+        // Explicitly create and store new Injector only if necessary
+        injector.compareAndSet(null, create());
+
+        // Consistently return the same Injector, even if two create operations
+        // happen concurrently
+        return injector.get();
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/60000253/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProvider.java
index 8db48b7..e752163 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProvider.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProvider.java
@@ -19,15 +19,7 @@
 
 package org.apache.guacamole.auth.mysql;
 
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.net.auth.AuthenticationProvider;
-import org.apache.guacamole.net.auth.Credentials;
-import org.apache.guacamole.net.auth.UserContext;
-import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProviderModule;
-import org.apache.guacamole.auth.jdbc.user.AuthenticationProviderService;
-import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProvider;
 
 /**
  * Provides a MySQL based implementation of the AuthenticationProvider
@@ -36,39 +28,15 @@ import org.apache.guacamole.net.auth.AuthenticatedUser;
  * @author James Muehlner
  * @author Michael Jumper
  */
-public class MySQLAuthenticationProvider implements AuthenticationProvider {
-
-    /**
-     * Injector which will manage the object graph of this authentication
-     * provider.
-     */
-    private final Injector injector;
+public class MySQLAuthenticationProvider extends JDBCAuthenticationProvider {
 
     /**
      * Creates a new MySQLAuthenticationProvider that reads and writes
      * authentication data to a MySQL database defined by properties in
      * guacamole.properties.
-     *
-     * @throws GuacamoleException
-     *     If a required property is missing, or an error occurs while parsing
-     *     a property.
      */
-    public MySQLAuthenticationProvider() throws GuacamoleException {
-
-        // Get local environment
-        MySQLEnvironment environment = new MySQLEnvironment();
-
-        // Set up Guice injector.
-        injector = Guice.createInjector(
-
-            // Configure MySQL-specific authentication
-            new MySQLAuthenticationProviderModule(environment),
-
-            // Configure JDBC authentication core
-            new JDBCAuthenticationProviderModule(environment)
-
-        );
-
+    public MySQLAuthenticationProvider() {
+        super(new MySQLInjectorProvider());
     }
 
     @Override
@@ -76,42 +44,4 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
         return "mysql";
     }
 
-    @Override
-    public AuthenticatedUser authenticateUser(Credentials credentials)
-            throws GuacamoleException {
-
-        // Create AuthenticatedUser based on credentials, if valid
-        AuthenticationProviderService authProviderService = injector.getInstance(AuthenticationProviderService.class);
-        return authProviderService.authenticateUser(this, credentials);
-
-    }
-
-    @Override
-    public AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser authenticatedUser,
-            Credentials credentials) throws GuacamoleException {
-
-        // No need to update authenticated users
-        return authenticatedUser;
-
-    }
-
-    @Override
-    public UserContext getUserContext(AuthenticatedUser authenticatedUser)
-            throws GuacamoleException {
-
-        // Create UserContext based on credentials, if valid
-        AuthenticationProviderService authProviderService = injector.getInstance(AuthenticationProviderService.class);
-        return authProviderService.getUserContext(authenticatedUser);
-
-    }
-
-    @Override
-    public UserContext updateUserContext(UserContext context,
-            AuthenticatedUser authenticatedUser) throws GuacamoleException {
-
-        // No need to update the context
-        return context;
-
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/60000253/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLInjectorProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLInjectorProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLInjectorProvider.java
new file mode 100644
index 0000000..09c40be
--- /dev/null
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLInjectorProvider.java
@@ -0,0 +1,51 @@
+/*
+ * 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.auth.mysql;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProviderModule;
+import org.apache.guacamole.auth.jdbc.JDBCInjectorProvider;
+
+/**
+ * JDBCInjectorProvider implementation which configures Guice injections for
+ * connecting to a MySQL database based on MySQL-specific options provided via
+ * guacamole.properties.
+ *
+ * @author Michael Jumper
+ */
+public class MySQLInjectorProvider extends JDBCInjectorProvider {
+
+    @Override
+    protected Injector create() throws GuacamoleException {
+
+        // Get local environment
+        MySQLEnvironment environment = new MySQLEnvironment();
+
+        // Set up Guice injector
+        return Guice.createInjector(
+            new JDBCAuthenticationProviderModule(environment),
+            new MySQLAuthenticationProviderModule(environment)
+        );
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/60000253/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProvider.java
index cd37d05..1c4b816 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProvider.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProvider.java
@@ -19,17 +19,7 @@
 
 package org.apache.guacamole.auth.postgresql;
 
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.net.auth.AuthenticationProvider;
-import org.apache.guacamole.net.auth.Credentials;
-import org.apache.guacamole.net.auth.UserContext;
-import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProviderModule;
-import org.apache.guacamole.auth.jdbc.user.AuthenticationProviderService;
-import org.apache.guacamole.net.auth.AuthenticatedUser;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProvider;
 
 /**
  * Provides a PostgreSQL-based implementation of the AuthenticationProvider
@@ -38,44 +28,15 @@ import org.slf4j.LoggerFactory;
  * @author James Muehlner
  * @author Michael Jumper
  */
-public class PostgreSQLAuthenticationProvider implements AuthenticationProvider {
-
-    /**
-     * Logger for this class.
-     */
-    private static final Logger logger = LoggerFactory.getLogger(PostgreSQLAuthenticationProvider.class);
-
-    /**
-     * Injector which will manage the object graph of this authentication
-     * provider.
-     */
-    private final Injector injector;
+public class PostgreSQLAuthenticationProvider extends JDBCAuthenticationProvider {
 
     /**
      * Creates a new PostgreSQLAuthenticationProvider that reads and writes
      * authentication data to a PostgreSQL database defined by properties in
      * guacamole.properties.
-     *
-     * @throws GuacamoleException
-     *     If a required property is missing, or an error occurs while parsing
-     *     a property.
      */
-    public PostgreSQLAuthenticationProvider() throws GuacamoleException {
-
-        // Get local environment
-        PostgreSQLEnvironment environment = new PostgreSQLEnvironment();
-
-        // Set up Guice injector.
-        injector = Guice.createInjector(
-
-            // Configure PostgreSQL-specific authentication
-            new PostgreSQLAuthenticationProviderModule(environment),
-
-            // Configure JDBC authentication core
-            new JDBCAuthenticationProviderModule(environment)
-
-        );
-
+    public PostgreSQLAuthenticationProvider() {
+        super(new PostgreSQLInjectorProvider());
     }
 
     @Override
@@ -83,42 +44,4 @@ public class PostgreSQLAuthenticationProvider implements AuthenticationProvider
         return "postgresql";
     }
 
-    @Override
-    public AuthenticatedUser authenticateUser(Credentials credentials)
-            throws GuacamoleException {
-
-        // Create AuthenticatedUser based on credentials, if valid
-        AuthenticationProviderService authProviderService = injector.getInstance(AuthenticationProviderService.class);
-        return authProviderService.authenticateUser(this, credentials);
-
-    }
-
-    @Override
-    public AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser authenticatedUser,
-            Credentials credentials) throws GuacamoleException {
-
-        // No need to update authenticated users
-        return authenticatedUser;
-
-    }
-
-    @Override
-    public UserContext getUserContext(AuthenticatedUser authenticatedUser)
-            throws GuacamoleException {
-
-        // Create UserContext based on credentials, if valid
-        AuthenticationProviderService authProviderService = injector.getInstance(AuthenticationProviderService.class);
-        return authProviderService.getUserContext(authenticatedUser);
-
-    }
-
-    @Override
-    public UserContext updateUserContext(UserContext context,
-            AuthenticatedUser authenticatedUser) throws GuacamoleException {
-
-        // No need to update the context
-        return context;
-
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/60000253/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLInjectorProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLInjectorProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLInjectorProvider.java
new file mode 100644
index 0000000..ff34399
--- /dev/null
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLInjectorProvider.java
@@ -0,0 +1,51 @@
+/*
+ * 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.auth.postgresql;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProviderModule;
+import org.apache.guacamole.auth.jdbc.JDBCInjectorProvider;
+
+/**
+ * JDBCInjectorProvider implementation which configures Guice injections for
+ * connecting to a PostgreSQL database based on PostgreSQL-specific options
+ * provided via guacamole.properties.
+ *
+ * @author Michael Jumper
+ */
+public class PostgreSQLInjectorProvider extends JDBCInjectorProvider {
+
+    @Override
+    protected Injector create() throws GuacamoleException {
+
+        // Get local environment
+        PostgreSQLEnvironment environment = new PostgreSQLEnvironment();
+
+        // Set up Guice injector
+        return Guice.createInjector(
+            new JDBCAuthenticationProviderModule(environment),
+            new PostgreSQLAuthenticationProviderModule(environment)
+        );
+
+    }
+
+}


[3/4] incubator-guacamole-client git commit: GUACAMOLE-5: Handle shared connections via dedicated AuthenticationProvider.

Posted by jm...@apache.org.
GUACAMOLE-5: Handle shared connections via dedicated AuthenticationProvider.


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/06a7ca1b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/06a7ca1b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/06a7ca1b

Branch: refs/heads/master
Commit: 06a7ca1b7a70d699d9e7a2fa57f8bcef760a3177
Parents: 4e3212f
Author: Michael Jumper <mj...@apache.org>
Authored: Thu Jul 28 19:45:43 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Fri Jul 29 18:46:58 2016 -0700

----------------------------------------------------------------------
 .../SharedAuthenticationProviderService.java    | 84 ++++++++++++++++++++
 .../MySQLSharedAuthenticationProvider.java      | 52 ++++++++++++
 .../src/main/resources/guac-manifest.json       |  3 +-
 .../PostgreSQLSharedAuthenticationProvider.java | 52 ++++++++++++
 .../src/main/resources/guac-manifest.json       |  3 +-
 5 files changed, 192 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/06a7ca1b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/SharedAuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/SharedAuthenticationProviderService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/SharedAuthenticationProviderService.java
new file mode 100644
index 0000000..1ca667a
--- /dev/null
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/SharedAuthenticationProviderService.java
@@ -0,0 +1,84 @@
+/*
+ * 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.auth.jdbc.sharing;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.jdbc.AuthenticationProviderService;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
+import org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
+
+/**
+ * Service which authenticates users based on share keys and provides for the
+ * creation of corresponding. The created UserContext objects are restricted to
+ * the connections associated with those share keys via a common
+ * ConnectionSharingService.
+ *
+ * @author Michael Jumper
+ */
+public class SharedAuthenticationProviderService implements AuthenticationProviderService {
+
+    /**
+     * Provider for retrieving SharedConnectionUserContext instances.
+     */
+    @Inject
+    private Provider<SharedConnectionUserContext> sharedUserContextProvider;
+
+    /**
+     * Service for sharing active connections.
+     */
+    @Inject
+    private ConnectionSharingService sharingService;
+
+    @Override
+    public AuthenticatedUser authenticateUser(AuthenticationProvider authenticationProvider,
+            Credentials credentials) throws GuacamoleException {
+
+        // Check whether user is authenticating with a valid sharing key
+        AuthenticatedUser user = sharingService.retrieveSharedConnectionUser(authenticationProvider, credentials);
+        if (user != null)
+            return user;
+
+        // Otherwise, unauthorized
+        throw new GuacamoleInvalidCredentialsException("Invalid login", CredentialsInfo.USERNAME_PASSWORD);
+
+    }
+
+    @Override
+    public org.apache.guacamole.net.auth.UserContext getUserContext(
+            AuthenticatedUser authenticatedUser) throws GuacamoleException {
+
+        // Produce sharing-specific user context if this is the user of a shared connection
+        if (authenticatedUser instanceof SharedConnectionUser) {
+            SharedConnectionUserContext context = sharedUserContextProvider.get();
+            context.init((SharedConnectionUser) authenticatedUser);
+            return context;
+        }
+
+        // No shared connections otherwise
+        return null;
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/06a7ca1b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLSharedAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLSharedAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLSharedAuthenticationProvider.java
new file mode 100644
index 0000000..f9ae15e
--- /dev/null
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLSharedAuthenticationProvider.java
@@ -0,0 +1,52 @@
+/*
+ * 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.auth.mysql;
+
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.jdbc.InjectedAuthenticationProvider;
+import org.apache.guacamole.auth.jdbc.sharing.SharedAuthenticationProviderService;
+
+/**
+ * Provides a implementation of AuthenticationProvider which interacts with the
+ * MySQL AuthenticationProvider, accepting share keys as credentials and
+ * providing access to the shared connections.
+ *
+ * @author Michael Jumper
+ */
+public class MySQLSharedAuthenticationProvider extends InjectedAuthenticationProvider {
+
+    /**
+     * Creates a new MySQLSharedAuthenticationProvider that provides access to
+     * shared connections exposed by the MySQLAuthenticationProvider.
+     *
+     * @throws GuacamoleException
+     *     If a required property is missing, or an error occurs while parsing
+     *     a property.
+     */
+    public MySQLSharedAuthenticationProvider() throws GuacamoleException {
+        super(new MySQLInjectorProvider(), SharedAuthenticationProviderService.class);
+    }
+
+    @Override
+    public String getIdentifier() {
+        return "mysql-shared";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/06a7ca1b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/guac-manifest.json
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/guac-manifest.json b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/guac-manifest.json
index 1aa0b8c..7d92900 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/guac-manifest.json
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/guac-manifest.json
@@ -6,7 +6,8 @@
     "namespace" : "guac-mysql",
 
     "authProviders" : [
-        "org.apache.guacamole.auth.mysql.MySQLAuthenticationProvider"
+        "org.apache.guacamole.auth.mysql.MySQLAuthenticationProvider",
+        "org.apache.guacamole.auth.mysql.MySQLSharedAuthenticationProvider"
     ],
 
     "translations" : [

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/06a7ca1b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLSharedAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLSharedAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLSharedAuthenticationProvider.java
new file mode 100644
index 0000000..c2f78c3
--- /dev/null
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLSharedAuthenticationProvider.java
@@ -0,0 +1,52 @@
+/*
+ * 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.auth.postgresql;
+
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.jdbc.InjectedAuthenticationProvider;
+import org.apache.guacamole.auth.jdbc.sharing.SharedAuthenticationProviderService;
+
+/**
+ * Provides a implementation of AuthenticationProvider which interacts with the
+ * PostgreSQL AuthenticationProvider, accepting share keys as credentials and
+ * providing access to the shared connections.
+ *
+ * @author Michael Jumper
+ */
+public class PostgreSQLSharedAuthenticationProvider extends InjectedAuthenticationProvider {
+
+    /**
+     * Creates a new PostgreSQLSharedAuthenticationProvider that provides access
+     * to shared connections exposed by the PostgreSQLAuthenticationProvider.
+     *
+     * @throws GuacamoleException
+     *     If a required property is missing, or an error occurs while parsing
+     *     a property.
+     */
+    public PostgreSQLSharedAuthenticationProvider() throws GuacamoleException {
+        super(new PostgreSQLInjectorProvider(), SharedAuthenticationProviderService.class);
+    }
+
+    @Override
+    public String getIdentifier() {
+        return "postgresql-shared";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/06a7ca1b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/guac-manifest.json
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/guac-manifest.json b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/guac-manifest.json
index 64d6a23..1f259c4 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/guac-manifest.json
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/guac-manifest.json
@@ -6,7 +6,8 @@
     "namespace" : "guac-postgresql",
 
     "authProviders" : [
-        "org.apache.guacamole.auth.postgresql.PostgreSQLAuthenticationProvider"
+        "org.apache.guacamole.auth.postgresql.PostgreSQLAuthenticationProvider",
+        "org.apache.guacamole.auth.postgresql.PostgreSQLSharedAuthenticationProvider"
     ],
 
     "translations" : [


[2/4] incubator-guacamole-client git commit: GUACAMOLE-5: Use AuthenticationProviderService as the means of defining AuthenticationProvider behavior.

Posted by jm...@apache.org.
GUACAMOLE-5: Use AuthenticationProviderService as the means of defining AuthenticationProvider behavior.


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/4e3212f9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/4e3212f9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/4e3212f9

Branch: refs/heads/master
Commit: 4e3212f9fda500223f8b24f43f403d4bf540eb43
Parents: 6000025
Author: Michael Jumper <mj...@apache.org>
Authored: Thu Jul 28 17:16:03 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Fri Jul 29 18:46:58 2016 -0700

----------------------------------------------------------------------
 .../jdbc/AuthenticationProviderService.java     |  80 ++++++++++
 .../jdbc/InjectedAuthenticationProvider.java    | 105 +++++++++++++
 .../auth/jdbc/JDBCAuthenticationProvider.java   | 101 -------------
 .../jdbc/JDBCAuthenticationProviderService.java |  85 +++++++++++
 .../user/AuthenticationProviderService.java     | 146 -------------------
 .../auth/mysql/MySQLAuthenticationProvider.java |  14 +-
 .../PostgreSQLAuthenticationProvider.java       |  14 +-
 7 files changed, 290 insertions(+), 255 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4e3212f9/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/AuthenticationProviderService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/AuthenticationProviderService.java
new file mode 100644
index 0000000..a821bfa
--- /dev/null
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/AuthenticationProviderService.java
@@ -0,0 +1,80 @@
+/*
+ * 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.auth.jdbc;
+
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.UserContext;
+
+/**
+ * Service which authenticates users based on credentials and provides for
+ * the creation of corresponding, new UserContext objects for authenticated
+ * users.
+ *
+ * @author Michael Jumper
+ */
+public interface AuthenticationProviderService  {
+
+    /**
+     * Authenticates the user having the given credentials, returning a new
+     * AuthenticatedUser instance only if the credentials are valid. If the
+     * credentials are invalid or expired, an appropriate GuacamoleException
+     * will be thrown.
+     *
+     * @param authenticationProvider
+     *     The AuthenticationProvider on behalf of which the user is being
+     *     authenticated.
+     *
+     * @param credentials
+     *     The credentials to use to produce the AuthenticatedUser.
+     *
+     * @return
+     *     A new AuthenticatedUser instance for the user identified by the
+     *     given credentials.
+     *
+     * @throws GuacamoleException
+     *     If an error occurs during authentication, or if the given
+     *     credentials are invalid or expired.
+     */
+    public AuthenticatedUser authenticateUser(AuthenticationProvider authenticationProvider,
+            Credentials credentials) throws GuacamoleException;
+
+    /**
+     * Returning a new UserContext instance for the given already-authenticated
+     * user. A new placeholder account will be created for any user that does
+     * not already exist within the database.
+     *
+     * @param authenticatedUser
+     *     The credentials to use to produce the UserContext.
+     *
+     * @return
+     *     A new UserContext instance for the user identified by the given
+     *     credentials.
+     *
+     * @throws GuacamoleException
+     *     If an error occurs during authentication, or if the given
+     *     credentials are invalid or expired.
+     */
+    public UserContext getUserContext(AuthenticatedUser authenticatedUser)
+            throws GuacamoleException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4e3212f9/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
new file mode 100644
index 0000000..cc25e4a
--- /dev/null
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/InjectedAuthenticationProvider.java
@@ -0,0 +1,105 @@
+/*
+ * 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.auth.jdbc;
+
+import com.google.inject.Injector;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.UserContext;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+
+/**
+ * Provides a base implementation of an AuthenticationProvider which delegates
+ * the various function calls to an underlying AuthenticationProviderService
+ * implementation. As such a service is injectable by Guice, this provides a
+ * means for Guice to (effectively) apply dependency injection to an
+ * AuthenticationProvider, even though it is the AuthenticationProvider that
+ * serves as the entry point.
+ *
+ * @author Michael Jumper
+ */
+public abstract class InjectedAuthenticationProvider implements AuthenticationProvider {
+
+    /**
+     * The AuthenticationProviderService to which all AuthenticationProvider
+     * calls will be delegated.
+     */
+    private final AuthenticationProviderService authProviderService;
+
+    /**
+     * Creates a new AuthenticationProvider that delegates all calls to an
+     * underlying AuthenticationProviderService. The behavior of the
+     * AuthenticationProvider is defined by the given
+     * AuthenticationProviderService implementation, which will be injected by
+     * the Guice Injector provided by the given JDBCInjectorProvider.
+     *
+     * @param injectorProvider
+     *     A JDBCInjectorProvider instance which provides singleton instances
+     *     of a Guice Injector, pre-configured to set up all injections and
+     *     access to the underlying database via MyBatis.
+     *
+     * @param authProviderServiceClass
+     *    The AuthenticationProviderService implementation which defines the
+     *    behavior of this AuthenticationProvider.
+     *
+     * @throws GuacamoleException
+     *     If the Injector cannot be created due to an error.
+     */
+    public InjectedAuthenticationProvider(JDBCInjectorProvider injectorProvider,
+            Class<? extends AuthenticationProviderService> authProviderServiceClass)
+        throws GuacamoleException {
+
+        Injector injector = injectorProvider.get();
+        authProviderService = injector.getInstance(authProviderServiceClass);
+
+    }
+
+    @Override
+    public AuthenticatedUser authenticateUser(Credentials credentials)
+            throws GuacamoleException {
+        return authProviderService.authenticateUser(this, credentials);
+    }
+
+    @Override
+    public AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser authenticatedUser,
+            Credentials credentials) throws GuacamoleException {
+
+        // No need to update authenticated users
+        return authenticatedUser;
+
+    }
+
+    @Override
+    public UserContext getUserContext(AuthenticatedUser authenticatedUser)
+            throws GuacamoleException {
+        return authProviderService.getUserContext(authenticatedUser);
+    }
+
+    @Override
+    public UserContext updateUserContext(UserContext context,
+            AuthenticatedUser authenticatedUser) throws GuacamoleException {
+
+        // No need to update the context
+        return context;
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4e3212f9/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProvider.java
deleted file mode 100644
index ebacd13..0000000
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProvider.java
+++ /dev/null
@@ -1,101 +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.auth.jdbc;
-
-import com.google.inject.Injector;
-import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.net.auth.AuthenticationProvider;
-import org.apache.guacamole.net.auth.Credentials;
-import org.apache.guacamole.net.auth.UserContext;
-import org.apache.guacamole.auth.jdbc.user.AuthenticationProviderService;
-import org.apache.guacamole.net.auth.AuthenticatedUser;
-
-/**
- * Provides a base implementation of an AuthenticationProvider which is backed
- * by an arbitrary underlying database. It is up to the subclass implementation
- * to configure the underlying database appropriately via Guice.
- *
- * @author James Muehlner
- * @author Michael Jumper
- */
-public abstract class JDBCAuthenticationProvider implements AuthenticationProvider {
-
-    /**
-     * Provider of the singleton Injector instance which will manage the object
-     * graph of this authentication provider.
-     */
-    private final JDBCInjectorProvider injectorProvider;
-
-    /**
-     * Creates a new AuthenticationProvider that is backed by an arbitrary
-     * underlying database.
-     *
-     * @param injectorProvider
-     *     A JDBCInjectorProvider instance which provides singleton instances
-     *     of a Guice Injector, pre-configured to set up all injections and
-     *     access to the underlying database via MyBatis.
-     */
-    public JDBCAuthenticationProvider(JDBCInjectorProvider injectorProvider) {
-        this.injectorProvider = injectorProvider;
-    }
-
-    @Override
-    public AuthenticatedUser authenticateUser(Credentials credentials)
-            throws GuacamoleException {
-
-        Injector injector = injectorProvider.get();
-
-        // Create AuthenticatedUser based on credentials, if valid
-        AuthenticationProviderService authProviderService = injector.getInstance(AuthenticationProviderService.class);
-        return authProviderService.authenticateUser(this, credentials);
-
-    }
-
-    @Override
-    public AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser authenticatedUser,
-            Credentials credentials) throws GuacamoleException {
-
-        // No need to update authenticated users
-        return authenticatedUser;
-
-    }
-
-    @Override
-    public UserContext getUserContext(AuthenticatedUser authenticatedUser)
-            throws GuacamoleException {
-
-        Injector injector = injectorProvider.get();
-
-        // Create UserContext based on credentials, if valid
-        AuthenticationProviderService authProviderService = injector.getInstance(AuthenticationProviderService.class);
-        return authProviderService.getUserContext(authenticatedUser);
-
-    }
-
-    @Override
-    public UserContext updateUserContext(UserContext context,
-            AuthenticatedUser authenticatedUser) throws GuacamoleException {
-
-        // No need to update the context
-        return context;
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4e3212f9/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProviderService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProviderService.java
new file mode 100644
index 0000000..07b7382
--- /dev/null
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProviderService.java
@@ -0,0 +1,85 @@
+/*
+ * 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.auth.jdbc;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.jdbc.user.ModeledUser;
+import org.apache.guacamole.auth.jdbc.user.UserContext;
+import org.apache.guacamole.auth.jdbc.user.UserService;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
+import org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
+
+/**
+ * AuthenticationProviderService implementation which authenticates users with
+ * a username/password pair, producing new UserContext objects which are backed
+ * by an underlying, arbitrary database.
+ *
+ * @author Michael Jumper
+ */
+public class JDBCAuthenticationProviderService implements AuthenticationProviderService  {
+
+    /**
+     * Service for accessing users.
+     */
+    @Inject
+    private UserService userService;
+
+    /**
+     * Provider for retrieving UserContext instances.
+     */
+    @Inject
+    private Provider<UserContext> userContextProvider;
+
+    @Override
+    public AuthenticatedUser authenticateUser(AuthenticationProvider authenticationProvider,
+            Credentials credentials) throws GuacamoleException {
+
+        // Authenticate user
+        AuthenticatedUser user = userService.retrieveAuthenticatedUser(authenticationProvider, credentials);
+        if (user != null)
+            return user;
+
+        // Otherwise, unauthorized
+        throw new GuacamoleInvalidCredentialsException("Invalid login", CredentialsInfo.USERNAME_PASSWORD);
+
+    }
+
+    @Override
+    public org.apache.guacamole.net.auth.UserContext getUserContext(
+            AuthenticatedUser authenticatedUser) throws GuacamoleException {
+
+        // Retrieve user account for already-authenticated user
+        ModeledUser user = userService.retrieveUser(authenticatedUser);
+        if (user == null)
+            return null;
+
+        // Link to user context
+        UserContext context = userContextProvider.get();
+        context.init(user.getCurrentUser());
+        return context;
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4e3212f9/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/AuthenticationProviderService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/AuthenticationProviderService.java
deleted file mode 100644
index 3e61cf5..0000000
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/AuthenticationProviderService.java
+++ /dev/null
@@ -1,146 +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.auth.jdbc.user;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.auth.jdbc.sharing.ConnectionSharingService;
-import org.apache.guacamole.auth.jdbc.sharing.SharedConnectionUser;
-import org.apache.guacamole.auth.jdbc.sharing.SharedConnectionUserContext;
-import org.apache.guacamole.net.auth.AuthenticatedUser;
-import org.apache.guacamole.net.auth.AuthenticationProvider;
-import org.apache.guacamole.net.auth.Credentials;
-import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
-import org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
-
-/**
- * Service which authenticates users based on credentials and provides for
- * the creation of corresponding, new UserContext objects for authenticated
- * users.
- *
- * @author Michael Jumper
- */
-public class AuthenticationProviderService  {
-
-    /**
-     * Service for accessing users.
-     */
-    @Inject
-    private UserService userService;
-
-    /**
-     * Provider for retrieving UserContext instances.
-     */
-    @Inject
-    private Provider<UserContext> userContextProvider;
-
-    /**
-     * Provider for retrieving SharedConnectionUserContext instances.
-     */
-    @Inject
-    private Provider<SharedConnectionUserContext> sharedUserContextProvider;
-
-    /**
-     * Service for sharing active connections.
-     */
-    @Inject
-    private ConnectionSharingService sharingService;
-
-    /**
-     * Authenticates the user having the given credentials, returning a new
-     * AuthenticatedUser instance only if the credentials are valid. If the
-     * credentials are invalid or expired, an appropriate GuacamoleException
-     * will be thrown.
-     *
-     * @param authenticationProvider
-     *     The AuthenticationProvider on behalf of which the user is being
-     *     authenticated.
-     *
-     * @param credentials
-     *     The credentials to use to produce the AuthenticatedUser.
-     *
-     * @return
-     *     A new AuthenticatedUser instance for the user identified by the
-     *     given credentials.
-     *
-     * @throws GuacamoleException
-     *     If an error occurs during authentication, or if the given
-     *     credentials are invalid or expired.
-     */
-    public AuthenticatedUser authenticateUser(AuthenticationProvider authenticationProvider,
-            Credentials credentials) throws GuacamoleException {
-
-        AuthenticatedUser user;
-
-        // Check whether user is authenticating with a valid sharing key
-        user = sharingService.retrieveSharedConnectionUser(authenticationProvider, credentials);
-        if (user != null)
-            return user;
-
-        // Authenticate user
-        user = userService.retrieveAuthenticatedUser(authenticationProvider, credentials);
-        if (user != null)
-            return user;
-
-        // Otherwise, unauthorized
-        throw new GuacamoleInvalidCredentialsException("Invalid login", CredentialsInfo.USERNAME_PASSWORD);
-
-    }
-
-    /**
-     * Returning a new UserContext instance for the given already-authenticated
-     * user. A new placeholder account will be created for any user that does
-     * not already exist within the database.
-     *
-     * @param authenticatedUser
-     *     The credentials to use to produce the UserContext.
-     *
-     * @return
-     *     A new UserContext instance for the user identified by the given
-     *     credentials.
-     *
-     * @throws GuacamoleException
-     *     If an error occurs during authentication, or if the given
-     *     credentials are invalid or expired.
-     */
-    public org.apache.guacamole.net.auth.UserContext getUserContext(
-            AuthenticatedUser authenticatedUser) throws GuacamoleException {
-
-        // Produce sharing-specific user context if this is the user of a shared connection
-        if (authenticatedUser instanceof SharedConnectionUser) {
-            SharedConnectionUserContext context = sharedUserContextProvider.get();
-            context.init((SharedConnectionUser) authenticatedUser);
-            return context;
-        }
-
-        // Retrieve user account for already-authenticated user
-        ModeledUser user = userService.retrieveUser(authenticatedUser);
-        if (user == null)
-            return null;
-
-        // Link to user context
-        UserContext context = userContextProvider.get();
-        context.init(user.getCurrentUser());
-        return context;
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4e3212f9/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProvider.java
index e752163..e8ba307 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProvider.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProvider.java
@@ -19,7 +19,9 @@
 
 package org.apache.guacamole.auth.mysql;
 
-import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProvider;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.jdbc.InjectedAuthenticationProvider;
+import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProviderService;
 
 /**
  * Provides a MySQL based implementation of the AuthenticationProvider
@@ -28,15 +30,19 @@ import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProvider;
  * @author James Muehlner
  * @author Michael Jumper
  */
-public class MySQLAuthenticationProvider extends JDBCAuthenticationProvider {
+public class MySQLAuthenticationProvider extends InjectedAuthenticationProvider {
 
     /**
      * Creates a new MySQLAuthenticationProvider that reads and writes
      * authentication data to a MySQL database defined by properties in
      * guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If a required property is missing, or an error occurs while parsing
+     *     a property.
      */
-    public MySQLAuthenticationProvider() {
-        super(new MySQLInjectorProvider());
+    public MySQLAuthenticationProvider() throws GuacamoleException {
+        super(new MySQLInjectorProvider(), JDBCAuthenticationProviderService.class);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4e3212f9/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProvider.java
index 1c4b816..f8ef00d 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProvider.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProvider.java
@@ -19,7 +19,9 @@
 
 package org.apache.guacamole.auth.postgresql;
 
-import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProvider;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.jdbc.InjectedAuthenticationProvider;
+import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProviderService;
 
 /**
  * Provides a PostgreSQL-based implementation of the AuthenticationProvider
@@ -28,15 +30,19 @@ import org.apache.guacamole.auth.jdbc.JDBCAuthenticationProvider;
  * @author James Muehlner
  * @author Michael Jumper
  */
-public class PostgreSQLAuthenticationProvider extends JDBCAuthenticationProvider {
+public class PostgreSQLAuthenticationProvider extends InjectedAuthenticationProvider {
 
     /**
      * Creates a new PostgreSQLAuthenticationProvider that reads and writes
      * authentication data to a PostgreSQL database defined by properties in
      * guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If a required property is missing, or an error occurs while parsing
+     *     a property.
      */
-    public PostgreSQLAuthenticationProvider() {
-        super(new PostgreSQLInjectorProvider());
+    public PostgreSQLAuthenticationProvider() throws GuacamoleException {
+        super(new PostgreSQLInjectorProvider(), JDBCAuthenticationProviderService.class);
     }
 
     @Override


[4/4] incubator-guacamole-client git commit: GUACAMOLE-5: Merge change allowing for sharing-specific authentication providers.

Posted by jm...@apache.org.
GUACAMOLE-5: Merge change allowing for sharing-specific authentication providers.


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/872aac37
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/872aac37
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/872aac37

Branch: refs/heads/master
Commit: 872aac375cedf8e22444ed6fb2531b0e44869da6
Parents: b1a8a4d 06a7ca1
Author: James Muehlner <ja...@guac-dev.org>
Authored: Fri Jul 29 19:07:22 2016 -0700
Committer: James Muehlner <ja...@guac-dev.org>
Committed: Fri Jul 29 19:07:22 2016 -0700

----------------------------------------------------------------------
 .../jdbc/AuthenticationProviderService.java     |  80 ++++++++++
 .../jdbc/InjectedAuthenticationProvider.java    | 105 +++++++++++++
 .../jdbc/JDBCAuthenticationProviderService.java |  85 +++++++++++
 .../auth/jdbc/JDBCInjectorProvider.java         |  90 ++++++++++++
 .../SharedAuthenticationProviderService.java    |  84 +++++++++++
 .../user/AuthenticationProviderService.java     | 146 -------------------
 .../auth/mysql/MySQLAuthenticationProvider.java |  72 +--------
 .../auth/mysql/MySQLInjectorProvider.java       |  51 +++++++
 .../MySQLSharedAuthenticationProvider.java      |  52 +++++++
 .../src/main/resources/guac-manifest.json       |   3 +-
 .../PostgreSQLAuthenticationProvider.java       |  79 +---------
 .../postgresql/PostgreSQLInjectorProvider.java  |  51 +++++++
 .../PostgreSQLSharedAuthenticationProvider.java |  52 +++++++
 .../src/main/resources/guac-manifest.json       |   3 +-
 14 files changed, 662 insertions(+), 291 deletions(-)
----------------------------------------------------------------------