mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-38: Code cleanup; style, and grammar tweaks.
This commit is contained in:
@@ -25,8 +25,8 @@ import org.apache.guacamole.net.auth.AbstractAuthenticationProvider;
|
||||
import org.apache.guacamole.net.auth.UserContext;
|
||||
|
||||
/**
|
||||
* Class providing the necessary hooks into the Guacamole Client authentication
|
||||
* process so that the QuickConnect functionality can be initialized and be used
|
||||
* This class provides the necessary hooks into the Guacamole Client authentication
|
||||
* process so that the QuickConnect functionality can be initialized and used
|
||||
* throughout the web client.
|
||||
*/
|
||||
public class QuickConnectAuthenticationProvider extends AbstractAuthenticationProvider {
|
||||
|
@@ -31,7 +31,7 @@ import org.apache.guacamole.net.auth.Connection;
|
||||
import org.apache.guacamole.protocol.GuacamoleConfiguration;
|
||||
|
||||
/**
|
||||
* Implementation of the Connection Directory, stored
|
||||
* Implementation of a directory to stored Connection objects
|
||||
* completely in-memory.
|
||||
*/
|
||||
public class QuickConnectDirectory extends SimpleDirectory<Connection> {
|
||||
@@ -58,14 +58,12 @@ public class QuickConnectDirectory extends SimpleDirectory<Connection> {
|
||||
private AtomicInteger connectionId;
|
||||
|
||||
/**
|
||||
* Creates a new QuickConnectDirectory which provides access to the
|
||||
* connections contained within the given Map.
|
||||
* Creates a new QuickConnectDirectory with the default
|
||||
* empty Map for Connection objects, and the specified
|
||||
* ConnectionGroup at the root of the directory.
|
||||
*
|
||||
* @param connections
|
||||
* 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.
|
||||
* A group that should be at the root of this directory.
|
||||
*/
|
||||
public QuickConnectDirectory(ConnectionGroup rootGroup) {
|
||||
this.rootGroup = (QuickConnectionGroup)rootGroup;
|
||||
@@ -74,11 +72,12 @@ public class QuickConnectDirectory extends SimpleDirectory<Connection> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current counter and then increments it.
|
||||
* Returns the current connection identifier counter and
|
||||
* then increments it.
|
||||
*
|
||||
* @return
|
||||
* An Integer representing the next available connection
|
||||
* ID to get used when adding connections.
|
||||
* An int representing the next available connection
|
||||
* identifier to be used when adding connections.
|
||||
*/
|
||||
private int getNextConnectionID() {
|
||||
return connectionId.getAndIncrement();
|
||||
@@ -90,9 +89,9 @@ public class QuickConnectDirectory extends SimpleDirectory<Connection> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SimpleConnection object from a GuacamoleConfiguration
|
||||
* and get an ID and place it on the tree, returning the new
|
||||
* connection identifier value.
|
||||
* Create a SimpleConnection object from a GuacamoleConfiguration,
|
||||
* obtain an identifier, and place it on the tree, returning the
|
||||
* identifier value of the new connection.
|
||||
*
|
||||
* @param config
|
||||
* The GuacamoleConfiguration to use to create the
|
||||
@@ -106,17 +105,17 @@ public class QuickConnectDirectory extends SimpleDirectory<Connection> {
|
||||
*/
|
||||
public String create(GuacamoleConfiguration config) throws GuacamoleException {
|
||||
|
||||
// Get the next connection ID
|
||||
// Get the next connection identifier.
|
||||
String connectionId = Integer.toString(getNextConnectionID());
|
||||
|
||||
// Generate a name for the configuration
|
||||
// Generate a name for the configuration.
|
||||
String name = QCParser.getName(config);
|
||||
|
||||
// Create a new connection and set parent identifier.
|
||||
// Create a new connection and set the parent identifier.
|
||||
Connection connection = new SimpleConnection(name, connectionId, config);
|
||||
connection.setParentIdentifier(ROOT_IDENTIFIER);
|
||||
|
||||
// Place the object in directory
|
||||
// Place the object in this directory.
|
||||
add(connection);
|
||||
|
||||
// Add connection to the tree.
|
||||
|
@@ -32,8 +32,8 @@ import org.apache.guacamole.net.auth.simple.SimpleUser;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* extension, used for storing connections the user has created
|
||||
* with the QuickConnect bar in the webapp.
|
||||
*/
|
||||
public class QuickConnectUserContext extends AbstractUserContext {
|
||||
|
||||
@@ -48,12 +48,6 @@ public class QuickConnectUserContext extends AbstractUserContext {
|
||||
*/
|
||||
private final User self;
|
||||
|
||||
/**
|
||||
* The Directory with access only to the User associated with this
|
||||
* UserContext.
|
||||
*/
|
||||
private final Directory<User> userDirectory;
|
||||
|
||||
/**
|
||||
* The Directory with access to all connections within the root group
|
||||
* associated with this UserContext.
|
||||
@@ -86,15 +80,14 @@ public class QuickConnectUserContext extends AbstractUserContext {
|
||||
DEFAULT_ROOT_CONNECTION_GROUP
|
||||
);
|
||||
|
||||
// Initialize the user to a SimpleUser with the username, no
|
||||
// preexisting connections, and the single root group.
|
||||
// Initialize the user to a SimpleUser with the provided username,
|
||||
// no connections, and the single root group.
|
||||
this.self = new SimpleUser(username,
|
||||
Collections.<String>emptyList(),
|
||||
Collections.singleton(DEFAULT_ROOT_CONNECTION_GROUP)
|
||||
);
|
||||
|
||||
// Initialize each of the directories associated with the userContext.
|
||||
this.userDirectory = new SimpleDirectory<User>(self);
|
||||
// Initialize the connection directory
|
||||
this.connectionDirectory = new QuickConnectDirectory(this.rootGroup);
|
||||
|
||||
// Set the authProvider to the calling authProvider object.
|
||||
@@ -122,12 +115,6 @@ public class QuickConnectUserContext extends AbstractUserContext {
|
||||
return authProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Directory<User> getUserDirectory()
|
||||
throws GuacamoleException {
|
||||
return userDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionGroup getRootConnectionGroup() throws GuacamoleException {
|
||||
return rootGroup;
|
||||
|
@@ -31,20 +31,20 @@ import org.apache.guacamole.net.auth.ConnectionGroup;
|
||||
import org.apache.guacamole.protocol.GuacamoleClientInformation;
|
||||
|
||||
/**
|
||||
* Provides a very simple, single-level connection group used
|
||||
* for temporarily storing the QuickConnections created by
|
||||
* users.
|
||||
* Provides a simple, single-level connection group used for
|
||||
* temporarily storing the Connection objects created by users.
|
||||
*/
|
||||
public class QuickConnectionGroup extends AbstractConnectionGroup {
|
||||
|
||||
/**
|
||||
* The connection identifiers for this group.
|
||||
* A set that will store the Connection identifiers for this group.
|
||||
*/
|
||||
private Set<String> connectionIdentifiers;
|
||||
private Set<String> connectionIdentifiers =
|
||||
new HashSet<String>(Collections.<String>emptyList());
|
||||
|
||||
/**
|
||||
* Set up a QuickConnectionGroup with a name and identifier, and
|
||||
* an empty set of child connections.
|
||||
* Set up a QuickConnectionGroup with the provided name and
|
||||
* identifier.
|
||||
*
|
||||
* @param name
|
||||
* The name of the QuickConnectionGroup.
|
||||
@@ -58,13 +58,12 @@ public class QuickConnectionGroup extends AbstractConnectionGroup {
|
||||
setIdentifier(identifier);
|
||||
setType(ConnectionGroup.Type.ORGANIZATIONAL);
|
||||
|
||||
this.connectionIdentifiers = new HashSet<String>(Collections.<String>emptyList());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a connection identifier to this connection group, and
|
||||
* return the identifier if the add succeeds, else return null.
|
||||
* return the identifier if the add succeeds, otheriwse
|
||||
* return null.
|
||||
*
|
||||
* @param identifier
|
||||
* The identifier of the connection to add to the group.
|
||||
|
@@ -29,8 +29,8 @@ import org.apache.guacamole.auth.quickconnect.QuickConnectDirectory;
|
||||
import org.apache.guacamole.auth.quickconnect.utility.QCParser;
|
||||
|
||||
/**
|
||||
* A class to create and manage REST endpoints for the
|
||||
* QuickConnect extension.
|
||||
* A class that implements REST endpoints for the QuickConnect
|
||||
* extension.
|
||||
*/
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class QuickConnectREST {
|
||||
@@ -41,31 +41,27 @@ public class QuickConnectREST {
|
||||
private QuickConnectDirectory directory;
|
||||
|
||||
/**
|
||||
* Construct a new QuickConnectREST class, taking in the UserContext
|
||||
* object that calls this constructor.
|
||||
* Construct a new QuickConnectREST class, taking in a
|
||||
* QuickConnectDirectory for use with this class.
|
||||
*
|
||||
* @param directory
|
||||
* The ConnectionDirectory object associated with this REST endpoint
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the UserContext is unavailable or the directory object
|
||||
* cannot be retrieved.
|
||||
* The QuickConnectDirectory object to associate with this
|
||||
* REST endpoint class.
|
||||
*/
|
||||
public QuickConnectREST(QuickConnectDirectory directory)
|
||||
throws GuacamoleException {
|
||||
public QuickConnectREST(QuickConnectDirectory directory) {
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the URI read from the POST input, add the connection
|
||||
* to the directory, and return the ID of the newly-created
|
||||
* to the directory, and return the identifier of the newly-created
|
||||
* connection.
|
||||
*
|
||||
* @param uri
|
||||
* The URI to parse into a connection.
|
||||
*
|
||||
* @return
|
||||
* The ID of the connection in the directory.
|
||||
* The identifier of the connection in the directory.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If an error is encountered parsing the URI.
|
||||
@@ -78,6 +74,5 @@ public class QuickConnectREST {
|
||||
return directory.create(QCParser.getConfiguration(uri));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -34,23 +34,16 @@ import org.apache.guacamole.GuacamoleClientException;
|
||||
import org.apache.guacamole.GuacamoleServerException;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.protocol.GuacamoleConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* A utility class to parse out a URI into the settings necessary
|
||||
* to create and establish a Guacamole connection.
|
||||
* to generate a GuacamoleConfiguration object.
|
||||
*/
|
||||
public class QCParser {
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
private final static Logger logger = LoggerFactory.getLogger(QCParser.class);
|
||||
|
||||
/**
|
||||
* The default protocol to parse to if one is provided in
|
||||
* the incoming URI..
|
||||
* The default protocol to use if one is not provided in
|
||||
* the incoming URI.
|
||||
*/
|
||||
public static final String DEFAULT_URI_PROTOCOL = "ssh";
|
||||
|
||||
@@ -75,8 +68,8 @@ public class QCParser {
|
||||
private static final int PASSWORD_GROUP = 2;
|
||||
|
||||
/**
|
||||
* Parse out a URI string and get a connection from that string,
|
||||
* or an exception if the parsing fails.
|
||||
* Parse out a URI string and get a GuacamoleConfiguration
|
||||
* from that string, or an exception if the parsing fails.
|
||||
*
|
||||
* @param uri
|
||||
* The string form of the URI to be parsed.
|
||||
@@ -99,21 +92,27 @@ public class QCParser {
|
||||
catch (URISyntaxException e) {
|
||||
throw new GuacamoleClientException("Invalid URI Syntax", e);
|
||||
}
|
||||
|
||||
// Break out individual components of the URI.
|
||||
String protocol = qcUri.getScheme();
|
||||
String host = qcUri.getHost();
|
||||
int port = qcUri.getPort();
|
||||
String userInfo = qcUri.getUserInfo();
|
||||
String query = qcUri.getQuery();
|
||||
|
||||
String username = null;
|
||||
String password = null;
|
||||
Map<String, String> queryParams = null;
|
||||
|
||||
// Assign default protocol if one is not found in the URI.
|
||||
if (protocol == null || protocol.isEmpty())
|
||||
protocol = DEFAULT_URI_PROTOCOL;
|
||||
|
||||
// Assign default host if one is not found in the URI.
|
||||
if (host == null || host.isEmpty())
|
||||
host = DEFAULT_URI_HOST;
|
||||
|
||||
// Look for extra query parameters and parse them out.
|
||||
if (query != null && !query.isEmpty()) {
|
||||
try {
|
||||
queryParams = parseQueryString(query);
|
||||
@@ -123,6 +122,7 @@ public class QCParser {
|
||||
}
|
||||
}
|
||||
|
||||
// Look for the username and password and parse them out.
|
||||
if (userInfo != null && !userInfo.isEmpty()) {
|
||||
|
||||
Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
|
||||
@@ -133,6 +133,7 @@ public class QCParser {
|
||||
|
||||
}
|
||||
|
||||
// Generate a new GuacamoleConfiguration and set parameters.
|
||||
GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
|
||||
qcConfig.setProtocol(protocol);
|
||||
qcConfig.setParameter("hostname",host);
|
||||
@@ -159,7 +160,7 @@ public class QCParser {
|
||||
* a map with the parameters.
|
||||
*
|
||||
* @param queryStr
|
||||
* The query string to parse for the values.
|
||||
* The query string to parse for key/value pairs.
|
||||
*
|
||||
* @return
|
||||
* A map with the key/value pairs.
|
||||
@@ -174,7 +175,7 @@ public class QCParser {
|
||||
List<String> paramList = Arrays.asList(queryStr.split("&"));
|
||||
Map<String, String> parameters = new HashMap<String,String>();
|
||||
|
||||
// Split into key/value pairs and decode
|
||||
// Loop through key/value pairs and put them in the Map.
|
||||
for (String param : paramList) {
|
||||
String[] paramArray = param.split("=", 2);
|
||||
parameters.put(URLDecoder.decode(paramArray[0], "UTF-8"),
|
||||
|
Reference in New Issue
Block a user