mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-08 06:01:22 +00:00
Ticket #362: Moved all HTTP Exception handling into AOP magic.
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
package org.glyptodon.guacamole.net.basic.rest;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||||
|
import org.glyptodon.guacamole.GuacamoleException;
|
||||||
|
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method interceptor to wrap some custom exception handling around methods
|
||||||
|
* that expose AuthenticationProvider functionality through the REST interface.
|
||||||
|
* Translates various types of GuacamoleExceptions into appropriate HTTP responses.
|
||||||
|
*
|
||||||
|
* @author James Muehlner
|
||||||
|
*/
|
||||||
|
public class AuthProviderRESTExceptionWrapper implements MethodInterceptor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||||
|
// Get the logger for the intercepted class
|
||||||
|
Logger logger = LoggerFactory.getLogger(invocation.getMethod().getDeclaringClass());
|
||||||
|
|
||||||
|
try {
|
||||||
|
return invocation.proceed();
|
||||||
|
} catch(GuacamoleSecurityException e) {
|
||||||
|
throw new HTTPException(Response.Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
||||||
|
} catch(GuacamoleClientException e) {
|
||||||
|
throw new HTTPException(Response.Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
||||||
|
} catch(GuacamoleException e) {
|
||||||
|
logger.error("Unexpected GuacamoleException caught while executing " + invocation.getMethod().getName() + ".", e);
|
||||||
|
throw new HTTPException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,34 @@
|
|||||||
|
package org.glyptodon.guacamole.net.basic.rest;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks that a method exposes functionality from the Guacamole AuthenticationProvider
|
||||||
|
* using a REST interface.
|
||||||
|
*
|
||||||
|
* @author James Muehlner
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.METHOD})
|
||||||
|
public @interface AuthProviderRESTExposure {}
|
@@ -19,6 +19,7 @@ package org.glyptodon.guacamole.net.basic.rest;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.matcher.Matchers;
|
||||||
import org.glyptodon.guacamole.GuacamoleException;
|
import org.glyptodon.guacamole.GuacamoleException;
|
||||||
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
|
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
|
||||||
import org.glyptodon.guacamole.net.basic.properties.BasicGuacamoleProperties;
|
import org.glyptodon.guacamole.net.basic.properties.BasicGuacamoleProperties;
|
||||||
@@ -74,6 +75,8 @@ public class RESTModule extends AbstractModule {
|
|||||||
bind(AuthenticationService.class);
|
bind(AuthenticationService.class);
|
||||||
|
|
||||||
bind(AuthTokenGenerator.class).to(SecureRandomAuthTokenGenerator.class);
|
bind(AuthTokenGenerator.class).to(SecureRandomAuthTokenGenerator.class);
|
||||||
|
|
||||||
|
bindInterceptor(Matchers.any(), Matchers.annotatedWith(AuthProviderRESTExposure.class), new AuthProviderRESTExceptionWrapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@ import org.glyptodon.guacamole.GuacamoleException;
|
|||||||
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
|
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
|
||||||
import org.glyptodon.guacamole.net.auth.Credentials;
|
import org.glyptodon.guacamole.net.auth.Credentials;
|
||||||
import org.glyptodon.guacamole.net.auth.UserContext;
|
import org.glyptodon.guacamole.net.auth.UserContext;
|
||||||
|
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -78,6 +79,7 @@ public class LoginRESTService {
|
|||||||
* @return The auth token for the newly logged-in user.
|
* @return The auth token for the newly logged-in user.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public APIAuthToken login(@QueryParam("username") String username,
|
public APIAuthToken login(@QueryParam("username") String username,
|
||||||
@QueryParam("password") String password) {
|
@QueryParam("password") String password) {
|
||||||
|
|
||||||
|
@@ -39,6 +39,7 @@ import org.glyptodon.guacamole.net.auth.Connection;
|
|||||||
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
||||||
import org.glyptodon.guacamole.net.auth.Directory;
|
import org.glyptodon.guacamole.net.auth.Directory;
|
||||||
import org.glyptodon.guacamole.net.auth.UserContext;
|
import org.glyptodon.guacamole.net.auth.UserContext;
|
||||||
|
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -80,38 +81,32 @@ public class ConnectionRESTService {
|
|||||||
* @param parentID The ID of the ConnectionGroup the connections
|
* @param parentID The ID of the ConnectionGroup the connections
|
||||||
* belong to. If null, the root connection group will be used.
|
* belong to. If null, the root connection group will be used.
|
||||||
* @return The connection list.
|
* @return The connection list.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while listing connections.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
public List<APIConnection> getConnections(@QueryParam("token") String authToken, @QueryParam("parentID") String parentID) {
|
@AuthProviderRESTExposure
|
||||||
|
public List<APIConnection> getConnections(@QueryParam("token") String authToken, @QueryParam("parentID") String parentID)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// If the parent connection group is passed in, try to find it.
|
||||||
// If the parent connection group is passed in, try to find it.
|
ConnectionGroup parentConnectionGroup;
|
||||||
ConnectionGroup parentConnectionGroup;
|
if(parentID == null)
|
||||||
if(parentID == null)
|
parentConnectionGroup = userContext.getRootConnectionGroup();
|
||||||
parentConnectionGroup = userContext.getRootConnectionGroup();
|
else {
|
||||||
else {
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
||||||
parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(parentConnectionGroup == null)
|
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
|
||||||
|
|
||||||
Directory<String, Connection> connectionDirectory =
|
|
||||||
parentConnectionGroup.getConnectionDirectory();
|
|
||||||
|
|
||||||
// Return the converted connection directory
|
|
||||||
return connectionService.convertConnectionList(connectionDirectory);
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while listing connections.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(parentConnectionGroup == null)
|
||||||
|
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
||||||
|
|
||||||
|
Directory<String, Connection> connectionDirectory =
|
||||||
|
parentConnectionGroup.getConnectionDirectory();
|
||||||
|
|
||||||
|
// Return the converted connection directory
|
||||||
|
return connectionService.convertConnectionList(connectionDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,34 +116,27 @@ public class ConnectionRESTService {
|
|||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param connectionID The ID of the Connection..
|
* @param connectionID The ID of the Connection..
|
||||||
* @return The connection.
|
* @return The connection.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while retrieving the connection.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/{connectionID}")
|
@Path("/{connectionID}")
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public APIConnection getConnection(@QueryParam("token") String authToken,
|
public APIConnection getConnection(@QueryParam("token") String authToken,
|
||||||
@PathParam("connectionID") String connectionID) {
|
@PathParam("connectionID") String connectionID) throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the connection directory
|
||||||
// Get the connection directory
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, Connection> connectionDirectory =
|
||||||
Directory<String, Connection> connectionDirectory =
|
rootGroup.getConnectionDirectory();
|
||||||
rootGroup.getConnectionDirectory();
|
|
||||||
|
// Get the connection
|
||||||
// Get the connection
|
Connection connection = connectionDirectory.get(connectionID);
|
||||||
Connection connection = connectionDirectory.get(connectionID);
|
|
||||||
|
if(connection == null)
|
||||||
if(connection == null)
|
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID.");
|
|
||||||
|
return new APIConnection(connection);
|
||||||
return new APIConnection(connection);
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while getting connection.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -157,32 +145,26 @@ public class ConnectionRESTService {
|
|||||||
* @param authToken The authentication token that is used to authenticate
|
* @param authToken The authentication token that is used to authenticate
|
||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param connectionID The ID of the Connection to delete.
|
* @param connectionID The ID of the Connection to delete.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while deleting the connection.
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{connectionID}")
|
@Path("/{connectionID}")
|
||||||
public void deleteConnection(@QueryParam("token") String authToken, @PathParam("connectionID") String connectionID) {
|
@AuthProviderRESTExposure
|
||||||
|
public void deleteConnection(@QueryParam("token") String authToken, @PathParam("connectionID") String connectionID)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the connection directory
|
||||||
// Get the connection directory
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, Connection> connectionDirectory =
|
||||||
Directory<String, Connection> connectionDirectory =
|
rootGroup.getConnectionDirectory();
|
||||||
rootGroup.getConnectionDirectory();
|
|
||||||
|
// Make sure the connection is there before trying to delete
|
||||||
// Make sure the connection is there before trying to delete
|
if(connectionDirectory.get(connectionID) == null)
|
||||||
if(connectionDirectory.get(connectionID) == null)
|
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID.");
|
|
||||||
|
// Delete the connection
|
||||||
// Delete the connection
|
connectionDirectory.remove(connectionID);
|
||||||
connectionDirectory.remove(connectionID);
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while deleting connection.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -197,45 +179,38 @@ public class ConnectionRESTService {
|
|||||||
* belong to. If null, the root connection group will be used.
|
* belong to. If null, the root connection group will be used.
|
||||||
* @param connection The connection to create.
|
* @param connection The connection to create.
|
||||||
* @return The identifier of the new connection.
|
* @return The identifier of the new connection.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while creating the connection.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public String createConnection(@QueryParam("token") String authToken,
|
public String createConnection(@QueryParam("token") String authToken,
|
||||||
@QueryParam("parentID") String parentID, APIConnection connection) {
|
@QueryParam("parentID") String parentID, APIConnection connection) throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
if(connection == null)
|
||||||
if(connection == null)
|
throw new GuacamoleClientException("A connection is required for this request.");
|
||||||
throw new GuacamoleClientException("A connection is required for this request.");
|
|
||||||
|
// If the parent connection group is passed in, try to find it.
|
||||||
// If the parent connection group is passed in, try to find it.
|
ConnectionGroup parentConnectionGroup;
|
||||||
ConnectionGroup parentConnectionGroup;
|
if(parentID == null)
|
||||||
if(parentID == null)
|
parentConnectionGroup = userContext.getRootConnectionGroup();
|
||||||
parentConnectionGroup = userContext.getRootConnectionGroup();
|
else {
|
||||||
else {
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
||||||
parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(parentConnectionGroup == null)
|
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
|
||||||
|
|
||||||
Directory<String, Connection> connectionDirectory =
|
|
||||||
parentConnectionGroup.getConnectionDirectory();
|
|
||||||
|
|
||||||
// Create the connection
|
|
||||||
connectionDirectory.add(new APIConnectionWrapper(connection));
|
|
||||||
|
|
||||||
// Return the new connection identifier
|
|
||||||
return connection.getIdentifier();
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while creating connection.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(parentConnectionGroup == null)
|
||||||
|
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
||||||
|
|
||||||
|
Directory<String, Connection> connectionDirectory =
|
||||||
|
parentConnectionGroup.getConnectionDirectory();
|
||||||
|
|
||||||
|
// Create the connection
|
||||||
|
connectionDirectory.add(new APIConnectionWrapper(connection));
|
||||||
|
|
||||||
|
// Return the new connection identifier
|
||||||
|
return connection.getIdentifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -245,36 +220,29 @@ public class ConnectionRESTService {
|
|||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param connectionID The ID of the Connection to move.
|
* @param connectionID The ID of the Connection to move.
|
||||||
* @param connection The connection to update.
|
* @param connection The connection to update.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while updating the connection.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/{connectionID}")
|
@Path("/{connectionID}")
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public void updateConnection(@QueryParam("token") String authToken,
|
public void updateConnection(@QueryParam("token") String authToken,
|
||||||
@PathParam("connectionID") String connectionID, APIConnection connection) {
|
@PathParam("connectionID") String connectionID, APIConnection connection) throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
if(connection == null)
|
||||||
if(connection == null)
|
throw new GuacamoleClientException("A connection is required for this request.");
|
||||||
throw new GuacamoleClientException("A connection is required for this request.");
|
|
||||||
|
// Get the connection directory
|
||||||
// Get the connection directory
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, Connection> connectionDirectory =
|
||||||
Directory<String, Connection> connectionDirectory =
|
rootGroup.getConnectionDirectory();
|
||||||
rootGroup.getConnectionDirectory();
|
|
||||||
|
// Make sure the connection is there before trying to update
|
||||||
// Make sure the connection is there before trying to update
|
if(connectionDirectory.get(connectionID) == null)
|
||||||
if(connectionDirectory.get(connectionID) == null)
|
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID.");
|
|
||||||
|
// Update the connection
|
||||||
// Update the connection
|
connectionDirectory.update(new APIConnectionWrapper(connection));
|
||||||
connectionDirectory.update(new APIConnectionWrapper(connection));
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught updating connection.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -283,38 +251,31 @@ public class ConnectionRESTService {
|
|||||||
* @param authToken The authentication token that is used to authenticate
|
* @param authToken The authentication token that is used to authenticate
|
||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param connectionID The ID of the Connection to move.
|
* @param connectionID The ID of the Connection to move.
|
||||||
* @param parentID The ID of the ConnectionGroup the connections
|
* @param parentID The ID of the ConnectionGroup the connection is to be moved to.
|
||||||
* belong to. If null, the root connection group will be used.
|
* @throws GuacamoleException If a problem is encountered while moving the connection.
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{connectionID}")
|
@Path("/{connectionID}")
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public void moveConnection(@QueryParam("token") String authToken,
|
public void moveConnection(@QueryParam("token") String authToken,
|
||||||
@PathParam("connectionID") String connectionID, @QueryParam("parentID") String parentID) {
|
@PathParam("connectionID") String connectionID, @QueryParam("parentID") String parentID)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the connection directory
|
||||||
// Get the connection directory
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, Connection> connectionDirectory =
|
||||||
Directory<String, Connection> connectionDirectory =
|
rootGroup.getConnectionDirectory();
|
||||||
rootGroup.getConnectionDirectory();
|
|
||||||
|
// Find the new parent connection group
|
||||||
// Find the new parent connection group
|
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
ConnectionGroup parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
||||||
ConnectionGroup parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
|
||||||
|
if(parentConnectionGroup == null)
|
||||||
if(parentConnectionGroup == null)
|
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
|
||||||
|
// Move the connection
|
||||||
// Move the connection
|
connectionDirectory.move(connectionID, parentConnectionGroup.getConnectionDirectory());
|
||||||
connectionDirectory.move(connectionID, parentConnectionGroup.getConnectionDirectory());
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught moving connection.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -38,6 +38,7 @@ import org.glyptodon.guacamole.GuacamoleSecurityException;
|
|||||||
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
||||||
import org.glyptodon.guacamole.net.auth.Directory;
|
import org.glyptodon.guacamole.net.auth.Directory;
|
||||||
import org.glyptodon.guacamole.net.auth.UserContext;
|
import org.glyptodon.guacamole.net.auth.UserContext;
|
||||||
|
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -79,38 +80,32 @@ public class ConnectionGroupRESTService {
|
|||||||
* @param parentID The ID of the ConnectionGroup the connection groups
|
* @param parentID The ID of the ConnectionGroup the connection groups
|
||||||
* belong to. If null, the root connection group will be used.
|
* belong to. If null, the root connection group will be used.
|
||||||
* @return The connection list.
|
* @return The connection list.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while listing connection groups.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
public List<APIConnectionGroup> getConnectionGroups(@QueryParam("token") String authToken, @QueryParam("parentID") String parentID) {
|
@AuthProviderRESTExposure
|
||||||
|
public List<APIConnectionGroup> getConnectionGroups(@QueryParam("token") String authToken, @QueryParam("parentID") String parentID)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// If the parent connection group is passed in, try to find it.
|
||||||
// If the parent connection group is passed in, try to find it.
|
ConnectionGroup parentConnectionGroup;
|
||||||
ConnectionGroup parentConnectionGroup;
|
if(parentID == null)
|
||||||
if(parentID == null)
|
parentConnectionGroup = userContext.getRootConnectionGroup();
|
||||||
parentConnectionGroup = userContext.getRootConnectionGroup();
|
else {
|
||||||
else {
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
||||||
parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(parentConnectionGroup == null)
|
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
|
||||||
|
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
|
||||||
parentConnectionGroup.getConnectionGroupDirectory();
|
|
||||||
|
|
||||||
// return the converted connection group list
|
|
||||||
return connectionGroupService.convertConnectionGroupList(connectionGroupDirectory);
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while listing connection groups.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(parentConnectionGroup == null)
|
||||||
|
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
||||||
|
|
||||||
|
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
||||||
|
parentConnectionGroup.getConnectionGroupDirectory();
|
||||||
|
|
||||||
|
// return the converted connection group list
|
||||||
|
return connectionGroupService.convertConnectionGroupList(connectionGroupDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,35 +115,28 @@ public class ConnectionGroupRESTService {
|
|||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param connectionGroupID The ID of the ConnectionGroup.
|
* @param connectionGroupID The ID of the ConnectionGroup.
|
||||||
* @return The connection group.
|
* @return The connection group.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while retrieving the connection group.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/{connectionGroupID}")
|
@Path("/{connectionGroupID}")
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public APIConnectionGroup getConnectionGroup(@QueryParam("token") String authToken,
|
public APIConnectionGroup getConnectionGroup(@QueryParam("token") String authToken,
|
||||||
@PathParam("connectionGroupID") String connectionGroupID) {
|
@PathParam("connectionGroupID") String connectionGroupID) throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the connection group directory
|
||||||
// Get the connection group directory
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
rootGroup.getConnectionGroupDirectory();
|
||||||
rootGroup.getConnectionGroupDirectory();
|
|
||||||
|
// Get the connection group
|
||||||
// Get the connection group
|
ConnectionGroup connectionGroup = connectionGroupDirectory.get(connectionGroupID);
|
||||||
ConnectionGroup connectionGroup = connectionGroupDirectory.get(connectionGroupID);
|
|
||||||
|
if(connectionGroup == null)
|
||||||
if(connectionGroup == null)
|
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided ID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided ID.");
|
|
||||||
|
// Return the connectiion group
|
||||||
// Return the connectiion group
|
return new APIConnectionGroup(connectionGroup);
|
||||||
return new APIConnectionGroup(connectionGroup);
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while getting connection group.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -157,32 +145,26 @@ public class ConnectionGroupRESTService {
|
|||||||
* @param authToken The authentication token that is used to authenticate
|
* @param authToken The authentication token that is used to authenticate
|
||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param connectionGroupID The ID of the ConnectionGroup to delete.
|
* @param connectionGroupID The ID of the ConnectionGroup to delete.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while deleting the connection group.
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{connectionGroupID}")
|
@Path("/{connectionGroupID}")
|
||||||
public void deleteConnectionGroup(@QueryParam("token") String authToken, @PathParam("connectionGroupID") String connectionGroupID) {
|
@AuthProviderRESTExposure
|
||||||
|
public void deleteConnectionGroup(@QueryParam("token") String authToken,
|
||||||
|
@PathParam("connectionGroupID") String connectionGroupID) throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the connection group directory
|
||||||
// Get the connection group directory
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
rootGroup.getConnectionGroupDirectory();
|
||||||
rootGroup.getConnectionGroupDirectory();
|
|
||||||
|
// Make sure the connection is there before trying to delete
|
||||||
// Make sure the connection is there before trying to delete
|
if(connectionGroupDirectory.get(connectionGroupID) == null)
|
||||||
if(connectionGroupDirectory.get(connectionGroupID) == null)
|
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided ID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided ID.");
|
|
||||||
|
// Delete the connection group
|
||||||
// Delete the connection group
|
connectionGroupDirectory.remove(connectionGroupID);
|
||||||
connectionGroupDirectory.remove(connectionGroupID);
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while deleting connection group.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -197,45 +179,38 @@ public class ConnectionGroupRESTService {
|
|||||||
* belong to. If null, the root connection group will be used.
|
* belong to. If null, the root connection group will be used.
|
||||||
* @param connection The connection group to create.
|
* @param connection The connection group to create.
|
||||||
* @return The identifier of the new connection group.
|
* @return The identifier of the new connection group.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while creating the connection group.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public String createConnectionGroup(@QueryParam("token") String authToken,
|
public String createConnectionGroup(@QueryParam("token") String authToken,
|
||||||
@QueryParam("parentID") String parentID, APIConnectionGroup connectionGroup) {
|
@QueryParam("parentID") String parentID, APIConnectionGroup connectionGroup) throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
if(connectionGroup == null)
|
||||||
if(connectionGroup == null)
|
throw new GuacamoleClientException("A connection group is required for this request.");
|
||||||
throw new GuacamoleClientException("A connection group is required for this request.");
|
|
||||||
|
// If the parent connection group is passed in, try to find it.
|
||||||
// If the parent connection group is passed in, try to find it.
|
ConnectionGroup parentConnectionGroup;
|
||||||
ConnectionGroup parentConnectionGroup;
|
if(parentID == null)
|
||||||
if(parentID == null)
|
parentConnectionGroup = userContext.getRootConnectionGroup();
|
||||||
parentConnectionGroup = userContext.getRootConnectionGroup();
|
else {
|
||||||
else {
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
||||||
parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(parentConnectionGroup == null)
|
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
|
||||||
|
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
|
||||||
parentConnectionGroup.getConnectionGroupDirectory();
|
|
||||||
|
|
||||||
// Create the connection group
|
|
||||||
connectionGroupDirectory.add(new APIConnectionGroupWrapper(connectionGroup));
|
|
||||||
|
|
||||||
// Return the new connection group identifier
|
|
||||||
return connectionGroup.getIdentifier();
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while creating connection group.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(parentConnectionGroup == null)
|
||||||
|
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
||||||
|
|
||||||
|
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
||||||
|
parentConnectionGroup.getConnectionGroupDirectory();
|
||||||
|
|
||||||
|
// Create the connection group
|
||||||
|
connectionGroupDirectory.add(new APIConnectionGroupWrapper(connectionGroup));
|
||||||
|
|
||||||
|
// Return the new connection group identifier
|
||||||
|
return connectionGroup.getIdentifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -245,36 +220,30 @@ public class ConnectionGroupRESTService {
|
|||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param connectionID The ID of the ConnectionGroup to update.
|
* @param connectionID The ID of the ConnectionGroup to update.
|
||||||
* @param connection The connection group to update.
|
* @param connection The connection group to update.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while updating the connection group.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/{connectionGroupID}")
|
@Path("/{connectionGroupID}")
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public void updateConnectionGroup(@QueryParam("token") String authToken,
|
public void updateConnectionGroup(@QueryParam("token") String authToken,
|
||||||
@PathParam("connectionGroupID") String connectionGroupID, APIConnectionGroup connectionGroup) {
|
@PathParam("connectionGroupID") String connectionGroupID, APIConnectionGroup connectionGroup)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
if(connectionGroup == null)
|
||||||
if(connectionGroup == null)
|
throw new GuacamoleClientException("A connection group is required for this request.");
|
||||||
throw new GuacamoleClientException("A connection is required for this request.");
|
|
||||||
|
// Get the connection directory
|
||||||
// Get the connection directory
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
rootGroup.getConnectionGroupDirectory();
|
||||||
rootGroup.getConnectionGroupDirectory();
|
|
||||||
|
// Make sure the connection group is there before trying to update
|
||||||
// Make sure the connection group is there before trying to update
|
if(connectionGroupDirectory.get(connectionGroupID) == null)
|
||||||
if(connectionGroupDirectory.get(connectionGroupID) == null)
|
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided ID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided ID.");
|
|
||||||
|
// Update the connection group
|
||||||
// Update the connection group
|
connectionGroupDirectory.update(new APIConnectionGroupWrapper(connectionGroup));
|
||||||
connectionGroupDirectory.update(new APIConnectionGroupWrapper(connectionGroup));
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught updating connection group.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -282,39 +251,32 @@ public class ConnectionGroupRESTService {
|
|||||||
*
|
*
|
||||||
* @param authToken The authentication token that is used to authenticate
|
* @param authToken The authentication token that is used to authenticate
|
||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param connectionID The ID of the ConnectionGroup to move.
|
* @param connectionGroupID The ID of the ConnectionGroup to move.
|
||||||
* @param parentID The ID of the ConnectionGroup the connection groups
|
* @param parentID The ID of the ConnectionGroup the connection group is to be moved to.
|
||||||
* belong to. If null, the root connection group will be used.
|
* @throws GuacamoleException If a problem is encountered while moving the connection group.
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{connectionGroupID}")
|
@Path("/{connectionGroupID}")
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public void moveConnectionGroup(@QueryParam("token") String authToken,
|
public void moveConnectionGroup(@QueryParam("token") String authToken,
|
||||||
@PathParam("connectionGroupID") String connectionGroupID, @QueryParam("parentID") String parentID) {
|
@PathParam("connectionGroupID") String connectionGroupID,
|
||||||
|
@QueryParam("parentID") String parentID) throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the connection group directory
|
||||||
// Get the connection group directory
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
||||||
Directory<String, ConnectionGroup> connectionGroupDirectory =
|
rootGroup.getConnectionGroupDirectory();
|
||||||
rootGroup.getConnectionGroupDirectory();
|
|
||||||
|
// Find the new parent connection group
|
||||||
// Find the new parent connection group
|
Directory<String, ConnectionGroup> newConnectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
||||||
Directory<String, ConnectionGroup> newConnectionGroupDirectory = rootGroup.getConnectionGroupDirectory();
|
ConnectionGroup parentConnectionGroup = newConnectionGroupDirectory.get(parentID);
|
||||||
ConnectionGroup parentConnectionGroup = newConnectionGroupDirectory.get(parentID);
|
|
||||||
|
if(parentConnectionGroup == null)
|
||||||
if(parentConnectionGroup == null)
|
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID.");
|
|
||||||
|
// Move the connection group
|
||||||
// Move the connection group
|
connectionGroupDirectory.move(connectionGroupID, parentConnectionGroup.getConnectionGroupDirectory());
|
||||||
connectionGroupDirectory.move(connectionGroupID, parentConnectionGroup.getConnectionGroupDirectory());
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught moving connection group.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@ import org.glyptodon.guacamole.GuacamoleException;
|
|||||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||||
import org.glyptodon.guacamole.net.auth.User;
|
import org.glyptodon.guacamole.net.auth.User;
|
||||||
import org.glyptodon.guacamole.net.auth.UserContext;
|
import org.glyptodon.guacamole.net.auth.UserContext;
|
||||||
|
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -73,29 +74,22 @@ public class PermissionRESTService {
|
|||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param userID The ID of the user to retrieve permissions for.
|
* @param userID The ID of the user to retrieve permissions for.
|
||||||
* @return The permission list.
|
* @return The permission list.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while listing permissions.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/{userID}")
|
@Path("/{userID}")
|
||||||
public List<APIPermission> getPermissions(@QueryParam("token") String authToken, @PathParam("userID") String userID) {
|
@AuthProviderRESTExposure
|
||||||
|
public List<APIPermission> getPermissions(@QueryParam("token") String authToken, @PathParam("userID") String userID)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the user
|
||||||
// Get the user
|
User user = userContext.getUserDirectory().get(userID);
|
||||||
User user = userContext.getUserDirectory().get(userID);
|
|
||||||
|
if(user == null)
|
||||||
if(user == null)
|
throw new HTTPException(Status.NOT_FOUND, "User not found with the provided userID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "User not found with the provided userID.");
|
|
||||||
|
return permissionService.convertPermissionList(user.getPermissions());
|
||||||
return permissionService.convertPermissionList(user.getPermissions());
|
|
||||||
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while listing permissions.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,30 +99,24 @@ public class PermissionRESTService {
|
|||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param userID The user ID to add the permission for.
|
* @param userID The user ID to add the permission for.
|
||||||
* @param permission The permission to add for the user with the given userID.
|
* @param permission The permission to add for the user with the given userID.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while adding the permission.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/{userID}")
|
@Path("/{userID}")
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public void addPermission(@QueryParam("token") String authToken,
|
public void addPermission(@QueryParam("token") String authToken,
|
||||||
@PathParam("userID") String userID, APIPermission permission) {
|
@PathParam("userID") String userID, APIPermission permission)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the user
|
||||||
// Get the user
|
User user = userContext.getUserDirectory().get(userID);
|
||||||
User user = userContext.getUserDirectory().get(userID);
|
|
||||||
|
if(user == null)
|
||||||
if(user == null)
|
throw new HTTPException(Status.NOT_FOUND, "User not found with the provided userID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "User not found with the provided userID.");
|
|
||||||
|
// Add the new permission
|
||||||
// Add the new permission
|
user.addPermission(permission.toPermission());
|
||||||
user.addPermission(permission.toPermission());
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught adding permission.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,30 +126,24 @@ public class PermissionRESTService {
|
|||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param userID The user ID to remove the permission for.
|
* @param userID The user ID to remove the permission for.
|
||||||
* @param permission The permission to remove for the user with the given userID.
|
* @param permission The permission to remove for the user with the given userID.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while removing the permission.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/remove{userID}/")
|
@Path("/remove{userID}/")
|
||||||
|
@AuthProviderRESTExposure
|
||||||
public void removePermission(@QueryParam("token") String authToken,
|
public void removePermission(@QueryParam("token") String authToken,
|
||||||
@PathParam("userID") String userID, APIPermission permission) {
|
@PathParam("userID") String userID, APIPermission permission)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the user
|
||||||
// Get the user
|
User user = userContext.getUserDirectory().get(userID);
|
||||||
User user = userContext.getUserDirectory().get(userID);
|
|
||||||
|
if(user == null)
|
||||||
if(user == null)
|
throw new HTTPException(Status.NOT_FOUND, "User not found with the provided userID.");
|
||||||
throw new HTTPException(Status.NOT_FOUND, "User not found with the provided userID.");
|
|
||||||
|
// Remove the permission
|
||||||
// Remove the permission
|
user.removePermission(permission.toPermission());
|
||||||
user.removePermission(permission.toPermission());
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught removing permission.", e);
|
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ import org.glyptodon.guacamole.GuacamoleSecurityException;
|
|||||||
import org.glyptodon.guacamole.net.auth.Directory;
|
import org.glyptodon.guacamole.net.auth.Directory;
|
||||||
import org.glyptodon.guacamole.net.auth.User;
|
import org.glyptodon.guacamole.net.auth.User;
|
||||||
import org.glyptodon.guacamole.net.auth.UserContext;
|
import org.glyptodon.guacamole.net.auth.UserContext;
|
||||||
|
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -74,25 +75,18 @@ public class UserRESTService {
|
|||||||
* @param authToken The authentication token that is used to authenticate
|
* @param authToken The authentication token that is used to authenticate
|
||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @return The user list.
|
* @return The user list.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while listing users.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
public List<APIUser> getUsers(@QueryParam("token") String authToken) {
|
@AuthProviderRESTExposure
|
||||||
|
public List<APIUser> getUsers(@QueryParam("token") String authToken) throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the directory
|
||||||
// Get the directory
|
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
||||||
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
|
||||||
|
// Convert and return the user directory listing
|
||||||
// Convert and return the user directory listing
|
return userService.convertUserList(userDirectory);
|
||||||
return userService.convertUserList(userDirectory);
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Response.Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Response.Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while listing users.", e);
|
|
||||||
throw new HTTPException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,32 +94,26 @@ public class UserRESTService {
|
|||||||
* @param authToken The authentication token that is used to authenticate
|
* @param authToken The authentication token that is used to authenticate
|
||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @return user The user.
|
* @return user The user.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while retrieving the user.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/{userID}")
|
@Path("/{userID}")
|
||||||
public APIUser getUser(@QueryParam("token") String authToken, @PathParam("userID") String userID) {
|
@AuthProviderRESTExposure
|
||||||
|
public APIUser getUser(@QueryParam("token") String authToken, @PathParam("userID") String userID)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the directory
|
||||||
// Get the directory
|
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
||||||
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
|
||||||
|
// Get the user
|
||||||
// Get the user
|
User user = userDirectory.get(userID);
|
||||||
User user = userDirectory.get(userID);
|
|
||||||
|
if(user == null)
|
||||||
if(user == null)
|
throw new HTTPException(Response.Status.NOT_FOUND, "User not found with the provided userID.");
|
||||||
throw new HTTPException(Response.Status.NOT_FOUND, "User not found with the provided userID.");
|
|
||||||
|
// Return the user
|
||||||
// Return the user
|
return new APIUser(user);
|
||||||
return new APIUser(user);
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Response.Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Response.Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while getting user.", e);
|
|
||||||
throw new HTTPException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,27 +121,21 @@ public class UserRESTService {
|
|||||||
* @param authToken The authentication token that is used to authenticate
|
* @param authToken The authentication token that is used to authenticate
|
||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param user The new user to create.
|
* @param user The new user to create.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while creating the user.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
public String createUser(@QueryParam("token") String authToken, APIUser user) {
|
@AuthProviderRESTExposure
|
||||||
|
public String createUser(@QueryParam("token") String authToken, APIUser user)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the directory
|
||||||
// Get the directory
|
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
||||||
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
|
||||||
|
// Create the user
|
||||||
// Create the user
|
userDirectory.add(new APIUserWrapper(user));
|
||||||
userDirectory.add(new APIUserWrapper(user));
|
|
||||||
|
return user.getUsername();
|
||||||
return user.getUsername();
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Response.Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Response.Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while creating user.", e);
|
|
||||||
throw new HTTPException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,38 +144,32 @@ public class UserRESTService {
|
|||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param userID The unique identifier of the user to update.
|
* @param userID The unique identifier of the user to update.
|
||||||
* @param user The updated user.
|
* @param user The updated user.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while updating the user.
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/{userID}")
|
@Path("/{userID}")
|
||||||
public void updateUser(@QueryParam("token") String authToken, @PathParam("userID") String userID, APIUser user) {
|
@AuthProviderRESTExposure
|
||||||
|
public void updateUser(@QueryParam("token") String authToken, @PathParam("userID") String userID, APIUser user)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the directory
|
||||||
// Get the directory
|
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
||||||
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
|
||||||
|
if(!user.getUsername().equals(userID))
|
||||||
if(!user.getUsername().equals(userID))
|
throw new HTTPException(Response.Status.BAD_REQUEST, "Username does not match provided userID.");
|
||||||
throw new HTTPException(Response.Status.BAD_REQUEST, "Username does not match provided userID.");
|
|
||||||
|
// Get the user
|
||||||
// Get the user
|
User existingUser = userDirectory.get(userID);
|
||||||
User existingUser = userDirectory.get(userID);
|
|
||||||
|
if(existingUser == null)
|
||||||
if(existingUser == null)
|
throw new HTTPException(Response.Status.NOT_FOUND, "User not found with the provided userID.");
|
||||||
throw new HTTPException(Response.Status.NOT_FOUND, "User not found with the provided userID.");
|
|
||||||
|
/*
|
||||||
/*
|
* Update the user with the permission set from the existing user
|
||||||
* Update the user with the permission set from the existing user
|
* since the user REST endpoints do not expose permissions
|
||||||
* since the user REST endpoints do not expose permissions
|
*/
|
||||||
*/
|
userDirectory.update(new APIUserWrapper(user, existingUser.getPermissions()));
|
||||||
userDirectory.update(new APIUserWrapper(user, existingUser.getPermissions()));
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Response.Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Response.Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while updating user.", e);
|
|
||||||
throw new HTTPException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -201,31 +177,25 @@ public class UserRESTService {
|
|||||||
* @param authToken The authentication token that is used to authenticate
|
* @param authToken The authentication token that is used to authenticate
|
||||||
* the user performing the operation.
|
* the user performing the operation.
|
||||||
* @param userID The unique identifier of the user to delete.
|
* @param userID The unique identifier of the user to delete.
|
||||||
|
* @throws GuacamoleException If a problem is encountered while deleting the user.
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{userID}")
|
@Path("/{userID}")
|
||||||
public void deleteUser(@QueryParam("token") String authToken, @PathParam("userID") String userID) {
|
@AuthProviderRESTExposure
|
||||||
|
public void deleteUser(@QueryParam("token") String authToken, @PathParam("userID") String userID)
|
||||||
|
throws GuacamoleException {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
try {
|
// Get the directory
|
||||||
// Get the directory
|
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
||||||
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
|
||||||
|
// Get the user
|
||||||
// Get the user
|
User existingUser = userDirectory.get(userID);
|
||||||
User existingUser = userDirectory.get(userID);
|
|
||||||
|
if(existingUser == null)
|
||||||
if(existingUser == null)
|
throw new HTTPException(Response.Status.NOT_FOUND, "User not found with the provided userID.");
|
||||||
throw new HTTPException(Response.Status.NOT_FOUND, "User not found with the provided userID.");
|
|
||||||
|
// Delete the user
|
||||||
// Delete the user
|
userDirectory.remove(userID);
|
||||||
userDirectory.remove(userID);
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
|
||||||
throw new HTTPException(Response.Status.FORBIDDEN, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
|
||||||
} catch(GuacamoleClientException e) {
|
|
||||||
throw new HTTPException(Response.Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
|
||||||
} catch(GuacamoleException e) {
|
|
||||||
logger.error("Unexpected GuacamoleException caught while deleting user.", e);
|
|
||||||
throw new HTTPException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user