mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-16 07:10:48 +00:00
adjusted tests and verdicts to modified permission check
Change-Id: Ia4ad1b0769fec25a13e7d87dbde01d0ef8ba3b15
This commit is contained in:
1 parent
8195402e65
commit
4c8214afdb
2 files changed
+25
-23
No files matched your search
+12
-21
@@ -6,20 +6,15 @@ import java.util.Set;
|
||||
import com.sap.sse.common.Util;
|
||||
|
||||
/**
|
||||
* The {@link PermissionChecker} is an implementation of the permission
|
||||
* checking algorithm proposed in PermissionConcept.docx section 10. It
|
||||
* checks permissions in four stages where earlier stages overwrite later.
|
||||
* The {@link PermissionChecker} is an implementation of the permission checking algorithm also described in <a href=
|
||||
* "https://wiki.sapsailing.com/wiki/info/security/permission-concept#algorithm-boolean-ispermitted-principalcollection-principals-wildcardpermission-permission-for-composite-realm">Permission
|
||||
* Concept Wiki article</a>. It checks permissions in four stages where earlier stages overwrite later.
|
||||
*
|
||||
* 1. Firstly, the ownership of the data object is tested. If the
|
||||
* requesting user is the owner of the data object he is automatically
|
||||
* granted every possible permission for that data object.
|
||||
* 2. Secondly, the data object's ACL is checked if it grants or explicitly
|
||||
* revokes the permission.
|
||||
* 3. Thereafter, the permissions directly assigned to the user are checked.
|
||||
* 4. Finally the permissions implied by roles the user has are checked.
|
||||
* This includes dynamic and parametrized roles.
|
||||
*
|
||||
* @author Jonas Dann
|
||||
* 1. Firstly, the data object's ACL is checked if it grants or explicitly revokes the permission. 2. Thereafter, the
|
||||
* permissions directly assigned to the user are checked. 3. Finally the permissions implied by roles the user has are
|
||||
* checked. This includes roles qualified by the group/user ownerships of the objetcs to which they are applied.
|
||||
*
|
||||
* @author Jonas Dann, Axel Uhl (d043530)
|
||||
*/
|
||||
public class PermissionChecker {
|
||||
public enum PermissionState {
|
||||
@@ -48,17 +43,13 @@ public class PermissionChecker {
|
||||
}
|
||||
PermissionState result = PermissionState.NONE;
|
||||
|
||||
// 1. check user ownership
|
||||
if (ownership != null && Util.equalsWithNull(user, ownership.getUserOwner())) {
|
||||
result = PermissionState.GRANTED;
|
||||
}
|
||||
// 2. check ACL
|
||||
else if (acl != null) {
|
||||
// 1. check ACL
|
||||
if (acl != null) {
|
||||
// if no specific action is requested then this translates to a request for all permissions ("*")
|
||||
String action = parts.size() < 2 ? WildcardPermission.WILDCARD_TOKEN : (String) parts.get(1).toArray()[0];
|
||||
result = acl.hasPermission(user, action, groupsOfWhichUserIsMember);
|
||||
}
|
||||
// 3. check direct permissions
|
||||
// 2. check direct permissions
|
||||
if (result == PermissionState.NONE) {
|
||||
for (WildcardPermission directPermission : user.getPermissions()) {
|
||||
if (directPermission.implies(permission)) {
|
||||
@@ -67,7 +58,7 @@ public class PermissionChecker {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 4. check role permissions
|
||||
// 3. check role permissions
|
||||
if (result == PermissionState.NONE) {
|
||||
for (Role role : user.getRoles()) {
|
||||
if (implies(role, permission, ownership)) {
|
||||
|
||||
+13
-2
@@ -89,9 +89,13 @@ public class PermissionCheckerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOwnership() {
|
||||
public void testOwnership() throws UserManagementException {
|
||||
assertFalse(PermissionChecker.isPermitted(eventReadPermission, user, tenants, null, acl));
|
||||
assertFalse(PermissionChecker.isPermitted(eventReadPermission, user, tenants, adminOwnership, acl));
|
||||
// being the owning user does not imply any permissions per se
|
||||
assertFalse(PermissionChecker.isPermitted(eventReadPermission, user, tenants, ownership, acl));
|
||||
userStore.addRoleForUser(user.getName(), new RoleImpl(AdminRole.getInstance(), /* qualified for userTenant */ null, /* qualified for user */ user));
|
||||
// having the admin role qualified for objects owned by user should help
|
||||
assertTrue(PermissionChecker.isPermitted(eventReadPermission, user, tenants, ownership, acl));
|
||||
}
|
||||
|
||||
@@ -113,8 +117,14 @@ public class PermissionCheckerTest {
|
||||
WildcardPermission regattaPermission = Permission.REGATTA.getPermissionForObjects(DefaultModes.READ, regattaName);
|
||||
assertFalse(realm.isPermitted(principalCollection, leaderboardPermission.toString()));
|
||||
assertFalse(realm.isPermitted(principalCollection, regattaPermission.toString()));
|
||||
// let leaderboard be owned by user
|
||||
accessControlStore.createOwnership(Permission.LEADERBOARD.getQualifiedObjectIdentifier(leaderboardName), user,
|
||||
/* tenantOwner */ null, leaderboardName);
|
||||
// let regatta be owned by admin
|
||||
accessControlStore.createOwnership(Permission.REGATTA.getQualifiedObjectIdentifier(regattaName), adminUser,
|
||||
/* tenantOwner */ null, regattaName);
|
||||
// grant user the admin role, but only for objects owned by the user (leaderboard, but not regatta)
|
||||
userStore.addRoleForUser(user.getName(), new RoleImpl(AdminRole.getInstance(), /* qualifiedForTenant */ null, /* qualifiedForUser */ user));
|
||||
assertTrue(realm.isPermitted(principalCollection, leaderboardPermission.toString()));
|
||||
assertFalse(realm.isPermitted(principalCollection, regattaPermission.toString()));
|
||||
accessControlStore.createOwnership(Permission.REGATTA.getQualifiedObjectIdentifier(regattaName), /* userOwner */ null,
|
||||
@@ -147,7 +157,8 @@ public class PermissionCheckerTest {
|
||||
permissionMap.put(userTenant, permissionSet);
|
||||
acl = new AccessControlListImpl(permissionMap);
|
||||
assertFalse(PermissionChecker.isPermitted(eventReadPermission, user, tenants, adminOwnership, acl));
|
||||
assertTrue(PermissionChecker.isPermitted(eventReadPermission, user, tenants, ownership, acl));
|
||||
// User ownership shall NOT imply permissions; the revoking ACL still takes precedence
|
||||
assertFalse(PermissionChecker.isPermitted(eventReadPermission, user, tenants, ownership, acl));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user