Skip to content

Commit b59e696

Browse files
committed
new permission model with write and delete
1 parent 6c8831d commit b59e696

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

src/main/kotlin/com/cosmotech/api/rbac/RolesDefinition.kt

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,53 @@ const val ROLE_USER = "user"
1313
const val ROLE_NONE = "none"
1414

1515
// apply same format rules for permission for consistency
16-
const val PERMISSION_READ_DATA = "read_data"
16+
const val PERMISSION_READ = "read"
1717
const val PERMISSION_READ_SECURITY = "read_security"
1818
const val PERMISSION_CREATE_CHILDREN = "create_children"
19-
const val PERMISSION_EDIT = "edit"
20-
const val PERMISSION_EDIT_SECURITY = "edit_security"
19+
const val PERMISSION_WRITE = "write"
20+
const val PERMISSION_WRITE_SECURITY = "write_security"
21+
const val PERMISSION_DELETE = "delete"
2122
const val PERMISSION_LAUNCH = "launch"
2223
const val PERMISSION_VALIDATE = "validate"
2324

2425
val COMMON_ROLE_NONE_PERMISSIONS: List<String> = listOf()
25-
val COMMON_ROLE_READER_PERMISSIONS = listOf(PERMISSION_READ_DATA, PERMISSION_READ_SECURITY)
26+
val COMMON_ROLE_READER_PERMISSIONS = listOf(PERMISSION_READ, PERMISSION_READ_SECURITY)
2627
val COMMON_ROLE_USER_PERMISSIONS =
27-
listOf(PERMISSION_READ_DATA, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN)
28+
listOf(PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN)
2829
val COMMON_ROLE_EDITOR_PERMISSIONS =
2930
listOf(
30-
PERMISSION_READ_DATA, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, PERMISSION_EDIT)
31+
PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, PERMISSION_WRITE)
3132
val COMMON_ROLE_ADMIN_PERMISSIONS =
3233
listOf(
33-
PERMISSION_READ_DATA,
34+
PERMISSION_READ,
3435
PERMISSION_READ_SECURITY,
3536
PERMISSION_CREATE_CHILDREN,
36-
PERMISSION_EDIT,
37-
PERMISSION_EDIT_SECURITY)
37+
PERMISSION_WRITE,
38+
PERMISSION_WRITE_SECURITY,
39+
PERMISSION_DELETE,
40+
)
3841

3942
// Scenario roles & permissions
40-
val SCENARIO_ROLE_VIEWER_PERMISSIONS = listOf(PERMISSION_READ_DATA, PERMISSION_READ_SECURITY)
43+
val SCENARIO_ROLE_VIEWER_PERMISSIONS = listOf(PERMISSION_READ, PERMISSION_READ_SECURITY)
4144
val SCENARIO_ROLE_EDITOR_PERMISSIONS =
42-
listOf(PERMISSION_READ_DATA, PERMISSION_READ_SECURITY, PERMISSION_LAUNCH, PERMISSION_EDIT)
45+
listOf(PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_LAUNCH, PERMISSION_WRITE)
4346
val SCENARIO_ROLE_VALIDATOR_PERMISSIONS =
4447
listOf(
45-
PERMISSION_READ_DATA,
48+
PERMISSION_READ,
4649
PERMISSION_READ_SECURITY,
4750
PERMISSION_LAUNCH,
48-
PERMISSION_EDIT,
51+
PERMISSION_WRITE,
4952
PERMISSION_VALIDATE)
5053
val SCENARIO_ROLE_ADMIN_PERMISSIONS =
5154
listOf(
52-
PERMISSION_READ_DATA,
55+
PERMISSION_READ,
5356
PERMISSION_READ_SECURITY,
5457
PERMISSION_LAUNCH,
55-
PERMISSION_EDIT,
58+
PERMISSION_WRITE,
5659
PERMISSION_VALIDATE,
57-
PERMISSION_EDIT_SECURITY)
60+
PERMISSION_WRITE_SECURITY,
61+
PERMISSION_DELETE,
62+
)
5863

