diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/CredentialsRoleRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/CredentialsRoleRepository.kt index d3b724d3..778143b9 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/CredentialsRoleRepository.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/CredentialsRoleRepository.kt @@ -3,5 +3,5 @@ package com.izivia.ocpi.toolkit.modules.credentials.repositories import com.izivia.ocpi.toolkit.modules.credentials.domain.CredentialRole interface CredentialsRoleRepository { - suspend fun getCredentialsRoles(): List + suspend fun getCredentialsRoles(partnerId: String): List } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt index c05cc172..a92a0375 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt @@ -99,7 +99,7 @@ open class CredentialsClientService( credentials = Credentials( token = serverToken, url = clientVersionsEndpointUrl, - roles = clientCredentialsRoleRepository.getCredentialsRoles(), + roles = clientCredentialsRoleRepository.getCredentialsRoles(partnerId), ), debugHeaders = emptyMap(), ).let { @@ -148,7 +148,7 @@ open class CredentialsClientService( credentials = Credentials( token = credentialsServerToken, url = clientVersionsEndpointUrl, - roles = clientCredentialsRoleRepository.getCredentialsRoles(), + roles = clientCredentialsRoleRepository.getCredentialsRoles(partnerId), ), debugHeaders = emptyMap(), ).let { diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt index bd4b4e74..88717b62 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt @@ -5,7 +5,9 @@ import com.izivia.ocpi.toolkit.modules.credentials.CredentialsInterface import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials import com.izivia.ocpi.toolkit.modules.credentials.repositories.CredentialsRoleRepository import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.* +import com.izivia.ocpi.toolkit.modules.versions.domain.Version +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails +import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber import com.izivia.ocpi.toolkit.transport.TransportClientBuilder import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpRequest @@ -24,6 +26,8 @@ open class CredentialsServerService( ): OcpiResponseBody = OcpiResponseBody.of { getCredentials( serverToken = token, + partnerRepository.getPartnerIdByCredentialsServerToken(token) + ?: throw OcpiClientInvalidParametersException("Invalid ServerToken ($token)"), ) } @@ -36,7 +40,7 @@ open class CredentialsServerService( // It can happen when a partner unregister, then registers with its clientToken (which is the serverToken // for us) val partnerId = partnerRepository.getPartnerIdByCredentialsServerToken(token) - // If we could not find a partner with this serverToken, then, it means that it's probably a tokenA + // If we could not find a partner with this serverToken, then, it means that it's probably a tokenA ?: partnerRepository.getPartnerIdByCredentialsTokenA(credentialsTokenA = token) ?: throw OcpiClientInvalidParametersException( "Invalid token ($token) - should be either a TokenA or a ServerToken", @@ -70,6 +74,7 @@ open class CredentialsServerService( partnerId = partnerId, credentialsServerToken = generateUUIDv4Token(), ), + partnerId = partnerId, ) } @@ -109,6 +114,7 @@ open class CredentialsServerService( partnerId = partnerId, credentialsServerToken = generateUUIDv4Token(), ), + partnerId = partnerId, ) } @@ -218,9 +224,9 @@ open class CredentialsServerService( partnerRepository.saveEndpoints(partnerId = partnerId, endpoints = versionDetail.endpoints) } - private suspend fun getCredentials(serverToken: String): Credentials = Credentials( + private suspend fun getCredentials(serverToken: String, partnerId: String): Credentials = Credentials( token = serverToken, url = serverVersionsUrlProvider(), - roles = credentialsRoleRepository.getCredentialsRoles(), + roles = credentialsRoleRepository.getCredentialsRoles(partnerId), ) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt index 4fccd2fd..253aae0c 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt @@ -42,7 +42,7 @@ fun main() { service = CredentialsServerService( partnerRepository = receiverPlatformRepository, credentialsRoleRepository = object : CredentialsRoleRepository { - override suspend fun getCredentialsRoles(): List = listOf( + override suspend fun getCredentialsRoles(partnerId: String): List = listOf( CredentialRole( role = Role.EMSP, businessDetails = BusinessDetails(name = "Receiver", website = null, logo = null), diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt index d55a53f6..6bfe13ff 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt @@ -58,7 +58,7 @@ fun main() { clientPartnerRepository = senderPlatformRepository, clientVersionsRepository = senderVersionsRepository, clientCredentialsRoleRepository = object : CredentialsRoleRepository { - override suspend fun getCredentialsRoles(): List = listOf( + override suspend fun getCredentialsRoles(partnerId: String): List = listOf( CredentialRole( role = Role.CPO, businessDetails = BusinessDetails(name = "Sender", website = null, logo = null), diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt index eab98715..6b6e2f9e 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt @@ -65,7 +65,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { service = CredentialsServerService( partnerRepository = receiverPlatformRepo, credentialsRoleRepository = object : CredentialsRoleRepository { - override suspend fun getCredentialsRoles(): List = listOf( + override suspend fun getCredentialsRoles(partnerId: String): List = listOf( CredentialRole( role = Role.EMSP, businessDetails = BusinessDetails(name = "Receiver", website = null, logo = null), @@ -135,7 +135,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { clientPartnerRepository = PartnerMongoRepository(collection = senderServerSetupResult.partnerCollection), clientVersionsRepository = VersionsCacheRepository(baseUrl = senderServerSetupResult.transport.baseUrl), clientCredentialsRoleRepository = object : CredentialsRoleRepository { - override suspend fun getCredentialsRoles(): List = listOf( + override suspend fun getCredentialsRoles(partnerId: String): List = listOf( CredentialRole( role = Role.CPO, businessDetails = BusinessDetails(name = "Sender", website = null, logo = null),