GUACAMOLE-38: Use newly-implemented AbstractuserContext and AbstractAuthenticationProvider classes, remove deprecated classes.

This commit is contained in:
Nick Couchman
2018-04-14 11:22:40 -04:00
parent 43919e5623
commit 3feb2c2de1
3 changed files with 34 additions and 188 deletions

View File

@@ -23,7 +23,7 @@ import java.util.Collections;
import java.util.Map; import java.util.Map;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.AuthenticatedUser; import org.apache.guacamole.net.auth.AuthenticatedUser;
import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.AbstractAuthenticationProvider;
import org.apache.guacamole.net.auth.Credentials; import org.apache.guacamole.net.auth.Credentials;
import org.apache.guacamole.net.auth.credentials.CredentialsInfo; import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
import org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException; import org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
@@ -35,7 +35,7 @@ import org.apache.guacamole.protocol.GuacamoleConfiguration;
* process so that the QuickConnect functionality can be initialized and be used * process so that the QuickConnect functionality can be initialized and be used
* throughout the web client. * throughout the web client.
*/ */
public class QuickConnectAuthenticationProvider implements AuthenticationProvider { public class QuickConnectAuthenticationProvider extends AbstractAuthenticationProvider {
/** /**
* userContext for this authentication provider. * userContext for this authentication provider.
@@ -47,31 +47,6 @@ public class QuickConnectAuthenticationProvider implements AuthenticationProvide
return "quickconnect"; return "quickconnect";
} }
@Override
public Object getResource() throws GuacamoleException {
return null;
}
/**
* For QuickConnect, authenticateUser simply returns null because this
* extension is designed to provide only a connection directory to users
* that are already authenticated and not any actual authentication.
*
* @param credentials
* Credentials object passed in from Guacamole login.
*
* @return
* Returns null, which causes the client to move on to the next
* module.
*/
@Override
public AuthenticatedUser authenticateUser(Credentials credentials)
throws GuacamoleException {
return null;
}
@Override @Override
public UserContext getUserContext(AuthenticatedUser authenticatedUser) public UserContext getUserContext(AuthenticatedUser authenticatedUser)
throws GuacamoleException { throws GuacamoleException {
@@ -80,45 +55,4 @@ public class QuickConnectAuthenticationProvider implements AuthenticationProvide
} }
@Override
public AuthenticatedUser updateAuthenticatedUser(AuthenticatedUser authenticatedUser,
Credentials credentials) throws GuacamoleException {
// Simply return the given user, updating nothing
return authenticatedUser;
}
@Override
public UserContext updateUserContext(UserContext context,
AuthenticatedUser authorizedUser, Credentials credentials)
throws GuacamoleException {
// Simply return the given context, updating nothing
return context;
}
@Override
public UserContext decorate(UserContext context,
AuthenticatedUser authenticatedUser, Credentials credentials)
throws GuacamoleException {
// Simply return the given context, decorating nothing
return context;
}
@Override
public UserContext redecorate(UserContext decorated, UserContext context,
AuthenticatedUser authenticatedUser, Credentials credentials)
throws GuacamoleException {
return decorate(context, authenticatedUser, credentials);
}
@Override
public void shutdown() {
// Nothing to do, here.
}
} }

View File

