diff --git a/src/main/java/it/gov/pagopa/payhub/auth/service/TokenStoreService.java b/src/main/java/it/gov/pagopa/payhub/auth/service/TokenStoreService.java index b3787c11..a622c829 100644 --- a/src/main/java/it/gov/pagopa/payhub/auth/service/TokenStoreService.java +++ b/src/main/java/it/gov/pagopa/payhub/auth/service/TokenStoreService.java @@ -1,11 +1,9 @@ package it.gov.pagopa.payhub.auth.service; -import it.gov.pagopa.payhub.model.generated.AccessToken; - import java.util.Map; public interface TokenStoreService { - Map save(AccessToken accessToken, Map idTokenClaims); - Map load(AccessToken accessToken); - void delete(AccessToken accessToken); + Map save(String accessToken, Map idTokenClaims); + Map load(String accessToken); + void delete(String accessToken); } diff --git a/src/main/java/it/gov/pagopa/payhub/auth/service/TokenStoreServiceImpl.java b/src/main/java/it/gov/pagopa/payhub/auth/service/TokenStoreServiceImpl.java index 09c8f382..9592f8ee 100644 --- a/src/main/java/it/gov/pagopa/payhub/auth/service/TokenStoreServiceImpl.java +++ b/src/main/java/it/gov/pagopa/payhub/auth/service/TokenStoreServiceImpl.java @@ -1,7 +1,6 @@ package it.gov.pagopa.payhub.auth.service; import it.gov.pagopa.payhub.auth.configuration.RedisConfig; -import it.gov.pagopa.payhub.model.generated.AccessToken; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; @@ -15,19 +14,19 @@ class TokenStoreServiceImpl implements TokenStoreService{ @Override @CachePut - public Map save(AccessToken accessToken, Map idTokenClaims) { + public Map save(String accessToken, Map idTokenClaims) { return idTokenClaims; } @Override @Cacheable - public Map load(AccessToken accessToken) { + public Map load(String accessToken) { return null; } @Override @CacheEvict - public void delete(AccessToken accessToken) { + public void delete(String accessToken) { //Do Nothing } } diff --git a/src/main/java/it/gov/pagopa/payhub/auth/service/exchange/ExchangeTokenServiceImpl.java b/src/main/java/it/gov/pagopa/payhub/auth/service/exchange/ExchangeTokenServiceImpl.java index 63854215..464054c4 100644 --- a/src/main/java/it/gov/pagopa/payhub/auth/service/exchange/ExchangeTokenServiceImpl.java +++ b/src/main/java/it/gov/pagopa/payhub/auth/service/exchange/ExchangeTokenServiceImpl.java @@ -27,7 +27,7 @@ public AccessToken postToken(String clientId, String grantType, String subjectTo clientId, subjectTokenType, subjectIssuer, grantType, scope); Map claims = validateExternalTokenService.validate(clientId, grantType, subjectToken, subjectIssuer, subjectTokenType, scope); AccessToken accessToken = accessTokenBuilderService.build(); - tokenStoreService.save(accessToken, claims); + tokenStoreService.save(accessToken.getAccessToken(), claims); return accessToken; } } diff --git a/src/test/java/it/gov/pagopa/payhub/auth/service/TokenStoreServiceTest.java b/src/test/java/it/gov/pagopa/payhub/auth/service/TokenStoreServiceTest.java index 6ceab35e..482c6287 100644 --- a/src/test/java/it/gov/pagopa/payhub/auth/service/TokenStoreServiceTest.java +++ b/src/test/java/it/gov/pagopa/payhub/auth/service/TokenStoreServiceTest.java @@ -1,6 +1,5 @@ package it.gov.pagopa.payhub.auth.service; -import it.gov.pagopa.payhub.model.generated.AccessToken; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -15,7 +14,7 @@ class TokenStoreServiceTest { void givenClaimsWhenSaveThenReturnThem(){ // Given HashMap idTokenClaims = new HashMap<>(); - AccessToken accessToken = new AccessToken(); + String accessToken = "AccessToken"; // When Map result = service.save(accessToken, idTokenClaims); @@ -27,7 +26,7 @@ void givenClaimsWhenSaveThenReturnThem(){ @Test void givenAccessTokenWhenSaveThenNull(){ // Given - AccessToken accessToken = new AccessToken(); + String accessToken = "AccessToken"; // When Map result = service.load(accessToken); diff --git a/src/test/java/it/gov/pagopa/payhub/auth/service/exchange/ExchangeTokenServiceTest.java b/src/test/java/it/gov/pagopa/payhub/auth/service/exchange/ExchangeTokenServiceTest.java index 0f1ba2ff..313e2be5 100644 --- a/src/test/java/it/gov/pagopa/payhub/auth/service/exchange/ExchangeTokenServiceTest.java +++ b/src/test/java/it/gov/pagopa/payhub/auth/service/exchange/ExchangeTokenServiceTest.java @@ -53,7 +53,7 @@ void givenValidTokenWhenPostTokenThenSuccess(){ Mockito.when(validateExternalTokenServiceMock.validate(clientId, grantType, subjectToken, subjectIssuer, subjectTokenType, scope)) .thenReturn(expectedClaims); - AccessToken expectedAccessToken = new AccessToken(); + AccessToken expectedAccessToken = AccessToken.builder().accessToken("accessToken").build(); Mockito.when(accessTokenBuilderServiceMock.build()) .thenReturn(expectedAccessToken); @@ -62,6 +62,6 @@ void givenValidTokenWhenPostTokenThenSuccess(){ // Then Assertions.assertSame(expectedAccessToken, result); - Mockito.verify(tokenStoreServiceMock).save(Mockito.same(expectedAccessToken), Mockito.same(expectedClaims)); + Mockito.verify(tokenStoreServiceMock).save(Mockito.same(expectedAccessToken.getAccessToken()), Mockito.same(expectedClaims)); } }