Skip to content

Commit fa5839a

Browse files
apply corrections from pull request feedbacks
1 parent 1c81fd0 commit fa5839a

File tree

15 files changed

+24
-38
lines changed

15 files changed

+24
-38
lines changed

common/src/main/kotlin/com/cosmotech/common/config/CsmPlatformProperties.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ data class CsmPlatformProperties(
7474
val mailJwtClaim: String = "preferred_username",
7575

7676
/** The JWT Claim where the groups information are stored */
77-
val groupJwtClaim: String = "user_groups",
77+
val groupJwtClaim: String = "groups",
7878

7979
/** The JWT Claim where the roles information is stored */
8080
val rolesJwtClaim: String = "roles",

common/src/main/kotlin/com/cosmotech/common/rbac/CsmRbac.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ open class CsmRbac(
198198
} else {
199199
groups.any {
200200
this.getEntityRole(rbacSecurity, it) == this.getAdminRole(rolesDefinition)
201-
} ||
202-
this.getEntityRole(rbacSecurity, rbacSecurity.default) ==
203-
this.getAdminRole(rolesDefinition)
201+
} || rbacSecurity.default == this.getAdminRole(rolesDefinition)
204202
}
205203
logger.debug("RBAC ${rbacSecurity.id} - $user has default admin rbac role: $isAdmin")
206204
return isAdmin
@@ -220,9 +218,7 @@ open class CsmRbac(
220218
} else {
221219
groups.any {
222220
verifyPermissionFromRole(permission, getEntityRole(rbacSecurity, it), rolesDefinition)
223-
} ||
224-
verifyPermissionFromRole(
225-
permission, getEntityRole(rbacSecurity, rbacSecurity.default), rolesDefinition)
221+
} || verifyPermissionFromRole(permission, rbacSecurity.default, rolesDefinition)
226222
}
227223
logger.debug("RBAC ${rbacSecurity.id} - $user has permission $permission in ACL: $isAuthorized")
228224
return isAuthorized

common/src/main/kotlin/com/cosmotech/common/utils/SecurityUtils.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ fun getCurrentAccountIdentifier(configuration: CsmPlatformProperties): String {
5656
}
5757

5858
fun getCurrentAccountGroups(configuration: CsmPlatformProperties): List<String> {
59-
val authentication = getCurrentAuthentication()
60-
val jwt = (authentication as JwtAuthenticationToken).token.tokenValue
61-
val jwtClaimsSet = JWTParser.parse(jwt).jwtClaimsSet
62-
return jwtClaimsSet.getListClaim(configuration.authorization.groupJwtClaim).toList()
63-
as List<String>
59+
return (getValueFromAuthenticatedToken(configuration) {
60+
try {
61+
val jwt = JWTParser.parse(it)
62+
jwt.jwtClaimsSet.getStringListClaim(configuration.authorization.groupJwtClaim)
63+
} catch (e: ParseException) {
64+
JSONObjectUtils.parse(it)[configuration.authorization.groupJwtClaim] as List<String>
65+
}
66+
} ?: emptyList())
6467
}
6568

