Ticket #269: Clean up permission create/remove prototypes, add missing JavaDoc, fix whitespace at end of line.

This commit is contained in:
Michael Jumper
2013-02-26 02:44:33 -08:00
parent 97c1bc6a28
commit 6af023f7d3
5 changed files with 78 additions and 69 deletions

View File

@@ -87,7 +87,7 @@ public class ConnectionDirectory implements Directory<String, Connection>{
/**
* Set the user for this directory.
*
*
* @param user_id The ID of the user owning this connection directory.
*/
public void init(int user_id) {

View File

@@ -58,7 +58,7 @@ public class MySQLUser extends AbstractUser {
* The ID of this user in the database, if any.
*/
private Integer userID;
/**
* Service for encrypting passwords.
*/
@@ -81,26 +81,26 @@ public class MySQLUser extends AbstractUser {
* The set of current permissions a user has.
*/
private Set<Permission> permissions = new HashSet<Permission>();
/**
* Any newly added permissions that have yet to be committed.
*/
private Set<Permission> newPermissions = new HashSet<Permission>();
/**
* Any newly deleted permissions that have yet to be deleted.
*/
private Set<Permission> removedPermissions = new HashSet<Permission>();
/**
* Creates a new, empty MySQLUser.
*/
public MySQLUser() {
}
/**
* Initializes a new MySQLUser having the given username.
*
*
* @param name The name to assign to this MySQLUser.
*/
public void init(String name) {
@@ -110,7 +110,7 @@ public class MySQLUser extends AbstractUser {
/**
* Initializes a new MySQLUser, copying all data from the given user
* object.
*
*
* @param user The user object to copy.
* @throws GuacamoleException If an error occurs while reading the user
* data in the given object.
@@ -124,7 +124,7 @@ public class MySQLUser extends AbstractUser {
/**
* Initializes a new MySQLUser initialized from the given data from the
* database.
*
*
* @param user The user object, as retrieved from the database.
*/
public void init(UserWithBLOBs user) {
@@ -134,7 +134,7 @@ public class MySQLUser extends AbstractUser {
permissions.addAll(
permissionCheckUtility.getAllPermissions(user.getUser_id()));
}
/**
* Get the current set of permissions this user has.
* @return the current set of permissions.
@@ -142,7 +142,7 @@ public class MySQLUser extends AbstractUser {
public Set<Permission> getCurrentPermissions() {
return permissions;
}
/**
* Get any new permissions that have yet to be inserted.
* @return the new set of permissions.
@@ -150,7 +150,7 @@ public class MySQLUser extends AbstractUser {
public Set<Permission> getNewPermissions() {
return newPermissions;
}
/**
* Get any permissions that have not yet been deleted.
* @return the permissions that need to be deleted.
@@ -158,7 +158,7 @@ public class MySQLUser extends AbstractUser {
public Set<Permission> getRemovedPermissions() {
return removedPermissions;
}
/**
* Reset the new and removed permission sets after they are
* no longer needed.
@@ -170,7 +170,7 @@ public class MySQLUser extends AbstractUser {
/**
* Returns the ID of this user in the database, if it exists.
*
*
* @return The ID of this user in the database, or null if this user
* was not retrieved from the database.
*/
@@ -180,7 +180,7 @@ public class MySQLUser extends AbstractUser {
/**
* Sets the ID of this user to the given value.
*
*
* @param userID The ID to assign to this user.
*/
public void setUserID(Integer userID) {
@@ -216,7 +216,7 @@ public class MySQLUser extends AbstractUser {
* into the database. Beware that this object does not have associated
* permissions. The permissions of this MySQLUser must be dealt with
* separately.
*
*
* @return A new UserWithBLOBs containing all associated data of this
* MySQLUser.
*/
@@ -236,7 +236,7 @@ public class MySQLUser extends AbstractUser {
}
return user;
}
}

View File

@@ -76,7 +76,7 @@ public class MySQLUserContext implements UserContext {
*/
@Inject
private ProviderService providerService;
/**
* Initializes the user and directories associated with this context.
*

View File

@@ -131,7 +131,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
*/
@Inject
private ProviderService providerUtility;
/**
* Service for encrypting passwords.
*/
@@ -197,7 +197,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
user.setPassword_hash(
passwordUtility.createPasswordHash(object.getPassword(), salt));
}
userDAO.insert(user);
// Create permissions of new user in database
@@ -227,11 +227,10 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
}
/**
* Update all the permissions for a given user to be only those specified in the user object.
* Delete any permissions not in the list, and create any in the list that do not exist
* in the database.
* Add the given permissions to the given user.
*
* @param user The user whose permissions should be updated.
* @param user_id The ID of the user whose permissions should be updated.
* @param permissions The permissions to add.
* @throws GuacamoleException If an error occurs while updating the
* permissions of the given user.
*/
@@ -255,15 +254,25 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
}
// Create the new permissions
createUserPermissions(newUserPermissions, user_id);
createConnectionPermissions(newConnectionPermissions, user_id);
createSystemPermissions(newSystemPermissions, user_id);
createUserPermissions(user_id, newUserPermissions);
createConnectionPermissions(user_id, newConnectionPermissions);
createSystemPermissions(user_id, newSystemPermissions);
}
private void removePermissions(int user_id, Set<Permission> permissions) throws GuacamoleException {
/**
* Remove the given permissions from the given user.
*
* @param user_id The ID of the user whose permissions should be updated.
* @param permissions The permissions to remove.
* @throws GuacamoleException If an error occurs while updating the
* permissions of the given user.
*/
private void removePermissions(int user_id, Set<Permission> permissions)
throws GuacamoleException {
// Partition given permissions by permission type
List<UserPermission> removedUserPermissions = new ArrayList<UserPermission>();
List<ConnectionPermission> removedConnectionPermissions = new ArrayList<ConnectionPermission>();
@@ -280,27 +289,27 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
else if (permission instanceof SystemPermission)
removedSystemPermissions.add((SystemPermission) permission);
}
// Delete the removed permissions.
deleteUserPermissions(removedUserPermissions, user_id);
deleteConnectionPermissions(removedConnectionPermissions, user_id);
deleteSystemPermissions(removedSystemPermissions, user_id);
deleteUserPermissions(user_id, removedUserPermissions);
deleteConnectionPermissions(user_id, removedConnectionPermissions);
deleteSystemPermissions(user_id, removedSystemPermissions);
}
/**
* Create any new permissions having to do with users for a given user.
* Create the given user permissions for the given user.
*
* @param user_id The ID of the user to change the permissions of.
* @param permissions The new permissions the given user should have when
* this operation completes.
* @param user_id The ID of the user to change the permissions of.
* @throws GuacamoleException If permission to alter the access permissions
* of affected objects is denied.
*/
private void createUserPermissions(Collection<UserPermission> permissions,
int user_id)
private void createUserPermissions(int user_id,
Collection<UserPermission> permissions)
throws GuacamoleException {
if(permissions.isEmpty())
return;
@@ -323,7 +332,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
for (User dbUser : dbUsers) {
dbUserMap.put(dbUser.getUsername(), dbUser);
}
for (UserPermission permission : permissions) {
// Get user
@@ -353,16 +362,16 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
/**
* Delete permissions having to do with users for a given user.
*
* @param user_id The ID of the user to change the permissions of.
* @param permissions The permissions the given user should no longer have
* when this operation completes.
* @param user_id The ID of the user to change the permissions of.
* @throws GuacamoleException If permission to alter the access permissions
* of affected objects is denied.
*/
private void deleteUserPermissions(Collection<UserPermission> permissions,
int user_id)
private void deleteUserPermissions(int user_id,
Collection<UserPermission> permissions)
throws GuacamoleException {
if(permissions.isEmpty())
return;
@@ -387,7 +396,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
dbUserMap.put(dbUser.getUsername(), dbUser);
userIDs.add(dbUser.getUser_id());
}
// Verify we have permission to delete each user permission.
for (UserPermission permission : permissions) {
@@ -406,7 +415,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
+ " does not have permission to administrate user "
+ dbAffectedUser.getUser_id());
}
if(!userIDs.isEmpty()) {
UserPermissionExample userPermissionExample = new UserPermissionExample();
userPermissionExample.createCriteria().andUser_idEqualTo(user_id)
@@ -419,16 +428,16 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
* Create any new permissions having to do with connections for a given
* user.
*
* @param user_id The ID of the user to assign or remove permissions from.
* @param permissions The new permissions the user should have after this
* operation completes.
* @param user_id The ID of the user to assign or remove permissions from.
* @throws GuacamoleException If permission to alter the access permissions
* of affected objects is deniedD
*/
private void createConnectionPermissions(
Collection<ConnectionPermission> permissions, int user_id)
private void createConnectionPermissions(int user_id,
Collection<ConnectionPermission> permissions)
throws GuacamoleException {
if(permissions.isEmpty())
return;
@@ -483,16 +492,16 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
/**
* Delete permissions having to do with connections for a given user.
*
* @param user_id The ID of the user to change the permissions of.
* @param permissions The permissions the given user should no longer have
* when this operation completes.
* @param user_id The ID of the user to change the permissions of.
* @throws GuacamoleException If permission to alter the access permissions
* of affected objects is denied.
*/
private void deleteConnectionPermissions(Collection<ConnectionPermission> permissions,
int user_id)
private void deleteConnectionPermissions(int user_id,
Collection<ConnectionPermission> permissions)
throws GuacamoleException {
if(permissions.isEmpty())
return;
@@ -517,7 +526,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
dbConnectionMap.put(dbConnection.getConnection_name(), dbConnection);
connectionIDs.add(dbConnection.getConnection_id());
}
// Verify we have permission to delete each connection permission.
for (ConnectionPermission permission : permissions) {
@@ -536,7 +545,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
+ " does not have permission to administrate connection "
+ dbConnection.getConnection_id());
}
if(!connectionIDs.isEmpty()) {
ConnectionPermissionExample connectionPermissionExample = new ConnectionPermissionExample();
connectionPermissionExample.createCriteria().andUser_idEqualTo(user_id)
@@ -549,16 +558,16 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
* Create any new system permissions for a given user. All permissions in
* the given list will be inserted.
*
* @param user_id The ID of the user whose permissions should be updated.
* @param permissions The new system permissions that the given user should
* have when this operation completes.
* @param user_id The ID of the user whose permissions should be updated.
*/
private void createSystemPermissions(Collection<SystemPermission> permissions,
int user_id) {
private void createSystemPermissions(int user_id,
Collection<SystemPermission> permissions) {
if(permissions.isEmpty())
return;
// Build list of requested system permissions
List<String> systemPermissionTypes = new ArrayList<String>();
for (SystemPermission permission : permissions) {
@@ -609,18 +618,18 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
}
}
/**
* Delete system permissions for a given user. All permissions in
* the given list will be removed from the user.
*
* @param user_id The ID of the user whose permissions should be updated.
* @param permissions The permissions the given user should no longer have
* when this operation completes.
* @param user_id The ID of the user whose permissions should be updated.
*/
private void deleteSystemPermissions(Collection<SystemPermission> permissions,
int user_id) {
private void deleteSystemPermissions(int user_id,
Collection<SystemPermission> permissions) {
if(permissions.isEmpty())
return;
@@ -680,7 +689,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
// permissions.
if (!(object instanceof MySQLUser))
throw new GuacamoleException("User not from database.");
// Validate permission to update this user is granted
permissionCheckUtility.verifyUserUpdateAccess(this.user_id,
object.getUsername());

View File

@@ -384,7 +384,7 @@ public class PermissionCheckService {
// If no affected users at all, return empty set
if (affectedUserIDs.isEmpty())
return Collections.EMPTY_SET;
// Query corresponding user data for each retrieved ID
UserExample example = new UserExample();
example.createCriteria().andUser_idIn(Lists.newArrayList(affectedUserIDs));
@@ -720,7 +720,7 @@ public class PermissionCheckService {
// Otherwise, no connections available
return Collections.EMPTY_SET;
}
/**
@@ -860,7 +860,7 @@ public class PermissionCheckService {
List<ConnectionPermissionKey> connectionPermissions =
connectionPermissionDAO.selectByExample(connectionPermissionExample);
// If connection permissions present, add permissions
// If connection permissions present, add permissions
if (!connectionPermissions.isEmpty()) {
// Get list of affected connection IDs