GUAC-586: Associate AuthenticationProvider directly with UserContext.

This commit is contained in:
Michael Jumper
2015-08-26 12:53:38 -07:00
parent 6eee1e758c
commit 15e948138d
7 changed files with 80 additions and 17 deletions

View File

@@ -63,6 +63,7 @@ import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionPermis
import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionService; import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionService;
import org.glyptodon.guacamole.auth.jdbc.activeconnection.TrackedActiveConnection; import org.glyptodon.guacamole.auth.jdbc.activeconnection.TrackedActiveConnection;
import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.environment.Environment;
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
import org.mybatis.guice.MyBatisModule; import org.mybatis.guice.MyBatisModule;
import org.mybatis.guice.datasource.builtin.PooledDataSourceProvider; import org.mybatis.guice.datasource.builtin.PooledDataSourceProvider;
@@ -86,19 +87,31 @@ public class JDBCAuthenticationProviderModule extends MyBatisModule {
*/ */
private final GuacamoleTunnelService tunnelService; private final GuacamoleTunnelService tunnelService;
/**
* The AuthenticationProvider which is using this module to configure
* injection.
*/
private final AuthenticationProvider authProvider;
/** /**
* Creates a new JDBC authentication provider module that configures the * Creates a new JDBC authentication provider module that configures the
* various injected base classes using the given environment, and provides * various injected base classes using the given environment, and provides
* connections using the given socket service. * connections using the given socket service.
* *
* @param authProvider
* The AuthenticationProvider which is using this module to configure
* injection.
*
* @param environment * @param environment
* The environment to use to configure injected classes. * The environment to use to configure injected classes.
* *
* @param tunnelService * @param tunnelService
* The tunnel service to use to provide tunnels sockets for connections. * The tunnel service to use to provide tunnels sockets for connections.
*/ */
public JDBCAuthenticationProviderModule(Environment environment, public JDBCAuthenticationProviderModule(AuthenticationProvider authProvider,
Environment environment,
GuacamoleTunnelService tunnelService) { GuacamoleTunnelService tunnelService) {
this.authProvider = authProvider;
this.environment = environment; this.environment = environment;
this.tunnelService = tunnelService; this.tunnelService = tunnelService;
} }
@@ -126,6 +139,7 @@ public class JDBCAuthenticationProviderModule extends MyBatisModule {
// Bind core implementations of guacamole-ext classes // Bind core implementations of guacamole-ext classes
bind(ActiveConnectionDirectory.class); bind(ActiveConnectionDirectory.class);
bind(ActiveConnectionPermissionSet.class); bind(ActiveConnectionPermissionSet.class);
bind(AuthenticationProvider.class).toInstance(authProvider);
bind(Environment.class).toInstance(environment); bind(Environment.class).toInstance(environment);
bind(ConnectionDirectory.class); bind(ConnectionDirectory.class);
bind(ConnectionGroupDirectory.class); bind(ConnectionGroupDirectory.class);

View File

@@ -36,6 +36,7 @@ import org.glyptodon.guacamole.auth.jdbc.connection.ModeledConnection;
import org.glyptodon.guacamole.auth.jdbc.connectiongroup.ModeledConnectionGroup; import org.glyptodon.guacamole.auth.jdbc.connectiongroup.ModeledConnectionGroup;
import org.glyptodon.guacamole.form.Form; import org.glyptodon.guacamole.form.Form;
import org.glyptodon.guacamole.net.auth.ActiveConnection; import org.glyptodon.guacamole.net.auth.ActiveConnection;
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.Connection;
import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.ConnectionGroup;
import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.Directory;
@@ -51,6 +52,12 @@ import org.glyptodon.guacamole.net.auth.User;
public class UserContext extends RestrictedObject public class UserContext extends RestrictedObject
implements org.glyptodon.guacamole.net.auth.UserContext { implements org.glyptodon.guacamole.net.auth.UserContext {
/**
* The AuthenticationProvider that created this UserContext.
*/
@Inject
private AuthenticationProvider authProvider;
/** /**
* User directory restricted by the permissions of the user associated * User directory restricted by the permissions of the user associated
* with this context. * with this context.
@@ -103,6 +110,11 @@ public class UserContext extends RestrictedObject
return getCurrentUser().getUser(); return getCurrentUser().getUser();
} }
@Override
public AuthenticationProvider getAuthenticationProvider() {
return authProvider;
}
@Override @Override
public Directory<User> getUserDirectory() throws GuacamoleException { public Directory<User> getUserDirectory() throws GuacamoleException {
return userDirectory; return userDirectory;

View File

@@ -185,7 +185,8 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
new MySQLAuthenticationProviderModule(environment), new MySQLAuthenticationProviderModule(environment),
// Configure JDBC authentication core // Configure JDBC authentication core
new JDBCAuthenticationProviderModule(environment, getTunnelService(environment)) new JDBCAuthenticationProviderModule(this, environment,
getTunnelService(environment))
); );

View File

@@ -185,7 +185,8 @@ public class PostgreSQLAuthenticationProvider implements AuthenticationProvider
new PostgreSQLAuthenticationProviderModule(environment), new PostgreSQLAuthenticationProviderModule(environment),
// Configure JDBC authentication core // Configure JDBC authentication core
new JDBCAuthenticationProviderModule(environment, getTunnelService(environment)) new JDBCAuthenticationProviderModule(this, environment,
getTunnelService(environment))
); );

View File

@@ -43,6 +43,16 @@ public interface UserContext {
*/ */
User self(); User self();
/**
* Returns the AuthenticationProvider which created this UserContext, which
* may not be the same AuthenticationProvider that authenticated the user
* associated with this UserContext.
*
* @return
* The AuthenticationProvider that created this UserContext.
*/
AuthenticationProvider getAuthenticationProvider();
/** /**
* Retrieves a Directory which can be used to view and manipulate other * Retrieves a Directory which can be used to view and manipulate other
* users, but only as allowed by the permissions given to the user of this * users, but only as allowed by the permissions given to the user of this

View File

@@ -239,7 +239,7 @@ public abstract class SimpleAuthenticationProvider
return null; return null;
// Return user context restricted to authorized configs // Return user context restricted to authorized configs
return new SimpleUserContext(authenticatedUser.getIdentifier(), configs); return new SimpleUserContext(this, authenticatedUser.getIdentifier(), configs);
} }

View File

@@ -30,6 +30,7 @@ import java.util.UUID;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.form.Form; import org.glyptodon.guacamole.form.Form;
import org.glyptodon.guacamole.net.auth.ActiveConnection; import org.glyptodon.guacamole.net.auth.ActiveConnection;
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.Connection;
import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.ConnectionGroup;
import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.Directory;
@@ -51,6 +52,11 @@ public class SimpleUserContext implements UserContext {
*/ */
private static final String ROOT_IDENTIFIER = "ROOT"; private static final String ROOT_IDENTIFIER = "ROOT";
/**
* The AuthenticationProvider that created this UserContext.
*/
private final AuthenticationProvider authProvider;
/** /**
* Reference to the user whose permissions dictate the configurations * Reference to the user whose permissions dictate the configurations
* accessible within this UserContext. * accessible within this UserContext.
@@ -85,23 +91,34 @@ public class SimpleUserContext implements UserContext {
* configurations within the given Map. The username is assigned * configurations within the given Map. The username is assigned
* arbitrarily. * arbitrarily.
* *
* @param configs A Map of all configurations for which the user associated * @param authProvider
* with this UserContext has read access. * The AuthenticationProvider creating this UserContext.
*
* @param configs
* A Map of all configurations for which the user associated with this
* UserContext has read access.
*/ */
public SimpleUserContext(Map<String, GuacamoleConfiguration> configs) { public SimpleUserContext(AuthenticationProvider authProvider,
this(UUID.randomUUID().toString(), configs); Map<String, GuacamoleConfiguration> configs) {
this(authProvider, UUID.randomUUID().toString(), configs);
} }
/** /**
* Creates a new SimpleUserContext for the user with the given username * Creates a new SimpleUserContext for the user with the given username
* which provides access to only those configurations within the given Map. * which provides access to only those configurations within the given Map.
* *
* @param username The username of the user associated with this * @param authProvider
* UserContext. * The AuthenticationProvider creating this UserContext.
* @param configs A Map of all configurations for which the user associated *
* with this UserContext has read access. * @param username
* The username of the user associated with this UserContext.
*
* @param configs
* A Map of all configurations for which the user associated with
* this UserContext has read access.
*/ */
public SimpleUserContext(String username, Map<String, GuacamoleConfiguration> configs) { public SimpleUserContext(AuthenticationProvider authProvider,
String username, Map<String, GuacamoleConfiguration> configs) {
Collection<String> connectionIdentifiers = new ArrayList<String>(configs.size()); Collection<String> connectionIdentifiers = new ArrayList<String>(configs.size());
Collection<String> connectionGroupIdentifiers = Collections.singleton(ROOT_IDENTIFIER); Collection<String> connectionGroupIdentifiers = Collections.singleton(ROOT_IDENTIFIER);
@@ -139,6 +156,9 @@ public class SimpleUserContext implements UserContext {
this.connectionDirectory = new SimpleConnectionDirectory(connections); this.connectionDirectory = new SimpleConnectionDirectory(connections);
this.connectionGroupDirectory = new SimpleConnectionGroupDirectory(Collections.singleton(this.rootGroup)); this.connectionGroupDirectory = new SimpleConnectionGroupDirectory(Collections.singleton(this.rootGroup));
// Associate provided AuthenticationProvider
this.authProvider = authProvider;
} }
@Override @Override
@@ -146,6 +166,11 @@ public class SimpleUserContext implements UserContext {
return self; return self;
} }
@Override
public AuthenticationProvider getAuthenticationProvider() {
return authProvider;
}
@Override @Override
public Directory<User> getUserDirectory() public Directory<User> getUserDirectory()
throws GuacamoleException { throws GuacamoleException {