Skip to content

Commit 9f48492

Browse files
committed
feat(services): Do not sync permissions in ProductService
The synchronization of permissions in Keycloak when a product 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 28af20e commit 9f48492

File tree

7 files changed

+11
-84
lines changed

7 files changed

+11
-84
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ class DownloadsRouteIntegrationTest : AbstractIntegrationTest({
7171
dbExtension.db,
7272
dbExtension.fixtures.productRepository,
7373
dbExtension.fixtures.repositoryRepository,
74-
dbExtension.fixtures.ortRunRepository,
75-
authorizationService
74+
dbExtension.fixtures.ortRunRepository
7675
)
7776

7877
val orgId = organizationService.createOrganization(name = "name", description = "description").id

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ class OrganizationsRouteIntegrationTest : AbstractIntegrationTest({
140140
dbExtension.db,
141141
dbExtension.fixtures.productRepository,
142142
dbExtension.fixtures.repositoryRepository,
143-
dbExtension.fixtures.ortRunRepository,
144-
authorizationService
143+
dbExtension.fixtures.ortRunRepository
145144
)
146145
}
147146

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ class ProductsRouteIntegrationTest : AbstractIntegrationTest({
160160
dbExtension.db,
161161
dbExtension.fixtures.productRepository,
162162
dbExtension.fixtures.repositoryRepository,
163-
dbExtension.fixtures.ortRunRepository,
164-
authorizationService
163+
dbExtension.fixtures.ortRunRepository
165164
)
166165

167166
orgId = organizationService.createOrganization(name = "name", description = "description").id

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ class RepositoriesRouteIntegrationTest : AbstractIntegrationTest({
149149
dbExtension.db,
150150
dbExtension.fixtures.productRepository,
151151
dbExtension.fixtures.repositoryRepository,
152-
dbExtension.fixtures.ortRunRepository,
153-
authorizationService
152+
dbExtension.fixtures.ortRunRepository
154153
)
155154

156155
ortRunRepository = dbExtension.fixtures.ortRunRepository

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ class RunsRouteIntegrationTest : AbstractIntegrationTest({
170170
dbExtension.db,
171171
dbExtension.fixtures.productRepository,
172172
dbExtension.fixtures.repositoryRepository,
173-
dbExtension.fixtures.ortRunRepository,
174-
authorizationService
173+
dbExtension.fixtures.ortRunRepository
175174
)
176175

177176
ortRunRepository = dbExtension.fixtures.ortRunRepository

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

Lines changed: 4 additions & 25 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.ortrun.OrtRunsTable
2624
import org.eclipse.apoapsis.ortserver.dao.repositories.repository.RepositoriesTable
2725
import org.eclipse.apoapsis.ortserver.model.OrtRun
@@ -42,10 +40,6 @@ import org.jetbrains.exposed.sql.SortOrder
4240
import org.jetbrains.exposed.sql.and
4341
import org.jetbrains.exposed.sql.max
4442

45-
import org.slf4j.LoggerFactory
46-
47-
private val logger = LoggerFactory.getLogger(OrganizationService::class.java)
48-
4943
/**
5044
* A service providing functions for working with [products][Product].
5145
*/
@@ -54,7 +48,6 @@ class ProductService(
5448
private val productRepository: ProductRepository,
5549
private val repositoryRepository: RepositoryRepository,
5650
private val ortRunRepository: OrtRunRepository,
57-
private val authorizationService: AuthorizationService
5851
) {
5952
/**
6053
* Create a repository inside a [product][productId].
@@ -64,33 +57,19 @@ class ProductService(
6457
url: String,
6558
productId: Long,
6659
description: String?
67-
): Repository = db.dbQueryCatching {
60+
): Repository = db.dbQuery {
6861
repositoryRepository.create(type, url, productId, description)
69-
}.onSuccess { repository ->
70-
runCatching {
71-
authorizationService.createRepositoryPermissions(repository.id)
72-
authorizationService.createRepositoryRoles(repository.id)
73-
}.onFailure { e ->
74-
logger.error("Error while creating Keycloak roles for repository '${repository.id}'.", e)
75-
}
76-
}.getOrThrow()
62+
}
7763

7864
/**
7965
* Delete a [product][productId] with its [repositories][Repository] and [OrtRun]s.
8066
*/
81-
suspend fun deleteProduct(productId: Long): Unit = db.dbQueryCatching {
67+
suspend fun deleteProduct(productId: Long): Unit = db.dbQuery {
8268
ortRunRepository.deleteByProduct(productId)
8369
repositoryRepository.deleteByProduct(productId)
8470

8571
productRepository.delete(productId)
86-
}.onSuccess {
87-
runCatching {
88-
authorizationService.deleteProductPermissions(productId)
89-
authorizationService.deleteProductRoles(productId)
90-
}.onFailure { e ->
91-
logger.error("Error while deleting Keycloak roles for product '$productId'.", e)
92-
}
93-
}.getOrThrow()
72+
}
9473

9574
/**
9675
* Get a product by [productId]. Returns null if the product is not found.

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

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,11 @@ import io.kotest.core.spec.style.WordSpec
2323
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
2424
import io.kotest.matchers.shouldBe
2525

26-
import io.mockk.coEvery
27-
import io.mockk.coVerify
28-
import io.mockk.just
29-
import io.mockk.mockk
30-
import io.mockk.runs
31-
32-
import org.eclipse.apoapsis.ortserver.components.authorization.keycloak.service.AuthorizationService
3326
import org.eclipse.apoapsis.ortserver.dao.repositories.ortrun.DaoOrtRunRepository
3427
import org.eclipse.apoapsis.ortserver.dao.repositories.product.DaoProductRepository
3528
import org.eclipse.apoapsis.ortserver.dao.repositories.repository.DaoRepositoryRepository
3629
import org.eclipse.apoapsis.ortserver.dao.test.DatabaseTestExtension
3730
import org.eclipse.apoapsis.ortserver.dao.test.Fixtures
38-
import org.eclipse.apoapsis.ortserver.model.RepositoryType
3931

4032
import org.jetbrains.exposed.sql.Database
4133

@@ -56,48 +48,9 @@ class ProductServiceTest : WordSpec({
5648
fixtures = dbExtension.fixtures
5749
}
5850

59-
"createRepository" should {
60-
"create Keycloak permissions" {
61-
val authorizationService = mockk<AuthorizationService> {
62-
coEvery { createRepositoryPermissions(any()) } just runs
63-
coEvery { createRepositoryRoles(any()) } just runs
64-
}
65-
66-
val service =
67-
ProductService(db, productRepository, repositoryRepository, ortRunRepository, authorizationService)
68-
val repository = service.createRepository(
69-
RepositoryType.GIT,
70-
"https://example.com/repo.git",
71-
fixtures.product.id,
72-
"Description"
73-
)
74-
75-
coVerify(exactly = 1) {
76-
authorizationService.createRepositoryPermissions(repository.id)
77-
authorizationService.createRepositoryRoles(repository.id)
78-
}
79-
}
80-
}
81-
8251
"deleteProduct" should {
83-
"delete Keycloak permissions" {
84-
val authorizationService = mockk<AuthorizationService> {
85-
coEvery { deleteProductPermissions(any()) } just runs
86-
coEvery { deleteProductRoles(any()) } just runs
87-
}
88-
89-
val service =
90-
ProductService(db, productRepository, repositoryRepository, ortRunRepository, authorizationService)
91-
service.deleteProduct(fixtures.product.id)
92-
93-
coVerify(exactly = 1) {
94-
authorizationService.deleteProductPermissions(fixtures.product.id)
95-
authorizationService.deleteProductRoles(fixtures.product.id)
96-
}
97-
}
98-
9952
"delete all repositories associated to this product" {
100-
val service = ProductService(db, productRepository, repositoryRepository, ortRunRepository, mockk())
53+
val service = ProductService(db, productRepository, repositoryRepository, ortRunRepository)
10154

10255
val product = fixtures.createProduct()
10356

@@ -123,7 +76,7 @@ class ProductServiceTest : WordSpec({
12376

12477
"getRepositoryIdsForProduct" should {
12578
"return IDs for all repositories of a product" {
126-
val service = ProductService(db, productRepository, repositoryRepository, ortRunRepository, mockk())
79+
val service = ProductService(db, productRepository, repositoryRepository, ortRunRepository)
12780

12881
val prodId = fixtures.createProduct().id
12982

0 commit comments

Comments
 (0)