mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-38: Use newly-implemented AbstractuserContext and AbstractAuthenticationProvider classes, remove deprecated classes.
This commit is contained in:
@@ -23,7 +23,7 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
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.AbstractAuthenticationProvider;
|
||||
import org.apache.guacamole.net.auth.Credentials;
|
||||
import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
|
||||
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
|
||||
* throughout the web client.
|
||||
*/
|
||||
public class QuickConnectAuthenticationProvider implements AuthenticationProvider {
|
||||
public class QuickConnectAuthenticationProvider extends AbstractAuthenticationProvider {
|
||||
|
||||
/**
|
||||
* userContext for this authentication provider.
|
||||
@@ -47,31 +47,6 @@ public class QuickConnectAuthenticationProvider implements AuthenticationProvide
|
||||
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
|
||||
public UserContext getUserContext(AuthenticatedUser authenticatedUser)
|
||||
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.
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,12 +19,13 @@
|
||||
|
||||
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 org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.auth.quickconnect.utility.QCParser;
|
||||
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.protocol.GuacamoleConfiguration;
|
||||
|
||||
@@ -32,13 +33,19 @@ import org.apache.guacamole.protocol.GuacamoleConfiguration;
|
||||
* Implementation of the Connection Directory, stored
|
||||
* completely in-memory.
|
||||
*/
|
||||
public class QuickConnectDirectory extends SimpleConnectionDirectory {
|
||||
public class QuickConnectDirectory extends SimpleDirectory<Connection> {
|
||||
|
||||
/**
|
||||
* The unique identifier of the root connection group.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@@ -54,15 +61,15 @@ public class QuickConnectDirectory extends SimpleConnectionDirectory {
|
||||
* connections contained within the given Map.
|
||||
*
|
||||
* @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.
|
||||
* @param rootGroup
|
||||
* A group that should be at the base of this directory.
|
||||
*/
|
||||
public QuickConnectDirectory(Collection<Connection> connections, ConnectionGroup rootGroup) {
|
||||
super(connections);
|
||||
public QuickConnectDirectory(ConnectionGroup rootGroup) {
|
||||
this.rootGroup = (QuickConnectConnectionGroup)rootGroup;
|
||||
this.connectionId = new AtomicInteger();
|
||||
super.setObjects(this.connections);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,56 +84,21 @@ public class QuickConnectDirectory extends SimpleConnectionDirectory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Connection object) throws GuacamoleException {
|
||||
|
||||
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;
|
||||
|
||||
public void add(Connection connection) throws GuacamoleException {
|
||||
connections.put(connection.getIdentifier(), connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* The GuacamoleConfiguration to use to create the
|
||||
* QuickConnection object.
|
||||
*
|
||||
* @return
|
||||
* The connectionId of the object creation in the directory.
|
||||
* The identifier of the connection created in the directory.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs adding the object to the tree.
|
||||
@@ -144,7 +116,7 @@ public class QuickConnectDirectory extends SimpleConnectionDirectory {
|
||||
connection.setParentIdentifier(ROOT_IDENTIFIER);
|
||||
|
||||
// Place the object in directory
|
||||
putConnection(connection);
|
||||
add(connection);
|
||||
|
||||
// Add connection to the tree.
|
||||
this.rootGroup.addConnectionIdentifier(connectionId);
|
||||
@@ -152,9 +124,4 @@ public class QuickConnectDirectory extends SimpleConnectionDirectory {
|
||||
return connectionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Connection object) throws GuacamoleException {
|
||||
putConnection(object);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import java.util.Collections;
|
||||
import org.apache.guacamole.auth.quickconnect.rest.QuickConnectREST;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
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.ActivityRecord;
|
||||
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.UserContext;
|
||||
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.SimpleUser;
|
||||
import org.apache.guacamole.net.auth.simple.SimpleUserDirectory;
|
||||
|
||||
/**
|
||||
* A simple implementation of UserContext to support the QuickConnect
|
||||
* extension, primarily used for storing connections the user has
|
||||
* created using the QuickConnect bar in the webapp.
|
||||
*/
|
||||
public class QuickConnectUserContext implements UserContext {
|
||||
|
||||
/**
|
||||
* The unique identifier of the root connection group.
|
||||
*/
|
||||
public static final String ROOT_IDENTIFIER = "ROOT";
|
||||
public class QuickConnectUserContext extends AbstractUserContext {
|
||||
|
||||
/**
|
||||
* 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
|
||||
// single root identifier.
|
||||
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
|
||||
// preexisting connections, and the single root group.
|
||||
this.self = new SimpleUser(username,
|
||||
Collections.<String>emptyList(),
|
||||
Collections.singleton(ROOT_IDENTIFIER)
|
||||
Collections.singleton(DEFAULT_ROOT_CONNECTION_GROUP)
|
||||
);
|
||||
|
||||
// Initialize each of the directories associated with the userContext.
|
||||
this.userDirectory = new SimpleUserDirectory(self);
|
||||
this.connectionDirectory = new QuickConnectDirectory(Collections.<Connection>emptyList(), this.rootGroup);
|
||||
this.connectionGroupDirectory = new SimpleConnectionGroupDirectory(Collections.singleton(this.rootGroup));
|
||||
this.userDirectory = new SimpleDirectory<User>(self);
|
||||
this.connectionDirectory = new QuickConnectDirectory(this.rootGroup);
|
||||
this.connectionGroupDirectory = new SimpleDirectory<ConnectionGroup>(Collections.singleton(this.rootGroup));
|
||||
|
||||
// Set the authProvider to the calling authProvider object.
|
||||
this.authProvider = authProvider;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuickConnectDirectory getConnectionDirectory() {
|
||||
return connectionDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User self() {
|
||||
return self;
|
||||
@@ -134,11 +134,6 @@ public class QuickConnectUserContext implements UserContext {
|
||||
return new QuickConnectREST(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthenticationProvider getAuthenticationProvider() {
|
||||
return authProvider;
|
||||
@@ -150,18 +145,6 @@ public class QuickConnectUserContext implements UserContext {
|
||||
return userDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityRecordSet<ActivityRecord> getUserHistory()
|
||||
throws GuacamoleException {
|
||||
return new SimpleActivityRecordSet<ActivityRecord>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuickConnectDirectory getConnectionDirectory()
|
||||
throws GuacamoleException {
|
||||
return connectionDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Directory<ConnectionGroup> getConnectionGroupDirectory()
|
||||
throws GuacamoleException {
|
||||
@@ -173,42 +156,4 @@ public class QuickConnectUserContext implements UserContext {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user