diff --git a/esignet-core/src/main/java/io/mosip/esignet/core/dto/OIDCTransaction.java b/esignet-core/src/main/java/io/mosip/esignet/core/dto/OIDCTransaction.java index c680194ed..5a94b32d5 100644 --- a/esignet-core/src/main/java/io/mosip/esignet/core/dto/OIDCTransaction.java +++ b/esignet-core/src/main/java/io/mosip/esignet/core/dto/OIDCTransaction.java @@ -60,4 +60,5 @@ public class OIDCTransaction implements Serializable { //PKCE support ProofKeyCodeExchange proofKeyCodeExchange; List requestedCredentialScopes; + List claimStatuses; } diff --git a/esignet-core/src/main/java/io/mosip/esignet/core/spi/AuthorizationService.java b/esignet-core/src/main/java/io/mosip/esignet/core/spi/AuthorizationService.java index e378e12f2..695a17c00 100644 --- a/esignet-core/src/main/java/io/mosip/esignet/core/spi/AuthorizationService.java +++ b/esignet-core/src/main/java/io/mosip/esignet/core/spi/AuthorizationService.java @@ -80,4 +80,11 @@ public interface AuthorizationService { * @return */ SignupRedirectResponse prepareSignupRedirect(SignupRedirectRequest signupRedirectRequest, HttpServletResponse response); + + /** + * Get the ClaimStatus and check the consent Action + * @param transactionId + * @return + */ + ConsentDetailResponse getConsentDetails(String transactionId); } diff --git a/esignet-service/src/test/java/io/mosip/esignet/controllers/AuthorizationControllerTest.java b/esignet-service/src/test/java/io/mosip/esignet/controllers/AuthorizationControllerTest.java index 0e2b69e66..b46091937 100644 --- a/esignet-service/src/test/java/io/mosip/esignet/controllers/AuthorizationControllerTest.java +++ b/esignet-service/src/test/java/io/mosip/esignet/controllers/AuthorizationControllerTest.java @@ -41,6 +41,7 @@ import static io.mosip.esignet.core.constants.Constants.UTC_DATETIME_PATTERN; import static io.mosip.esignet.core.constants.ErrorConstants.*; import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -1140,4 +1141,11 @@ public void getAuthorizationCode_withInValidPermittedAuthorizeScopes_thenErrorRe .andExpect(jsonPath("$.errors[0].errorCode").value(ErrorConstants.INVALID_PERMITTED_SCOPE)); } + @Test + public void getConsentDetails_withValidDetails_thenSuccessResposne() throws Exception { + mockMvc.perform(get("/authorization/consent-details").header("oauth-details-key", "1234567890")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.response.consentAction").value("CAPTURE")); + } + } \ No newline at end of file diff --git a/oidc-service-impl/src/main/java/io/mosip/esignet/services/AuthorizationServiceImpl.java b/oidc-service-impl/src/main/java/io/mosip/esignet/services/AuthorizationServiceImpl.java index a0c0f11bd..f4acb203d 100644 --- a/oidc-service-impl/src/main/java/io/mosip/esignet/services/AuthorizationServiceImpl.java +++ b/oidc-service-impl/src/main/java/io/mosip/esignet/services/AuthorizationServiceImpl.java @@ -245,6 +245,20 @@ public AuthCodeResponse getAuthCode(AuthCodeRequest authCodeRequest) throws Esig return authCodeResponse; } + @Override + public ConsentDetailResponse getConsentDetails(String transactionId) { + OIDCTransaction transaction = cacheUtilService.getAuthenticatedTransaction(transactionId); + if(transaction == null) { + throw new InvalidTransactionException(); + } + ConsentDetailResponse consentDetailResponse=new ConsentDetailResponse(); + consentDetailResponse.setConsentAction(transaction.getConsentAction()); + consentDetailResponse.setTransactionId(transactionId); + consentDetailResponse.setClaimStatus(transaction.getClaimStatuses()); + return consentDetailResponse; + } + + private OIDCTransaction authenticate(AuthRequest authRequest, boolean checkConsentAction) { OIDCTransaction transaction = cacheUtilService.getPreAuthTransaction(authRequest.getTransactionId()); if(transaction == null) diff --git a/oidc-service-impl/src/main/java/io/mosip/esignet/services/ConsentHelperService.java b/oidc-service-impl/src/main/java/io/mosip/esignet/services/ConsentHelperService.java index 774a8b193..224adc26d 100644 --- a/oidc-service-impl/src/main/java/io/mosip/esignet/services/ConsentHelperService.java +++ b/oidc-service-impl/src/main/java/io/mosip/esignet/services/ConsentHelperService.java @@ -86,7 +86,6 @@ public void processConsent(OIDCTransaction transaction, boolean linked) { } } - public void updateUserConsent(OIDCTransaction transaction, String signature) { if(ConsentAction.NOCAPTURE.equals(transaction.getConsentAction()) && transaction.getEssentialClaims().isEmpty() diff --git a/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationServiceTest.java b/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationServiceTest.java index 8f2c7e931..f103003bd 100644 --- a/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationServiceTest.java +++ b/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationServiceTest.java @@ -13,10 +13,12 @@ import io.mosip.esignet.api.exception.KycAuthException; import io.mosip.esignet.api.spi.AuditPlugin; import io.mosip.esignet.api.spi.Authenticator; +import io.mosip.esignet.api.util.ConsentAction; import io.mosip.esignet.core.constants.Constants; import io.mosip.esignet.core.dto.*; import io.mosip.esignet.core.exception.EsignetException; import io.mosip.esignet.core.exception.InvalidClientException; +import io.mosip.esignet.core.exception.InvalidTransactionException; import io.mosip.esignet.core.spi.ClientManagementService; import io.mosip.esignet.core.util.AuthenticationContextClassRefUtil; import io.mosip.esignet.core.constants.ErrorConstants; @@ -1004,6 +1006,32 @@ public void getAuthCode_withValidInput_thenPass() { Assert.assertEquals(authorizationServiceImpl.getAuthCode(authCodeRequest).getState(), "test-state"); } + @Test + public void getConsentDetails_withValidTransaction_thenPass(){ + OIDCTransaction transaction=new OIDCTransaction(); + ClaimStatus claimStatus=new ClaimStatus(); + claimStatus.setClaim("email"); + claimStatus.setVerified(true); + claimStatus.setAvailable(true); + transaction.setClaimStatuses(List.of(claimStatus)); + transaction.setConsentAction(ConsentAction.NOCAPTURE); + Mockito.when(cacheUtilService.getAuthenticatedTransaction(Mockito.anyString())).thenReturn(transaction); + + ConsentDetailResponse consentDetailResponse = authorizationServiceImpl.getConsentDetails("transactionId"); + Assert.assertEquals(consentDetailResponse.getConsentAction(),ConsentAction.NOCAPTURE); + Assert.assertEquals(consentDetailResponse.getTransactionId(),"transactionId"); + } + + @Test + public void getConsentDetails_withInvalidTransaction_thenFail(){ + Mockito.when(cacheUtilService.getAuthenticatedTransaction(Mockito.anyString())).thenReturn(null); + try{ + authorizationServiceImpl.getConsentDetails("transactionId"); + }catch (InvalidTransactionException ex){ + Assert.assertEquals(ex.getErrorCode(),ErrorConstants.INVALID_TRANSACTION); + } + } + private OIDCTransaction createIdpTransaction(String[] acrs) { OIDCTransaction oidcTransaction = new OIDCTransaction(); Map idClaims = new HashMap<>(); diff --git a/oidc-service-impl/src/test/java/io/mosip/esignet/services/ConsentHelperServiceTest.java b/oidc-service-impl/src/test/java/io/mosip/esignet/services/ConsentHelperServiceTest.java index 0b836fdc6..4f0784c9c 100644 --- a/oidc-service-impl/src/test/java/io/mosip/esignet/services/ConsentHelperServiceTest.java +++ b/oidc-service-impl/src/test/java/io/mosip/esignet/services/ConsentHelperServiceTest.java @@ -458,7 +458,6 @@ public void processConsent_withInvalidSignature_thenFail(){ consentDetail.setSignature("haa.naa"); Mockito.when(consentService.getUserConsent(userConsentRequest)).thenReturn(Optional.of(consentDetail)); - try{ consentHelperService.processConsent(oidcTransaction,true); Assert.fail(); @@ -482,6 +481,7 @@ public void processConsent_withEmptyRequestedClaims_thenPass(){ Assert.assertEquals(oidcTransaction.getConsentAction(),ConsentAction.NOCAPTURE); } + private String generateSignature(Map payloadMap) throws Exception { // Define the header and payload