@@ -19,12 +19,13 @@
package org.apache.guacamole.auth.quickconnect; package org.apache.guacamole.auth.quickconnect;
import java.util.Collection; import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.quickconnect.utility.QCParser; import org.apache.guacamole.auth.quickconnect.utility.QCParser;
import org.apache.guacamole.net.auth.ConnectionGroup; import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.net.auth.simple.SimpleConnectionDirectory; import org.apache.guacamole.net.auth.simple.SimpleDirectory;
import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.protocol.GuacamoleConfiguration; import org.apache.guacamole.protocol.GuacamoleConfiguration;
@@ -32,13 +33,19 @@ import org.apache.guacamole.protocol.GuacamoleConfiguration;
* Implementation of the Connection Directory, stored * Implementation of the Connection Directory, stored
* completely in-memory. * completely in-memory.
*/ */
public class QuickConnectDirectory extends SimpleConnectionDirectory { public class QuickConnectDirectory extends SimpleDirectory<Connection> {
/** /**
* The unique identifier of the root connection group. * The unique identifier of the root connection group.
*/ */
private static final String ROOT_IDENTIFIER = "ROOT"; private static final String ROOT_IDENTIFIER = "ROOT";
/**
* The connections to store.
*/
private final Map<String, Connection> connections =
new HashMap<String, Connection>();
/** /**
* The root connection group for this directory. * The root connection group for this directory.
*/ */
@@ -54,15 +61,15 @@ public class QuickConnectDirectory extends SimpleConnectionDirectory {
* connections contained within the given Map. * connections contained within the given Map.
* *
* @param connections * @param connections
* A Collection of all connections that should be present in this * A Map of all connections that should be present in this
* connection directory. * connection directory.
* @param rootGroup * @param rootGroup
* A group that should be at the base of this directory. * A group that should be at the base of this directory.
*/ */
public QuickConnectDirectory(Collection<Connection> connections, ConnectionGroup rootGroup) { public QuickConnectDirectory(ConnectionGroup rootGroup) {
super(connections);
this.rootGroup = (QuickConnectConnectionGroup)rootGroup; this.rootGroup = (QuickConnectConnectionGroup)rootGroup;
this.connectionId = new AtomicInteger(); this.connectionId = new AtomicInteger();
super.setObjects(this.connections);
} }
/** /**
@@ -77,56 +84,21 @@ public class QuickConnectDirectory extends SimpleConnectionDirectory {
} }
@Override @Override
public void add(Connection object) throws GuacamoleException { public void add(Connection connection) throws GuacamoleException {
connections.put(connection.getIdentifier(), connection);
put(new QuickConnection(object));
}
/**
* Create a connection object on the tree using an existing
* QuickConnection connection, after setting the identifier
* and parent object.
*
* @param connection
* The QuickConnection object to add to the tree.
*
* @return
* The connectionId of the object added to the directory.
*
* @throws GuacamoleException
* If an error is encountered adding the object to the
* directory.
*/
public String put(QuickConnection connection) throws GuacamoleException {
// Get the next connection ID.
String connectionId = Integer.toString(getNextConnectionID());
// Set up identifier and parent on object.
connection.setIdentifier(connectionId);
connection.setParentIdentifier(ROOT_IDENTIFIER);
// Add connection to the directory
putConnection(connection);
// Add connection to the tree
this.rootGroup.addConnectionIdentifier(connectionId);
return connectionId;
} }
/** /**
* Create a QuickConnection object from a GuacamoleConfiguration * Create a QuickConnection object from a GuacamoleConfiguration
* and get an ID and place it on the tree. * and get an ID and place it on the tree, returning the new
* connection identifier value.
* *
* @param config * @param config
* The GuacamoleConfiguration to use to create the * The GuacamoleConfiguration to use to create the
* QuickConnection object. * QuickConnection object.
* *
* @return * @return
* The connectionId of the object creation in the directory. * The identifier of the connection created in the directory.
* *
* @throws GuacamoleException * @throws GuacamoleException
* If an error occurs adding the object to the tree. * If an error occurs adding the object to the tree.
@@ -144,7 +116,7 @@ public class QuickConnectDirectory extends SimpleConnectionDirectory {
connection.setParentIdentifier(ROOT_IDENTIFIER); connection.setParentIdentifier(ROOT_IDENTIFIER);
// Place the object in directory // Place the object in directory
putConnection(connection); add(connection);
// Add connection to the tree. // Add connection to the tree.
this.rootGroup.addConnectionIdentifier(connectionId); this.rootGroup.addConnectionIdentifier(connectionId);
@@ -152,9 +124,4 @@ public class QuickConnectDirectory extends SimpleConnectionDirectory {
return connectionId; return connectionId;
} }
@Override
public void update(Connection object) throws GuacamoleException {
putConnection(object);
}
} }

View File

@@ -24,6 +24,7 @@ import java.util.Collections;
import org.apache.guacamole.auth.quickconnect.rest.QuickConnectREST; import org.apache.guacamole.auth.quickconnect.rest.QuickConnectREST;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.form.Form; import org.apache.guacamole.form.Form;
import org.apache.guacamole.net.auth.AbstractUserContext;
import org.apache.guacamole.net.auth.ActiveConnection; import org.apache.guacamole.net.auth.ActiveConnection;
import org.apache.guacamole.net.auth.ActivityRecord; import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.ActivityRecordSet; import org.apache.guacamole.net.auth.ActivityRecordSet;
@@ -36,22 +37,15 @@ import org.apache.guacamole.net.auth.SharingProfile;
import org.apache.guacamole.net.auth.User; import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.UserContext; import org.apache.guacamole.net.auth.UserContext;
import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet; import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet;
import org.apache.guacamole.net.auth.simple.SimpleConnectionGroupDirectory;
import org.apache.guacamole.net.auth.simple.SimpleDirectory; import org.apache.guacamole.net.auth.simple.SimpleDirectory;
import org.apache.guacamole.net.auth.simple.SimpleUser; import org.apache.guacamole.net.auth.simple.SimpleUser;
import org.apache.guacamole.net.auth.simple.SimpleUserDirectory;
/** /**
* A simple implementation of UserContext to support the QuickConnect * A simple implementation of UserContext to support the QuickConnect
* extension, primarily used for storing connections the user has * extension, primarily used for storing connections the user has
* created using the QuickConnect bar in the webapp. * created using the QuickConnect bar in the webapp.
*/ */
public class QuickConnectUserContext implements UserContext { public class QuickConnectUserContext extends AbstractUserContext {
/**
* The unique identifier of the root connection group.
*/
public static final String ROOT_IDENTIFIER = "ROOT";
/** /**
* The AuthenticationProvider that created this UserContext. * The AuthenticationProvider that created this UserContext.
@@ -104,26 +98,32 @@ public class QuickConnectUserContext implements UserContext {
// Initialize the rootGroup to a basic connection group with a // Initialize the rootGroup to a basic connection group with a
// single root identifier. // single root identifier.
this.rootGroup = new QuickConnectConnectionGroup( this.rootGroup = new QuickConnectConnectionGroup(
ROOT_IDENTIFIER, ROOT_IDENTIFIER DEFAULT_ROOT_CONNECTION_GROUP,
DEFAULT_ROOT_CONNECTION_GROUP
); );
// Initialize the user to a SimpleUser with the username, no // Initialize the user to a SimpleUser with the username, no
// preexisting connections, and the single root group. // preexisting connections, and the single root group.
this.self = new SimpleUser(username, this.self = new SimpleUser(username,
Collections.<String>emptyList(), Collections.<String>emptyList(),
Collections.singleton(ROOT_IDENTIFIER) Collections.singleton(DEFAULT_ROOT_CONNECTION_GROUP)
); );
// Initialize each of the directories associated with the userContext. // Initialize each of the directories associated with the userContext.
this.userDirectory = new SimpleUserDirectory(self); this.userDirectory = new SimpleDirectory<User>(self);
this.connectionDirectory = new QuickConnectDirectory(Collections.<Connection>emptyList(), this.rootGroup); this.connectionDirectory = new QuickConnectDirectory(this.rootGroup);
this.connectionGroupDirectory = new SimpleConnectionGroupDirectory(Collections.singleton(this.rootGroup)); this.connectionGroupDirectory = new SimpleDirectory<ConnectionGroup>(Collections.singleton(this.rootGroup));
// Set the authProvider to the calling authProvider object. // Set the authProvider to the calling authProvider object.
this.authProvider = authProvider; this.authProvider = authProvider;
} }
@Override
public QuickConnectDirectory getConnectionDirectory() {
return connectionDirectory;
}
@Override @Override
public User self() { public User self() {
return self; return self;
@@ -134,11 +134,6 @@ public class QuickConnectUserContext implements UserContext {
return new QuickConnectREST(this); return new QuickConnectREST(this);
} }
@Override
public void invalidate() {
// Do nothing.
}
@Override @Override
public AuthenticationProvider getAuthenticationProvider() { public AuthenticationProvider getAuthenticationProvider() {
return authProvider; return authProvider;
@@ -150,18 +145,6 @@ public class QuickConnectUserContext implements UserContext {
return userDirectory; return userDirectory;
} }
@Override
public ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
return new SimpleActivityRecordSet<ActivityRecord>();
}
@Override
public QuickConnectDirectory getConnectionDirectory()
throws GuacamoleException {
return connectionDirectory;
}
@Override @Override
public Directory<ConnectionGroup> getConnectionGroupDirectory() public Directory<ConnectionGroup> getConnectionGroupDirectory()
throws GuacamoleException { throws GuacamoleException {
@@ -173,42 +156,4 @@ public class QuickConnectUserContext implements UserContext {
return rootGroup; return rootGroup;
} }
@Override
public Directory<SharingProfile> getSharingProfileDirectory()
throws GuacamoleException {
return new SimpleDirectory<SharingProfile>();
}
@Override
public Directory<ActiveConnection> getActiveConnectionDirectory()
throws GuacamoleException {
return new SimpleDirectory<ActiveConnection>();
}
@Override
public ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException {
return new SimpleActivityRecordSet<ConnectionRecord>();
}
@Override
public Collection<Form> getUserAttributes() {
return Collections.<Form>emptyList();
}
@Override
public Collection<Form> getConnectionAttributes() {
return Collections.<Form>emptyList();
}
@Override
public Collection<Form> getConnectionGroupAttributes() {
return Collections.<Form>emptyList();
}
@Override
public Collection<Form> getSharingProfileAttributes() {
return Collections.<Form>emptyList();
}
} }