Ticket #362. Created APIConnectionWrapper and added package info to the java packages.

This commit is contained in:
James Muehlner
2013-09-25 22:12:23 -07:00
parent 031d9c9137
commit 08934a4723
6 changed files with 158 additions and 35 deletions

View File

@@ -0,0 +1,6 @@
/**
* Classes related to the authentication aspect of the Guacamole REST API.
*/
package org.glyptodon.guacamole.net.basic.rest;

View File

@@ -18,20 +18,19 @@ package org.glyptodon.guacamole.net.basic.rest.connection;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.net.GuacamoleSocket;
import org.glyptodon.guacamole.net.auth.Connection;
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
/**
* A simple connection to expose through the REST endpoints.
*
* @author James Muehlner
*/
public class APIConnection implements Connection {
public class APIConnection {
/**
* The name of this connection.
@@ -43,15 +42,15 @@ public class APIConnection implements Connection {
*/
private String identifier;
/**
* The configuration associated with this connection.
*/
private GuacamoleConfiguration configuration;
/**
* The history records associated with this connection.
*/
private List<? extends ConnectionRecord> history;
/**
* Map of all associated parameter values, indexed by parameter name.
*/
private Map<String, String> parameters = new HashMap<String, String>();
/**
* Create an empty APIConnection.
@@ -68,55 +67,61 @@ public class APIConnection implements Connection {
throws GuacamoleException {
this.name = connection.getName();
this.identifier = connection.getIdentifier();
this.configuration = connection.getConfiguration();
this.history = connection.getHistory();
}
@Override
/**
* Returns the name of this connection.
* @return The name of this connection.
*/
public String getName() {
return name;
}
@Override
/**
* Set the name of this connection.
* @param name The name of this connection.
*/
public void setName(String name) {
this.name = name;
}
@Override
/**
* Returns the unique identifier for this connection.
* @return The unique identifier for this connection.
*/
public String getIdentifier() {
return identifier;
}
@Override
/**
* Sets the unique identifier for this connection.
*/
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
@Override
public GuacamoleConfiguration getConfiguration() {
return configuration;
}
@Override
public void setConfiguration(GuacamoleConfiguration configuration) {
this.configuration = configuration;
}
@Override
/**
* Returns the history records associated with this connection.
* @return The history records associated with this connection.
*/
public List<? extends ConnectionRecord> getHistory() {
return history;
}
/**
* Set the history records for this connection.
* @param history The history records for this connection.
* Returns the parameter map for this connection.
* @return The parameter map for this connection.
*/
public void setHistory(List<? extends ConnectionRecord> history) {
this.history = history;
public Map<String, String> getParameters() {
return parameters;
}
@Override
public GuacamoleSocket connect(GuacamoleClientInformation info) throws GuacamoleException {
throw new UnsupportedOperationException("Not supported.");
/**
* Sets the parameter map for this connection.
* @param parameters The parameter map for this connection.
*/
public void setParameters(Map<String, String> parameters) {
this.parameters = parameters;
}
}

View File

@@ -0,0 +1,100 @@
package org.glyptodon.guacamole.net.basic.rest.connection;
/*
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.net.GuacamoleSocket;
import org.glyptodon.guacamole.net.auth.Connection;
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
/**
* A wrapper to make an APIConnection look like a Connection. Useful where a
* org.glyptodon.guacamole.net.auth.Connection is required.
*
* @author James Muehlner
*/
public class APIConnectionWrapper implements Connection {
private final APIConnection apiConnection;
public APIConnectionWrapper(APIConnection apiConnection) {
this.apiConnection = apiConnection;
}
@Override
public String getName() {
return apiConnection.getName();
}
@Override
public void setName(String name) {
apiConnection.setName(name);
}
@Override
public String getIdentifier() {
return apiConnection.getIdentifier();
}
@Override
public void setIdentifier(String identifier) {
apiConnection.setIdentifier(identifier);
}
@Override
public GuacamoleConfiguration getConfiguration() {
// Create the GuacamoleConfiguration from the parameter map
GuacamoleConfiguration configuration = new GuacamoleConfiguration();
Map<String, String> parameters = apiConnection.getParameters();
for(String key : parameters.keySet())
configuration.setParameter(key, parameters.get(key));
return configuration;
}
@Override
public void setConfiguration(GuacamoleConfiguration config) {
// Create a parameter map from the GuacamoleConfiguration
Map<String, String> newParameters = new HashMap<String, String>();
for(String key : config.getParameterNames())
newParameters.put(key, config.getParameter(key));
apiConnection.setParameters(newParameters);
}
@Override
public GuacamoleSocket connect(GuacamoleClientInformation info) throws GuacamoleException {
throw new UnsupportedOperationException("Operation not supported.");
}
@Override
public List<? extends ConnectionRecord> getHistory() throws GuacamoleException {
return apiConnection.getHistory();
}
}

View File

@@ -231,7 +231,7 @@ public class ConnectionRESTService {
parentConnectionGroup.getConnectionDirectory();
// Create the connection
connectionDirectory.add(connection);
connectionDirectory.add(new APIConnectionWrapper(connection));
// Return the new connection identifier
return connection.getIdentifier();
@@ -273,7 +273,7 @@ public class ConnectionRESTService {
throw new GuacamoleClientException("No Connection with the provided ID.");
// Update the connection
connectionDirectory.update(connection);
connectionDirectory.update(new APIConnectionWrapper(connection));
} catch(GuacamoleSecurityException e) {
throw new HTTPException(Status.UNAUTHORIZED, e.getMessage() != null ? e.getMessage() : "Permission denied.");
} catch(GuacamoleClientException e) {

View File

@@ -0,0 +1,6 @@
/**
* Classes related to the connection manipulation aspect of the Guacamole REST API.
*/
package org.glyptodon.guacamole.net.basic.rest.connection;

View File

@@ -0,0 +1,6 @@
/**
* Classes related to the basic Guacamole REST API.
*/
package org.glyptodon.guacamole.net.basic.rest;