Ticket #269: Trim identifiers on add().

This commit is contained in:
Michael Jumper
2013-03-03 23:41:49 -08:00
parent e8bba941e1
commit 8f43da42bf
2 changed files with 8 additions and 8 deletions

View File

@@ -130,7 +130,8 @@ public class ConnectionDirectory implements Directory<String, Connection>{
@Override
public void add(Connection object) throws GuacamoleException {
if(object.getIdentifier().isEmpty())
String identifier = object.getIdentifier().trim();
if(identifier.isEmpty())
throw new GuacamoleClientException("The connection identifier cannot be blank.");
// Verify permission to create
@@ -139,13 +140,13 @@ public class ConnectionDirectory implements Directory<String, Connection>{
// Verify that no connection already exists with this identifier.
MySQLConnection previousConnection =
connectionService.retrieveConnection(object.getIdentifier(), user_id);
connectionService.retrieveConnection(identifier, user_id);
if(previousConnection != null)
throw new GuacamoleClientException("That connection identifier is already in use.");
// Create connection
MySQLConnection connection = connectionService.createConnection(
object.getIdentifier(), object.getConfiguration().getProtocol(),
identifier, object.getConfiguration().getProtocol(),
user_id);
// Add connection parameters

View File

@@ -154,7 +154,8 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
public void add(net.sourceforge.guacamole.net.auth.User object)
throws GuacamoleException {
if(object.getUsername().isEmpty())
String username = object.getUsername().trim();
if(username.isEmpty())
throw new GuacamoleClientException("The username cannot be blank.");
// Verify current user has permission to create users
@@ -163,14 +164,12 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
Preconditions.checkNotNull(object);
// Verify that no user already exists with this username.
MySQLUser previousUser =
userService.retrieveUser(object.getUsername());
MySQLUser previousUser = userService.retrieveUser(username);
if(previousUser != null)
throw new GuacamoleClientException("That username is already in use.");
// Create new user
MySQLUser user = userService.createUser(object.getUsername(),
object.getPassword());
MySQLUser user = userService.createUser(username, object.getPassword());
// Create permissions of new user in database
createPermissions(user.getUserID(), object.getPermissions());