GUACAMOLE-38: Code cleanup; style, and grammar tweaks.

This commit is contained in:
Nick Couchman
2018-04-20 21:21:15 -04:00
parent aabc871d7d
commit cfd1673791
6 changed files with 56 additions and 75 deletions

View File

@@ -25,8 +25,8 @@ import org.apache.guacamole.net.auth.AbstractAuthenticationProvider;
import org.apache.guacamole.net.auth.UserContext; import org.apache.guacamole.net.auth.UserContext;
/** /**
* Class providing the necessary hooks into the Guacamole Client authentication * This class provides the necessary hooks into the Guacamole Client authentication
* process so that the QuickConnect functionality can be initialized and be used * process so that the QuickConnect functionality can be initialized and used
* throughout the web client. * throughout the web client.
*/ */
public class QuickConnectAuthenticationProvider extends AbstractAuthenticationProvider { public class QuickConnectAuthenticationProvider extends AbstractAuthenticationProvider {

View File

@@ -31,7 +31,7 @@ import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.protocol.GuacamoleConfiguration; import org.apache.guacamole.protocol.GuacamoleConfiguration;
/** /**
* Implementation of the Connection Directory, stored * Implementation of a directory to stored Connection objects
* completely in-memory. * completely in-memory.
*/ */
public class QuickConnectDirectory extends SimpleDirectory<Connection> { public class QuickConnectDirectory extends SimpleDirectory<Connection> {
@@ -58,14 +58,12 @@ public class QuickConnectDirectory extends SimpleDirectory<Connection> {
private AtomicInteger connectionId; private AtomicInteger connectionId;
/** /**
* Creates a new QuickConnectDirectory which provides access to the * Creates a new QuickConnectDirectory with the default
* connections contained within the given Map. * 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 * @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) { public QuickConnectDirectory(ConnectionGroup rootGroup) {
this.rootGroup = (QuickConnectionGroup)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 * @return
* An Integer representing the next available connection * An int representing the next available connection
* ID to get used when adding connections. * identifier to be used when adding connections.
*/ */
private int getNextConnectionID() { private int getNextConnectionID() {
return connectionId.getAndIncrement(); return connectionId.getAndIncrement();
@@ -90,9 +89,9 @@ public class QuickConnectDirectory extends SimpleDirectory<Connection> {
} }
/** /**
* Create a SimpleConnection object from a GuacamoleConfiguration * Create a SimpleConnection object from a GuacamoleConfiguration,
* and get an ID and place it on the tree, returning the new * obtain an identifier, and place it on the tree, returning the
* connection identifier value. * identifier value of the new connection.
* *
* @param config * @param config
* The GuacamoleConfiguration to use to create the * The GuacamoleConfiguration to use to create the
@@ -106,17 +105,17 @@ public class QuickConnectDirectory extends SimpleDirectory<Connection> {
*/ */
public String create(GuacamoleConfiguration config) throws GuacamoleException { public String create(GuacamoleConfiguration config) throws GuacamoleException {
// Get the next connection ID // Get the next connection identifier.
String connectionId = Integer.toString(getNextConnectionID()); String connectionId = Integer.toString(getNextConnectionID());
// Generate a name for the configuration // Generate a name for the configuration.
String name = QCParser.getName(config); 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 connection = new SimpleConnection(name, connectionId, config);
connection.setParentIdentifier(ROOT_IDENTIFIER); connection.setParentIdentifier(ROOT_IDENTIFIER);
// Place the object in directory // Place the object in this directory.
add(connection); add(connection);
// Add connection to the tree. // Add connection to the tree.

View File

@@ -32,8 +32,8 @@ import org.apache.guacamole.net.auth.simple.SimpleUser;
/** /**
* 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, used for storing connections the user has created
* created using the QuickConnect bar in the webapp. * with the QuickConnect bar in the webapp.
*/ */
public class QuickConnectUserContext extends AbstractUserContext { public class QuickConnectUserContext extends AbstractUserContext {
@@ -48,12 +48,6 @@ public class QuickConnectUserContext extends AbstractUserContext {
*/ */
private final User self; 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 * The Directory with access to all connections within the root group
* associated with this UserContext. * associated with this UserContext.
@@ -86,15 +80,14 @@ public class QuickConnectUserContext extends AbstractUserContext {
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 provided username,
// preexisting connections, and the single root group. // no connections, and the single root group.
this.self = new SimpleUser(username, this.self = new SimpleUser(username,
Collections.<String>emptyList(), Collections.<String>emptyList(),
Collections.singleton(DEFAULT_ROOT_CONNECTION_GROUP) Collections.singleton(DEFAULT_ROOT_CONNECTION_GROUP)
); );
// Initialize each of the directories associated with the userContext. // Initialize the connection directory
this.userDirectory = new SimpleDirectory<User>(self);
this.connectionDirectory = new QuickConnectDirectory(this.rootGroup); this.connectionDirectory = new QuickConnectDirectory(this.rootGroup);
// Set the authProvider to the calling authProvider object. // Set the authProvider to the calling authProvider object.
@@ -122,12 +115,6 @@ public class QuickConnectUserContext extends AbstractUserContext {
return authProvider; return authProvider;
} }
@Override
public Directory<User> getUserDirectory()
throws GuacamoleException {
return userDirectory;
}
@Override @Override
public ConnectionGroup getRootConnectionGroup() throws GuacamoleException { public ConnectionGroup getRootConnectionGroup() throws GuacamoleException {
return rootGroup; return rootGroup;

View File

@@ -31,20 +31,20 @@ import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.protocol.GuacamoleClientInformation; import org.apache.guacamole.protocol.GuacamoleClientInformation;
/** /**
* Provides a very simple, single-level connection group used * Provides a simple, single-level connection group used for
* for temporarily storing the QuickConnections created by * temporarily storing the Connection objects created by users.
* users.
*/ */
public class QuickConnectionGroup extends AbstractConnectionGroup { 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 * Set up a QuickConnectionGroup with the provided name and
* an empty set of child connections. * identifier.
* *
* @param name * @param name
* The name of the QuickConnectionGroup. * The name of the QuickConnectionGroup.
@@ -58,13 +58,12 @@ public class QuickConnectionGroup extends AbstractConnectionGroup {
setIdentifier(identifier); setIdentifier(identifier);
setType(ConnectionGroup.Type.ORGANIZATIONAL); setType(ConnectionGroup.Type.ORGANIZATIONAL);
this.connectionIdentifiers = new HashSet<String>(Collections.<String>emptyList());
} }
/** /**
* Add a connection identifier to this connection group, and * 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 * @param identifier
* The identifier of the connection to add to the group. * The identifier of the connection to add to the group.

View File

@@ -29,8 +29,8 @@ import org.apache.guacamole.auth.quickconnect.QuickConnectDirectory;
import org.apache.guacamole.auth.quickconnect.utility.QCParser; import org.apache.guacamole.auth.quickconnect.utility.QCParser;
/** /**
* A class to create and manage REST endpoints for the * A class that implements REST endpoints for the QuickConnect
* QuickConnect extension. * extension.
*/ */
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public class QuickConnectREST { public class QuickConnectREST {
@@ -41,31 +41,27 @@ public class QuickConnectREST {
private QuickConnectDirectory directory; private QuickConnectDirectory directory;
/** /**
* Construct a new QuickConnectREST class, taking in the UserContext * Construct a new QuickConnectREST class, taking in a
* object that calls this constructor. * QuickConnectDirectory for use with this class.
* *
* @param directory * @param directory
* The ConnectionDirectory object associated with this REST endpoint * The QuickConnectDirectory object to associate with this
* * REST endpoint class.
* @throws GuacamoleException
* If the UserContext is unavailable or the directory object
* cannot be retrieved.
*/ */
public QuickConnectREST(QuickConnectDirectory directory) public QuickConnectREST(QuickConnectDirectory directory) {
throws GuacamoleException {
this.directory = directory; this.directory = directory;
} }
/** /**
* Parse the URI read from the POST input, add the connection * 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. * connection.
* *
* @param uri * @param uri
* The URI to parse into a connection. * The URI to parse into a connection.
* *
* @return * @return
* The ID of the connection in the directory. * The identifier of the connection in the directory.
* *
* @throws GuacamoleException * @throws GuacamoleException
* If an error is encountered parsing the URI. * If an error is encountered parsing the URI.
@@ -78,6 +74,5 @@ public class QuickConnectREST {
return directory.create(QCParser.getConfiguration(uri)); return directory.create(QCParser.getConfiguration(uri));
} }
} }

View File

@@ -34,23 +34,16 @@ import org.apache.guacamole.GuacamoleClientException;
import org.apache.guacamole.GuacamoleServerException; import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.protocol.GuacamoleConfiguration; 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 * 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 { public class QCParser {
/** /**
* Logger for this class. * The default protocol to use if one is not provided in
*/ * the incoming URI.
private final static Logger logger = LoggerFactory.getLogger(QCParser.class);
/**
* The default protocol to parse to if one is provided in
* the incoming URI..
*/ */
public static final String DEFAULT_URI_PROTOCOL = "ssh"; public static final String DEFAULT_URI_PROTOCOL = "ssh";
@@ -75,8 +68,8 @@ public class QCParser {
private static final int PASSWORD_GROUP = 2; private static final int PASSWORD_GROUP = 2;
/** /**
* Parse out a URI string and get a connection from that string, * Parse out a URI string and get a GuacamoleConfiguration
* or an exception if the parsing fails. * from that string, or an exception if the parsing fails.
* *
* @param uri * @param uri
* The string form of the URI to be parsed. * The string form of the URI to be parsed.
@@ -99,21 +92,27 @@ public class QCParser {
catch (URISyntaxException e) { catch (URISyntaxException e) {
throw new GuacamoleClientException("Invalid URI Syntax", e); throw new GuacamoleClientException("Invalid URI Syntax", e);
} }
// Break out individual components of the URI.
String protocol = qcUri.getScheme(); String protocol = qcUri.getScheme();
String host = qcUri.getHost(); String host = qcUri.getHost();
int port = qcUri.getPort(); int port = qcUri.getPort();
String userInfo = qcUri.getUserInfo(); String userInfo = qcUri.getUserInfo();
String query = qcUri.getQuery(); String query = qcUri.getQuery();
String username = null; String username = null;
String password = null; String password = null;
Map<String, String> queryParams = null; Map<String, String> queryParams = null;
// Assign default protocol if one is not found in the URI.
if (protocol == null || protocol.isEmpty()) if (protocol == null || protocol.isEmpty())
protocol = DEFAULT_URI_PROTOCOL; protocol = DEFAULT_URI_PROTOCOL;
// Assign default host if one is not found in the URI.
if (host == null || host.isEmpty()) if (host == null || host.isEmpty())
host = DEFAULT_URI_HOST; host = DEFAULT_URI_HOST;
// Look for extra query parameters and parse them out.
if (query != null && !query.isEmpty()) { if (query != null && !query.isEmpty()) {
try { try {
queryParams = parseQueryString(query); 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()) { if (userInfo != null && !userInfo.isEmpty()) {
Matcher userinfoMatcher = userinfoPattern.matcher(userInfo); Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
@@ -133,6 +133,7 @@ public class QCParser {
} }
// Generate a new GuacamoleConfiguration and set parameters.
GuacamoleConfiguration qcConfig = new GuacamoleConfiguration(); GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
qcConfig.setProtocol(protocol); qcConfig.setProtocol(protocol);
qcConfig.setParameter("hostname",host); qcConfig.setParameter("hostname",host);
@@ -159,7 +160,7 @@ public class QCParser {
* a map with the parameters. * a map with the parameters.
* *
* @param queryStr * @param queryStr
* The query string to parse for the values. * The query string to parse for key/value pairs.
* *
* @return * @return
* A map with the key/value pairs. * A map with the key/value pairs.
@@ -174,7 +175,7 @@ public class QCParser {
List<String> paramList = Arrays.asList(queryStr.split("&")); List<String> paramList = Arrays.asList(queryStr.split("&"));
Map<String, String> parameters = new HashMap<String,String>(); 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) { for (String param : paramList) {
String[] paramArray = param.split("=", 2); String[] paramArray = param.split("=", 2);
parameters.put(URLDecoder.decode(paramArray[0], "UTF-8"), parameters.put(URLDecoder.decode(paramArray[0], "UTF-8"),