GUACAMOLE-360: Add convenience function for testing user identity.

This commit is contained in:
Michael Jumper
2018-10-01 11:45:25 -07:00
parent ad937defa6
commit ea142d15ce
3 changed files with 17 additions and 2 deletions

View File

@@ -97,7 +97,7 @@ public class ActiveConnectionPermissionService
permissions.add(new ObjectPermission(ObjectPermission.Type.READ, identifier));
// If we're an admin, or the connection is ours, then we can DELETE
if (isAdmin || (targetEntity.isUser() && targetEntity.getIdentifier().equals(record.getUsername())))
if (isAdmin || targetEntity.isUser(record.getUsername()))
permissions.add(new ObjectPermission(ObjectPermission.Type.DELETE, identifier));
}

View File

@@ -105,6 +105,21 @@ public abstract class ModeledPermissions<ModelType extends EntityModel>
return getModel().getEntityType() == EntityType.USER;
}
/**
* Returns whether the underlying entity represents a specific user having
* the given username.
*
* @param username
* The username of a user.
*
* @return
* true if the underlying entity is a user that has the given username,
* false otherwise.
*/
public boolean isUser(String username) {
return isUser() && getIdentifier().equals(username);
}
/**
* Returns whether the underlying entity is a user group. Entities may be
* either users or user groups.

View File

@@ -101,7 +101,7 @@ public abstract class AbstractPermissionService<PermissionSetType extends Permis
throws GuacamoleException {
// A user can always read their own permissions
if (targetEntity.isUser() && user.getUser().getIdentifier().equals(targetEntity.getIdentifier()))
if (targetEntity.isUser(user.getUser().getIdentifier()))
return true;
// A system adminstrator can do anything