diff --git a/java/com.sap.sse.security.common/src/com/sap/sse/security/shared/PermissionChecker.java b/java/com.sap.sse.security.common/src/com/sap/sse/security/shared/PermissionChecker.java index 9c377d3bac6..29764a9af5e 100755 --- a/java/com.sap.sse.security.common/src/com/sap/sse/security/shared/PermissionChecker.java +++ b/java/com.sap.sse.security.common/src/com/sap/sse/security/shared/PermissionChecker.java @@ -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 Permission + * Concept Wiki article. 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)) { diff --git a/java/com.sap.sse.security.test/src/com/sap/sse/security/test/PermissionCheckerTest.java b/java/com.sap.sse.security.test/src/com/sap/sse/security/test/PermissionCheckerTest.java index c7e13e724bf..7e345b280a0 100755 --- a/java/com.sap.sse.security.test/src/com/sap/sse/security/test/PermissionCheckerTest.java +++ b/java/com.sap.sse.security.test/src/com/sap/sse/security/test/PermissionCheckerTest.java @@ -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