Skip to content

Commit 0101898

Browse files
committed
feat(services): Do not sync permissions in OrganizationService
The synchronization of permissions in Keycloak when an organization is created or deleted is no longer needed for the new authorization component. The dependency to an `AuthorizationService` instance can be dropped. Signed-off-by: Oliver Heger <[email protected]>
1 parent 9f48492 commit 0101898

File tree

8 files changed

+13
-145
lines changed

8 files changed

+13
-145
lines changed

core/src/test/kotlin/api/DownloadsRouteIntegrationTest.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import kotlin.time.Duration.Companion.minutes
3434

3535
import kotlinx.datetime.Clock
3636

37-
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.service.KeycloakAuthorizationService
3837
import org.eclipse.apoapsis.ortserver.config.ConfigManager
3938
import org.eclipse.apoapsis.ortserver.model.OrtRun
4039
import org.eclipse.apoapsis.ortserver.model.RepositoryType
@@ -51,20 +50,10 @@ class DownloadsRouteIntegrationTest : AbstractIntegrationTest({
5150
var repositoryId = -1L
5251

5352
beforeEach {
54-
val authorizationService = KeycloakAuthorizationService(
55-
keycloakClient,
56-
dbExtension.db,
57-
dbExtension.fixtures.organizationRepository,
58-
dbExtension.fixtures.productRepository,
59-
dbExtension.fixtures.repositoryRepository,
60-
keycloakGroupPrefix = ""
61-
)
62-
6353
val organizationService = OrganizationService(
6454
dbExtension.db,
6555
dbExtension.fixtures.organizationRepository,
66-
dbExtension.fixtures.productRepository,
67-
authorizationService
56+
dbExtension.fixtures.productRepository
6857
)
6958

7059
val productService = ProductService(

core/src/test/kotlin/api/OrganizationsRouteIntegrationTest.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.roles.Or
7878
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.roles.ProductRole
7979
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.roles.Superuser
8080
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.service.AuthorizationService
81-
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.service.KeycloakAuthorizationService
8281
import org.eclipse.apoapsis.ortserver.core.SUPERUSER
8382
import org.eclipse.apoapsis.ortserver.core.TEST_USER
8483
import org.eclipse.apoapsis.ortserver.model.JobStatus
@@ -120,20 +119,10 @@ class OrganizationsRouteIntegrationTest : AbstractIntegrationTest({
120119
lateinit var productService: ProductService
121120

122121
beforeEach {
123-
authorizationService = KeycloakAuthorizationService(
124-
keycloakClient,
125-
dbExtension.db,
126-
dbExtension.fixtures.organizationRepository,
127-
dbExtension.fixtures.productRepository,
128-
dbExtension.fixtures.repositoryRepository,
129-
keycloakGroupPrefix = ""
130-
)
131-
132122
organizationService = OrganizationService(
133123
dbExtension.db,
134124
dbExtension.fixtures.organizationRepository,
135-
dbExtension.fixtures.productRepository,
136-
authorizationService
125+
dbExtension.fixtures.productRepository
137126
)
138127

139128
productService = ProductService(

core/src/test/kotlin/api/ProductsRouteIntegrationTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ class ProductsRouteIntegrationTest : AbstractIntegrationTest({
150150
organizationService = OrganizationService(
151151
dbExtension.db,
152152
dbExtension.fixtures.organizationRepository,
153-
dbExtension.fixtures.productRepository,
154-
authorizationService
153+
dbExtension.fixtures.productRepository
155154
)
156155

157156
pluginService = PluginService(dbExtension.db)

core/src/test/kotlin/api/RepositoriesRouteIntegrationTest.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.mapToMod
8484
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.permissions.RepositoryPermission
8585
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.roles.RepositoryRole
8686
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.service.AuthorizationService
87-
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.service.KeycloakAuthorizationService
8887
import org.eclipse.apoapsis.ortserver.components.pluginmanager.PluginOptionTemplate
8988
import org.eclipse.apoapsis.ortserver.components.pluginmanager.PluginService
9089
import org.eclipse.apoapsis.ortserver.components.pluginmanager.PluginType
@@ -127,20 +126,10 @@ class RepositoriesRouteIntegrationTest : AbstractIntegrationTest({
127126
var productId = -1L
128127

129128
beforeEach {
130-
authorizationService = KeycloakAuthorizationService(
131-
keycloakClient,
132-
dbExtension.db,
133-
dbExtension.fixtures.organizationRepository,
134-
dbExtension.fixtures.productRepository,
135-
dbExtension.fixtures.repositoryRepository,
136-
keycloakGroupPrefix = ""
137-
)
138-
139129
val organizationService = OrganizationService(
140130
dbExtension.db,
141131
dbExtension.fixtures.organizationRepository,
142-
dbExtension.fixtures.productRepository,
143-
authorizationService
132+
dbExtension.fixtures.productRepository
144133
)
145134

146135
pluginService = PluginService(dbExtension.db)

core/src/test/kotlin/api/RunsRouteIntegrationTest.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ import org.eclipse.apoapsis.ortserver.api.v1.model.VulnerabilityRating
8686
import org.eclipse.apoapsis.ortserver.api.v1.model.VulnerabilityWithDetails
8787
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.permissions.RepositoryPermission
8888
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.roles.Superuser
89-
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.service.KeycloakAuthorizationService
9089
import org.eclipse.apoapsis.ortserver.config.ConfigManager
9190
import org.eclipse.apoapsis.ortserver.dao.utils.toDatabasePrecision
9291
import org.eclipse.apoapsis.ortserver.logaccess.LogFileCriteria
@@ -150,20 +149,10 @@ class RunsRouteIntegrationTest : AbstractIntegrationTest({
150149
var repositoryId = -1L
151150

152151
beforeEach {
153-
val authorizationService = KeycloakAuthorizationService(
154-
keycloakClient,
155-
dbExtension.db,
156-
dbExtension.fixtures.organizationRepository,
157-
dbExtension.fixtures.productRepository,
158-
dbExtension.fixtures.repositoryRepository,
159-
keycloakGroupPrefix = ""
160-
)
161-
162152
organizationService = OrganizationService(
163153
dbExtension.db,
164154
dbExtension.fixtures.organizationRepository,
165-
dbExtension.fixtures.productRepository,
166-
authorizationService
155+
dbExtension.fixtures.productRepository
167156
)
168157

169158
productService = ProductService(

services/hierarchy/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dependencies {
3030

3131
api(libs.exposedCore)
3232

33-
implementation(projects.components.authorizationKeycloak.backend)
3433
implementation(projects.dao)
3534
implementation(projects.services.reportStorageService)
3635

services/hierarchy/src/main/kotlin/OrganizationService.kt

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
package org.eclipse.apoapsis.ortserver.services
2121

22-
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.service.AuthorizationService
2322
import org.eclipse.apoapsis.ortserver.dao.dbQuery
24-
import org.eclipse.apoapsis.ortserver.dao.dbQueryCatching
2523
import org.eclipse.apoapsis.ortserver.dao.repositories.product.ProductsTable
2624
import org.eclipse.apoapsis.ortserver.dao.repositories.repository.RepositoriesTable
2725
import org.eclipse.apoapsis.ortserver.model.Organization
@@ -34,66 +32,40 @@ import org.eclipse.apoapsis.ortserver.model.util.OptionalValue
3432

3533
import org.jetbrains.exposed.sql.Database
3634

37-
import org.slf4j.LoggerFactory
38-
39-
private val logger = LoggerFactory.getLogger(OrganizationService::class.java)
40-
4135
/**
4236
* A service providing functions for working with [organizations][Organization].
4337
*/
4438
class OrganizationService(
4539
private val db: Database,
4640
private val organizationRepository: OrganizationRepository,
47-
private val productRepository: ProductRepository,
48-
private val authorizationService: AuthorizationService
41+
private val productRepository: ProductRepository
4942
) {
5043
/**
5144
* Create an organization.
5245
*/
53-
suspend fun createOrganization(name: String, description: String?): Organization = db.dbQueryCatching {
46+
suspend fun createOrganization(name: String, description: String?): Organization = db.dbQuery {
5447
organizationRepository.create(name, description)
55-
}.onSuccess { organization ->
56-
runCatching {
57-
authorizationService.createOrganizationPermissions(organization.id)
58-
authorizationService.createOrganizationRoles(organization.id)
59-
}.onFailure { e ->
60-
logger.error("Error while creating Keycloak roles for organization '${organization.id}'.", e)
61-
}
62-
}.getOrThrow()
48+
}
6349

6450
/**
6551
* Create a product inside an [organization][organizationId].
6652
*/
67-
suspend fun createProduct(name: String, description: String?, organizationId: Long) = db.dbQueryCatching {
53+
suspend fun createProduct(name: String, description: String?, organizationId: Long) = db.dbQuery {
6854
productRepository.create(name, description, organizationId)
69-
}.onSuccess { product ->
70-
runCatching {
71-
authorizationService.createProductPermissions(product.id)
72-
authorizationService.createProductRoles(product.id)
73-
}.onFailure { e ->
74-
logger.error("Error while creating Keycloak roles for product '${product.id}'.", e)
75-
}
76-
}.getOrThrow()
55+
}
7756

7857
/**
7958
* Delete an organization by [organizationId].
8059
*/
81-
suspend fun deleteOrganization(organizationId: Long): Unit = db.dbQueryCatching {
60+
suspend fun deleteOrganization(organizationId: Long): Unit = db.dbQuery {
8261
if (productRepository.countForOrganization(organizationId) != 0L) {
8362
throw OrganizationNotEmptyException(
8463
"Cannot delete organization '$organizationId', as it still contains products."
8564
)
8665
}
8766

8867
organizationRepository.delete(organizationId)
89-
}.onSuccess {
90-
runCatching {
91-
authorizationService.deleteOrganizationPermissions(organizationId)
92-
authorizationService.deleteOrganizationRoles(organizationId)
93-
}.onFailure { e ->
94-
logger.error("Error while deleting Keycloak roles for organization '$organizationId'.", e)
95-
}
96-
}.getOrThrow()
68+
}
9769

9870
/**
9971
* Get an organization by [organizationId]. Returns null if the organization is not found.

services/hierarchy/src/test/kotlin/OrganizationServiceTest.kt

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ package org.eclipse.apoapsis.ortserver.services
2222
import io.kotest.core.spec.style.WordSpec
2323
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
2424

25-
import io.mockk.coEvery
26-
import io.mockk.coVerify
27-
import io.mockk.just
28-
import io.mockk.mockk
29-
import io.mockk.runs
30-
31-
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.service.AuthorizationService
3225
import org.eclipse.apoapsis.ortserver.dao.repositories.organization.DaoOrganizationRepository
3326
import org.eclipse.apoapsis.ortserver.dao.repositories.product.DaoProductRepository
3427
import org.eclipse.apoapsis.ortserver.dao.test.DatabaseTestExtension
@@ -51,60 +44,9 @@ class OrganizationServiceTest : WordSpec({
5144
fixtures = dbExtension.fixtures
5245
}
5346

54-
"createOrganization" should {
55-
"create Keycloak roles" {
56-
val authorizationService = mockk<AuthorizationService> {
57-
coEvery { createOrganizationPermissions(any()) } just runs
58-
coEvery { createOrganizationRoles(any()) } just runs
59-
}
60-
61-
val service = OrganizationService(db, organizationRepository, productRepository, authorizationService)
62-
val organization = service.createOrganization("name", "description")
63-
64-
coVerify(exactly = 1) {
65-
authorizationService.createOrganizationPermissions(organization.id)
66-
authorizationService.createOrganizationRoles(organization.id)
67-
}
68-
}
69-
}
70-
71-
"createProduct" should {
72-
"create Keycloak roles" {
73-
val authorizationService = mockk<AuthorizationService> {
74-
coEvery { createProductPermissions(any()) } just runs
75-
coEvery { createProductRoles(any()) } just runs
76-
}
77-
78-
val service = OrganizationService(db, organizationRepository, productRepository, authorizationService)
79-
val product = service.createProduct("name", "description", fixtures.organization.id)
80-
81-
coVerify(exactly = 1) {
82-
authorizationService.createProductPermissions(product.id)
83-
authorizationService.createProductRoles(product.id)
84-
}
85-
}
86-
}
87-
88-
"deleteOrganization" should {
89-
"delete Keycloak roles" {
90-
val authorizationService = mockk<AuthorizationService> {
91-
coEvery { deleteOrganizationPermissions(any()) } just runs
92-
coEvery { deleteOrganizationRoles(any()) } just runs
93-
}
94-
95-
val service = OrganizationService(db, organizationRepository, productRepository, authorizationService)
96-
service.deleteOrganization(fixtures.organization.id)
97-
98-
coVerify(exactly = 1) {
99-
authorizationService.deleteOrganizationPermissions(fixtures.organization.id)
100-
authorizationService.deleteOrganizationRoles(fixtures.organization.id)
101-
}
102-
}
103-
}
104-
10547
"getRepositoryIdsForOrganization" should {
10648
"return IDs for all repositories found in the products of the organization" {
107-
val service = OrganizationService(db, organizationRepository, productRepository, mockk())
49+
val service = OrganizationService(db, organizationRepository, productRepository)
10850

10951
val orgId = fixtures.createOrganization().id
11052

0 commit comments

Comments
 (0)