mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUAC-550: Use appropriate exceptions for error cases. Report when resources cannot be used because they are locked, exhausted, etc.
This commit is contained in:
@@ -31,6 +31,7 @@ import java.util.Map;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionHistoryMapper;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionHistory;
|
||||
import org.glyptodon.guacamole.GuacamoleResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* Represents the map of currently active Connections to the count of the number
|
||||
@@ -396,7 +397,7 @@ public class ActiveConnectionMap {
|
||||
Connection connection = activeConnectionMap.get(connectionID);
|
||||
|
||||
if(connection == null)
|
||||
throw new GuacamoleException
|
||||
throw new GuacamoleResourceNotFoundException
|
||||
("Connection to decrement does not exist.");
|
||||
|
||||
// Decrement the current user count
|
||||
@@ -478,7 +479,7 @@ public class ActiveConnectionMap {
|
||||
connectionHistoryDAO.selectByPrimaryKey(historyID);
|
||||
|
||||
if(connectionHistory == null)
|
||||
throw new GuacamoleException("History record not found.");
|
||||
throw new GuacamoleResourceNotFoundException("History record not found.");
|
||||
|
||||
// Get the connection and user IDs
|
||||
int connectionID = connectionHistory.getConnection_id();
|
||||
|
@@ -37,6 +37,8 @@ import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionPermissionKey;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionGroupService;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionService;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.PermissionCheckService;
|
||||
import org.glyptodon.guacamole.GuacamoleResourceNotFoundException;
|
||||
import org.glyptodon.guacamole.GuacamoleUnsupportedException;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
|
||||
import org.mybatis.guice.transactional.Transactional;
|
||||
|
||||
@@ -231,7 +233,7 @@ public class ConnectionDirectory implements Directory<String, Connection>{
|
||||
// If connection not actually from this auth provider, we can't handle
|
||||
// the update
|
||||
if (!(object instanceof MySQLConnection))
|
||||
throw new GuacamoleException("Connection not from database.");
|
||||
throw new GuacamoleUnsupportedException("Connection not from database.");
|
||||
|
||||
MySQLConnection mySQLConnection = (MySQLConnection) object;
|
||||
|
||||
@@ -263,7 +265,7 @@ public class ConnectionDirectory implements Directory<String, Connection>{
|
||||
connectionService.retrieveConnection(identifier, user_id);
|
||||
|
||||
if(mySQLConnection == null)
|
||||
throw new GuacamoleException("Connection not found.");
|
||||
throw new GuacamoleResourceNotFoundException("Connection not found.");
|
||||
|
||||
// Verify permission to use the parent connection group for organizational purposes
|
||||
permissionCheckService.verifyConnectionGroupUsageAccess
|
||||
@@ -284,7 +286,7 @@ public class ConnectionDirectory implements Directory<String, Connection>{
|
||||
throws GuacamoleException {
|
||||
|
||||
if(!(directory instanceof ConnectionDirectory))
|
||||
throw new GuacamoleClientException("Directory not from database");
|
||||
throw new GuacamoleUnsupportedException("Directory not from database");
|
||||
|
||||
Integer toConnectionGroupID = ((ConnectionDirectory)directory).parentID;
|
||||
|
||||
@@ -293,7 +295,7 @@ public class ConnectionDirectory implements Directory<String, Connection>{
|
||||
connectionService.retrieveConnection(identifier, user_id);
|
||||
|
||||
if(mySQLConnection == null)
|
||||
throw new GuacamoleClientException("Connection not found.");
|
||||
throw new GuacamoleResourceNotFoundException("Connection not found.");
|
||||
|
||||
// Verify permission to update the connection
|
||||
permissionCheckService.verifyConnectionAccess(this.user_id,
|
||||
|
@@ -34,6 +34,8 @@ import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionGroupPermissionMap
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroupPermissionKey;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionGroupService;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.PermissionCheckService;
|
||||
import org.glyptodon.guacamole.GuacamoleResourceNotFoundException;
|
||||
import org.glyptodon.guacamole.GuacamoleUnsupportedException;
|
||||
import org.mybatis.guice.transactional.Transactional;
|
||||
|
||||
/**
|
||||
@@ -189,7 +191,7 @@ public class ConnectionGroupDirectory implements Directory<String, ConnectionGro
|
||||
// If connection not actually from this auth provider, we can't handle
|
||||
// the update
|
||||
if (!(object instanceof MySQLConnectionGroup))
|
||||
throw new GuacamoleException("Connection not from database.");
|
||||
throw new GuacamoleUnsupportedException("Connection not from database.");
|
||||
|
||||
MySQLConnectionGroup mySQLConnectionGroup = (MySQLConnectionGroup) object;
|
||||
|
||||
@@ -211,7 +213,7 @@ public class ConnectionGroupDirectory implements Directory<String, ConnectionGro
|
||||
connectionGroupService.retrieveConnectionGroup(identifier, user_id);
|
||||
|
||||
if(mySQLConnectionGroup == null)
|
||||
throw new GuacamoleException("Connection group not found.");
|
||||
throw new GuacamoleResourceNotFoundException("Connection group not found.");
|
||||
|
||||
// Verify permission to use the parent connection group for organizational purposes
|
||||
permissionCheckService.verifyConnectionGroupUsageAccess
|
||||
@@ -233,10 +235,10 @@ public class ConnectionGroupDirectory implements Directory<String, ConnectionGro
|
||||
throws GuacamoleException {
|
||||
|
||||
if(MySQLConstants.CONNECTION_GROUP_ROOT_IDENTIFIER.equals(identifier))
|
||||
throw new GuacamoleClientException("The root connection group cannot be moved.");
|
||||
throw new GuacamoleUnsupportedException("The root connection group cannot be moved.");
|
||||
|
||||
if(!(directory instanceof ConnectionGroupDirectory))
|
||||
throw new GuacamoleClientException("Directory not from database");
|
||||
throw new GuacamoleUnsupportedException("Directory not from database");
|
||||
|
||||
Integer toConnectionGroupID = ((ConnectionGroupDirectory)directory).parentID;
|
||||
|
||||
@@ -245,7 +247,7 @@ public class ConnectionGroupDirectory implements Directory<String, ConnectionGro
|
||||
connectionGroupService.retrieveConnectionGroup(identifier, user_id);
|
||||
|
||||
if(mySQLConnectionGroup == null)
|
||||
throw new GuacamoleClientException("Connection group not found.");
|
||||
throw new GuacamoleResourceNotFoundException("Connection group not found.");
|
||||
|
||||
// Verify permission to update the connection
|
||||
permissionCheckService.verifyConnectionAccess(this.user_id,
|
||||
@@ -279,7 +281,7 @@ public class ConnectionGroupDirectory implements Directory<String, ConnectionGro
|
||||
Integer relativeParentID = toConnectionGroupID;
|
||||
while(relativeParentID != null) {
|
||||
if(relativeParentID == mySQLConnectionGroup.getConnectionGroupID())
|
||||
throw new GuacamoleClientException("Connection group cycle detected.");
|
||||
throw new GuacamoleUnsupportedException("Connection group cycle detected.");
|
||||
|
||||
MySQLConnectionGroup relativeParentGroup = connectionGroupService.
|
||||
retrieveConnectionGroup(relativeParentID, user_id);
|
||||
|
@@ -52,6 +52,7 @@ import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionGroupService;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionService;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.PermissionCheckService;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.UserService;
|
||||
import org.glyptodon.guacamole.GuacamoleUnsupportedException;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ConnectionGroupPermission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ConnectionPermission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.Permission;
|
||||
@@ -631,7 +632,7 @@ public class UserDirectory implements Directory<String, User> {
|
||||
|
||||
// Prevent self-de-adminifying
|
||||
if (user_id == this.user_id)
|
||||
throw new GuacamoleClientException("Removing your own administrative permissions is not allowed.");
|
||||
throw new GuacamoleUnsupportedException("Removing your own administrative permissions is not allowed.");
|
||||
|
||||
// Build list of requested system permissions
|
||||
List<String> systemPermissionTypes = new ArrayList<String>();
|
||||
@@ -654,7 +655,7 @@ public class UserDirectory implements Directory<String, User> {
|
||||
// If user not actually from this auth provider, we can't handle updated
|
||||
// permissions.
|
||||
if (!(object instanceof MySQLUser))
|
||||
throw new GuacamoleException("User not from database.");
|
||||
throw new GuacamoleUnsupportedException("User not from database.");
|
||||
|
||||
MySQLUser mySQLUser = (MySQLUser) object;
|
||||
|
||||
@@ -685,7 +686,7 @@ public class UserDirectory implements Directory<String, User> {
|
||||
|
||||
// Prevent self-deletion
|
||||
if (user.getUserID() == this.user_id)
|
||||
throw new GuacamoleClientException("Deleting your own user is not allowed.");
|
||||
throw new GuacamoleUnsupportedException("Deleting your own user is not allowed.");
|
||||
|
||||
// Validate current user has permission to remove the specified user
|
||||
permissionCheckService.verifyUserAccess(this.user_id,
|
||||
|
@@ -28,7 +28,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.net.GuacamoleSocket;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.ActiveConnectionMap;
|
||||
@@ -40,6 +39,9 @@ import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroup;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroupExample;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroupExample.Criteria;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.properties.MySQLGuacamoleProperties;
|
||||
import org.glyptodon.guacamole.GuacamoleClientTooManyException;
|
||||
import org.glyptodon.guacamole.GuacamoleResourceNotFoundException;
|
||||
import org.glyptodon.guacamole.GuacamoleServerBusyException;
|
||||
import org.glyptodon.guacamole.properties.GuacamoleProperties;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
|
||||
|
||||
@@ -130,7 +132,7 @@ public class ConnectionGroupService {
|
||||
try {
|
||||
connectionGroupID = Integer.parseInt(uniqueIdentifier);
|
||||
} catch(NumberFormatException e) {
|
||||
throw new GuacamoleException("Invalid connection group ID.");
|
||||
throw new GuacamoleResourceNotFoundException("Invalid connection group ID.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,18 +196,18 @@ public class ConnectionGroupService {
|
||||
activeConnectionMap.getLeastUsedConnection(connectionIDs);
|
||||
|
||||
if(leastUsedConnectionID == null)
|
||||
throw new GuacamoleException("No connections found in group.");
|
||||
throw new GuacamoleResourceNotFoundException("No connections found in group.");
|
||||
|
||||
if(GuacamoleProperties.getProperty(
|
||||
MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS, false)
|
||||
&& activeConnectionMap.isActive(leastUsedConnectionID))
|
||||
throw new GuacamoleClientException
|
||||
throw new GuacamoleServerBusyException
|
||||
("Cannot connect. All connections are in use.");
|
||||
|
||||
if(GuacamoleProperties.getProperty(
|
||||
MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS, true)
|
||||
&& activeConnectionMap.isConnectionGroupUserActive(group.getConnectionGroupID(), userID))
|
||||
throw new GuacamoleClientException
|
||||
throw new GuacamoleClientTooManyException
|
||||
("Cannot connect. Connection group already in use by this user.");
|
||||
|
||||
// Get the connection
|
||||
|
@@ -30,7 +30,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.net.GuacamoleSocket;
|
||||
import org.glyptodon.guacamole.net.InetGuacamoleSocket;
|
||||
@@ -55,6 +54,8 @@ import org.glyptodon.guacamole.protocol.ConfiguredGuacamoleSocket;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
|
||||
import org.apache.ibatis.session.RowBounds;
|
||||
import org.glyptodon.guacamole.GuacamoleClientTooManyException;
|
||||
import org.glyptodon.guacamole.GuacamoleResourceConflictException;
|
||||
|
||||
/**
|
||||
* Service which provides convenience methods for creating, retrieving, and
|
||||
@@ -326,12 +327,12 @@ public class ConnectionService {
|
||||
if(GuacamoleProperties.getProperty(
|
||||
MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS, false)
|
||||
&& activeConnectionMap.isActive(connection.getConnectionID()))
|
||||
throw new GuacamoleClientException("Cannot connect. This connection is in use.");
|
||||
throw new GuacamoleResourceConflictException("Cannot connect. This connection is in use.");
|
||||
|
||||
if(GuacamoleProperties.getProperty(
|
||||
MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS, true)
|
||||
&& activeConnectionMap.isConnectionUserActive(connection.getConnectionID(), userID))
|
||||
throw new GuacamoleClientException
|
||||
throw new GuacamoleClientTooManyException
|
||||
("Cannot connect. Connection already in use by this user.");
|
||||
|
||||
// Get guacd connection information
|
||||
|
Reference in New Issue
Block a user