6669
fun getCurrentAuthenticatedRoles(configuration: CsmPlatformProperties): List<String> {

dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceIntegrationTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class DatasetServiceIntegrationTest() : CsmTestBase() {
9696
val UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME = "wrong_mimetype.yaml"
9797
val INVENTORY_SOURCE_FILE_NAME = "product_inventory.csv"
9898
val WRONG_ORIGINAL_FILE_NAME = "../../wrong_name_pattern.csv"
99-
val defaultGroup = listOf("myTestGroup")
10099

101100
private val logger = LoggerFactory.getLogger(DatasetServiceIntegrationTest::class.java)
102101

@@ -121,7 +120,7 @@ class DatasetServiceIntegrationTest() : CsmTestBase() {
121120
fun setUp() {
122121
mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt")
123122
every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER
124-
every { getCurrentAccountGroups(any()) } returns defaultGroup
123+
every { getCurrentAccountGroups(any()) } returns listOf("myTestGroup")
125124
every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns "test.user"
126125
every { getCurrentAuthenticatedRoles(any()) } returns listOf("user")
127126

dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceRBACTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class DatasetServiceRBACTest : CsmTestBase() {
8686
val CONNECTED_ADMIN_USER = "test.admin@cosmotech.com"
8787
val CONNECTED_DEFAULT_USER = "test.user@cosmotech.com"
8888
val CUSTOMER_SOURCE_FILE_NAME = "customers.csv"
89-
val defaultGroup = listOf("myTestGroup")
9089

9190
private val logger = LoggerFactory.getLogger(DatasetServiceIntegrationTest::class.java)
9291

@@ -112,7 +111,7 @@ class DatasetServiceRBACTest : CsmTestBase() {
112111
fun setUp() {
113112
mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt")
114113
every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER
115-
every { getCurrentAccountGroups(any()) } returns defaultGroup
114+
every { getCurrentAccountGroups(any()) } returns listOf("myTestGroup")
116115
every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns "test.user"
117116
every { getCurrentAuthenticatedRoles(any()) } returns listOf("user")
118117

organization/src/integrationTest/kotlin/com/cosmotech/organization/service/OrganizationServiceRBACTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import org.springframework.test.context.junit4.SpringRunner
5555
class OrganizationServiceRBACTest : CsmTestBase() {
5656
val CONNECTED_ADMIN_USER = "test.admin@cosmotech.com"
5757
val TEST_USER_MAIL = "testuser@mail.fr"
58-
val defaultGroup = listOf("myTestGroup")
5958

6059
// NEEDED: recreate indexes in redis
6160
@Autowired lateinit var rediSearchIndexer: RediSearchIndexer
@@ -71,7 +70,7 @@ class OrganizationServiceRBACTest : CsmTestBase() {
7170
fun setUp() {
7271
mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt")
7372
every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL
74-
every { getCurrentAccountGroups(any()) } returns defaultGroup
73+
every { getCurrentAccountGroups(any()) } returns listOf("myTestGroup")
7574
every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns "my.account-tester"
7675
every { getCurrentAuthenticatedRoles(any()) } returns listOf()
7776
rediSearchIndexer.createIndexFor(Organization::class.java)

organization/src/test/kotlin/com/cosmotech/organization/service/OrganizationServiceImplTests.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ const val USER_ID = "bob@mycompany.com"
5151
@ExtendWith(MockKExtension::class)
5252
class OrganizationServiceImplTests {
5353

54-
val defaultGroup = listOf("myTestGroup")
55-
5654
@Suppress("unused") @MockK private var eventPublisher: CsmEventPublisher = mockk(relaxed = true)
5755

5856
@Suppress("unused")
@@ -70,7 +68,7 @@ class OrganizationServiceImplTests {
7068

7169
mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt")
7270
every { getCurrentAccountIdentifier(any()) } returns USER_ID
73-
every { getCurrentAccountGroups(any()) } returns defaultGroup
71+
every { getCurrentAccountGroups(any()) } returns listOf("myTestGroup")
7472
every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns "my.account-tester"
7573
every { getCurrentAuthenticatedRoles(any()) } returns listOf()
7674

run/src/integrationTest/kotlin/com/cosmotech/run/service/RunServiceIntegrationTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class RunServiceIntegrationTest : CsmTestBase() {
8282

8383
val CONNECTED_ADMIN_USER = "test.admin@cosmotech.com"
8484
val CONNECTED_READER_USER = "test.user@cosmotech.com"
85-
val defaultGroup = listOf("myTestGroup")
8685
private val logger = LoggerFactory.getLogger(RunServiceIntegrationTest::class.java)
8786

8887
@MockK(relaxed = true) private lateinit var containerFactory: RunContainerFactory
@@ -115,7 +114,7 @@ class RunServiceIntegrationTest : CsmTestBase() {
115114
fun setUp() {
116115
mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt")
117116
every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER
118-
every { getCurrentAccountGroups(any()) } returns defaultGroup
117+
every { getCurrentAccountGroups(any()) } returns listOf("myTestGroup")
119118
every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns "test.user"
120119
every { getCurrentAuthenticatedRoles(any()) } returns listOf("user")
121120

runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceIntegrationTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class RunnerServiceIntegrationTest : CsmTestBase() {
9292
val TEST_USER_MAIL = "fake@mail.fr"
9393
val CUSTOMERS_FILE_NAME = "customers.csv"
9494
val CUSTOMERS_5_LINES_FILE_NAME = "customers_5_lines.csv"
95-
val defaultGroup = listOf("myTestGroup")
9695

9796
private val logger = LoggerFactory.getLogger(RunnerServiceIntegrationTest::class.java)
9897
private val defaultName = "my.account-tester@cosmotech.com"
@@ -144,7 +143,7 @@ class RunnerServiceIntegrationTest : CsmTestBase() {
144143
every { containerRegistryService.getImageLabel(any(), any(), any()) } returns null
145144
mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt")
146145
every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER
147-
every { getCurrentAccountGroups(any()) } returns defaultGroup
146+
every { getCurrentAccountGroups(any()) } returns listOf("myTestGroup")
148147
every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns "test.user"
149148
every { getCurrentAuthenticatedRoles(any()) } returns listOf(ROLE_ORGANIZATION_USER)
150149

runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceRBACTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class RunnerServiceRBACTest : CsmTestBase() {
8383

8484
val CONNECTED_ADMIN_USER = "test.admin@cosmotech.com"
8585
val TEST_USER_MAIL = "testuser@mail.fr"
86-
val defaultGroup = listOf("myTestGroup")
8786

8887
@Autowired lateinit var rediSearchIndexer: RediSearchIndexer
8988
@Autowired lateinit var organizationApiService: OrganizationApiServiceInterface
@@ -99,7 +98,7 @@ class RunnerServiceRBACTest : CsmTestBase() {
9998
fun setUp() {
10099
mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt")
101100
every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER
102-
every { getCurrentAccountGroups(any()) } returns defaultGroup
101+
every { getCurrentAccountGroups(any()) } returns listOf("myTestGroup")
103102
every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns "test.user"
104103
every { getCurrentAuthenticatedRoles(any()) } returns listOf()
105104

0 commit comments

Comments
 (0)