5964
@Component
6065
data class RolesDefinition(

src/test/kotlin/com/cosmotech/api/rbac/CsmRbacTests.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ class CsmRbacTests {
519519
fun `add custom role definition`() {
520520
val definition = getCommonRolesDefinition()
521521
val customRole = "custom_role"
522-
val customRolePermissions = listOf(PERMISSION_READ_DATA, "custom_permission")
522+
val customRolePermissions = listOf(PERMISSION_READ, "custom_permission")
523523
definition.permissions.put(customRole, customRolePermissions)
524524
val expected: MutableMap<String, List<String>> =
525525
mutableMapOf(
@@ -538,7 +538,7 @@ class CsmRbacTests {
538538
val definition = getCommonRolesDefinition()
539539
val customRole = "custom_role"
540540
val customPermission = "custom_permission"
541-
val customRolePermissions = listOf(PERMISSION_READ_DATA, customPermission)
541+
val customRolePermissions = listOf(PERMISSION_READ, customPermission)
542542
definition.permissions.put(customRole, customRolePermissions)
543543
val rbacTest = CsmRbac(csmPlatformProperties, admin)
544544
rbacTest.setUserRole(rbacSecurity, USER_NEW_READER, customRole, definition)
@@ -553,7 +553,7 @@ class CsmRbacTests {
553553
val rbacTest = CsmRbac(csmPlatformProperties, admin)
554554
rbacTest.setUserRole(rbacSecurity, USER_READER, ROLE_VIEWER, definition)
555555
every { securityContext.authentication } returns (userAuthentication as Authentication)
556-
assertTrue(rbacTest.check(rbacSecurity, PERMISSION_READ_DATA, USER_READER, definition))
556+
assertTrue(rbacTest.check(rbacSecurity, PERMISSION_READ, USER_READER, definition))
557557
}
558558

559559
@Test
@@ -567,7 +567,7 @@ class CsmRbacTests {
567567
RbacAccessControl(USER_READER, ROLE_VIEWER),
568568
))
569569
every { securityContext.authentication } returns (userAuthentication as Authentication)
570-
assertTrue(rbacTest.check(rbacSecurity, PERMISSION_READ_DATA, USER_READER, definition))
570+
assertTrue(rbacTest.check(rbacSecurity, PERMISSION_READ, USER_READER, definition))
571571
}
572572

573573
@Test
@@ -581,7 +581,7 @@ class CsmRbacTests {
581581
RbacAccessControl(USER_WRITER, ROLE_EDITOR),
582582
))
583583
every { securityContext.authentication } returns (userAuthentication as Authentication)
584-
assertTrue(rbacTest.check(rbacSecurity, PERMISSION_READ_DATA, USER_READER, definition))
584+
assertTrue(rbacTest.check(rbacSecurity, PERMISSION_READ, USER_READER, definition))
585585
}
586586

587587
@Test
@@ -595,7 +595,7 @@ class CsmRbacTests {
595595
RbacAccessControl(USER_WRITER, ROLE_EDITOR),
596596
))
597597
every { securityContext.authentication } returns (userAuthentication as Authentication)
598-
assertFalse(rbacTest.check(rbacSecurity, PERMISSION_EDIT_SECURITY, USER_READER, definition))
598+
assertFalse(rbacTest.check(rbacSecurity, PERMISSION_WRITE_SECURITY, USER_READER, definition))
599599
}
600600

601601
@Test
@@ -624,7 +624,7 @@ class CsmRbacTests {
624624
RbacAccessControl(USER_WRITER, ROLE_EDITOR),
625625
))
626626
every { securityContext.authentication } returns (userAuthentication as Authentication)
627-
assertTrue(rbacTest.check(rbacSecurity, PERMISSION_EDIT, USER_WRITER, definition))
627+
assertTrue(rbacTest.check(rbacSecurity, PERMISSION_WRITE, USER_WRITER, definition))
628628
}
629629

630630
@Test
@@ -638,7 +638,7 @@ class CsmRbacTests {
638638
RbacAccessControl(USER_MAIL_TOKEN, ROLE_EDITOR),
639639
))
640640
every { securityContext.authentication } returns (userAuthentication as Authentication)
641-
assertDoesNotThrow { rbacTest.verify(rbacSecurity, PERMISSION_EDIT, definition) }
641+
assertDoesNotThrow { rbacTest.verify(rbacSecurity, PERMISSION_WRITE, definition) }
642642
}
643643

644644
@Test
@@ -652,7 +652,7 @@ class CsmRbacTests {
652652
RbacAccessControl(USER_WRITER, ROLE_EDITOR),
653653
))
654654
every { securityContext.authentication } returns (userAuthentication as Authentication)
655-
assertTrue(rbacTest.check(rbacSecurity, PERMISSION_EDIT, USER_WRITER, definition))
655+
assertTrue(rbacTest.check(rbacSecurity, PERMISSION_WRITE, USER_WRITER, definition))
656656
}
657657

658658
@Test

0 commit comments

Comments
 (0)