mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
Ticket #362. Created APIConnectionWrapper and added package info to the java packages.
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Classes related to the authentication aspect of the Guacamole REST API.
|
||||||
|
*/
|
||||||
|
package org.glyptodon.guacamole.net.basic.rest;
|
||||||
|
|
@@ -18,20 +18,19 @@ package org.glyptodon.guacamole.net.basic.rest.connection;
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import org.glyptodon.guacamole.GuacamoleException;
|
import org.glyptodon.guacamole.GuacamoleException;
|
||||||
import org.glyptodon.guacamole.net.GuacamoleSocket;
|
|
||||||
import org.glyptodon.guacamole.net.auth.Connection;
|
import org.glyptodon.guacamole.net.auth.Connection;
|
||||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
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.
|
* A simple connection to expose through the REST endpoints.
|
||||||
*
|
*
|
||||||
* @author James Muehlner
|
* @author James Muehlner
|
||||||
*/
|
*/
|
||||||
public class APIConnection implements Connection {
|
public class APIConnection {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of this connection.
|
* The name of this connection.
|
||||||
@@ -43,15 +42,15 @@ public class APIConnection implements Connection {
|
|||||||
*/
|
*/
|
||||||
private String identifier;
|
private String identifier;
|
||||||
|
|
||||||
/**
|
|
||||||
* The configuration associated with this connection.
|
|
||||||
*/
|
|
||||||
private GuacamoleConfiguration configuration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The history records associated with this connection.
|
* The history records associated with this connection.
|
||||||
*/
|
*/
|
||||||
private List<? extends ConnectionRecord> history;
|
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.
|
* Create an empty APIConnection.
|
||||||
@@ -68,55 +67,61 @@ public class APIConnection implements Connection {
|
|||||||
throws GuacamoleException {
|
throws GuacamoleException {
|
||||||
this.name = connection.getName();
|
this.name = connection.getName();
|
||||||
this.identifier = connection.getIdentifier();
|
this.identifier = connection.getIdentifier();
|
||||||
this.configuration = connection.getConfiguration();
|
|
||||||
this.history = connection.getHistory();
|
this.history = connection.getHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Returns the name of this connection.
|
||||||
|
* @return The name of this connection.
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Set the name of this connection.
|
||||||
|
* @param name The name of this connection.
|
||||||
|
*/
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
|
/**
|
||||||
|
* Returns the unique identifier for this connection.
|
||||||
|
* @return The unique identifier for this connection.
|
||||||
|
*/
|
||||||
public String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
@Override
|
* Sets the unique identifier for this connection.
|
||||||
|
*/
|
||||||
public void setIdentifier(String identifier) {
|
public void setIdentifier(String identifier) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public GuacamoleConfiguration getConfiguration() {
|
* Returns the history records associated with this connection.
|
||||||
return configuration;
|
* @return The history records associated with this connection.
|
||||||
}
|
*/
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setConfiguration(GuacamoleConfiguration configuration) {
|
|
||||||
this.configuration = configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<? extends ConnectionRecord> getHistory() {
|
public List<? extends ConnectionRecord> getHistory() {
|
||||||
return history;
|
return history;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the history records for this connection.
|
* Returns the parameter map for this connection.
|
||||||
* @param history The history records for this connection.
|
* @return The parameter map for this connection.
|
||||||
*/
|
*/
|
||||||
public void setHistory(List<? extends ConnectionRecord> history) {
|
public Map<String, String> getParameters() {
|
||||||
this.history = history;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public GuacamoleSocket connect(GuacamoleClientInformation info) throws GuacamoleException {
|
* Sets the parameter map for this connection.
|
||||||
throw new UnsupportedOperationException("Not supported.");
|
* @param parameters The parameter map for this connection.
|
||||||
|
*/
|
||||||
|
public void setParameters(Map<String, String> parameters) {
|
||||||
|
this.parameters = parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -231,7 +231,7 @@ public class ConnectionRESTService {
|
|||||||
parentConnectionGroup.getConnectionDirectory();
|
parentConnectionGroup.getConnectionDirectory();
|
||||||
|
|
||||||
// Create the connection
|
// Create the connection
|
||||||
connectionDirectory.add(connection);
|
connectionDirectory.add(new APIConnectionWrapper(connection));
|
||||||
|
|
||||||
// Return the new connection identifier
|
// Return the new connection identifier
|
||||||
return connection.getIdentifier();
|
return connection.getIdentifier();
|
||||||
@@ -273,7 +273,7 @@ public class ConnectionRESTService {
|
|||||||
throw new GuacamoleClientException("No Connection with the provided ID.");
|
throw new GuacamoleClientException("No Connection with the provided ID.");
|
||||||
|
|
||||||
// Update the connection
|
// Update the connection
|
||||||
connectionDirectory.update(connection);
|
connectionDirectory.update(new APIConnectionWrapper(connection));
|
||||||
} catch(GuacamoleSecurityException e) {
|
} catch(GuacamoleSecurityException e) {
|
||||||
throw new HTTPException(Status.UNAUTHORIZED, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
throw new HTTPException(Status.UNAUTHORIZED, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
||||||
} catch(GuacamoleClientException e) {
|
} catch(GuacamoleClientException e) {
|
||||||
|
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Classes related to the connection manipulation aspect of the Guacamole REST API.
|
||||||
|
*/
|
||||||
|
package org.glyptodon.guacamole.net.basic.rest.connection;
|
||||||
|
|
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Classes related to the basic Guacamole REST API.
|
||||||
|
*/
|
||||||
|
package org.glyptodon.guacamole.net.basic.rest;
|
||||||
|
|
Reference in New Issue
Block a user