From d4c00f689031ac67621582797ee4736dd2668b08 Mon Sep 17 00:00:00 2001 From: Anusha Sunkada Date: Mon, 9 Oct 2023 15:09:56 +0530 Subject: [PATCH] ES-328 (#434) * ES-4 (#432) Co-authored-by: ase-101 <> * ES-328 --------- Co-authored-by: ase-101 <> --- .../services/ClientManagementServiceImpl.java | 4 ++-- .../mosip/esignet/ClientManagementServiceTest.java | 8 ++++---- .../esignet/core/spi/ClientManagementService.java | 4 ++-- .../controllers/ClientManagementController.java | 12 ++++++------ .../src/main/resources/application-dev.properties | 6 +++--- .../src/main/resources/application-local.properties | 6 +++--- esignet-service/src/main/resources/logback.xml | 11 +++++++++++ .../ClientMgmtControllerParameterizedTest.java | 4 ++-- 8 files changed, 33 insertions(+), 22 deletions(-) create mode 100644 esignet-service/src/main/resources/logback.xml diff --git a/client-management-service-impl/src/main/java/io/mosip/esignet/services/ClientManagementServiceImpl.java b/client-management-service-impl/src/main/java/io/mosip/esignet/services/ClientManagementServiceImpl.java index 8de117cca..4e0fb34db 100644 --- a/client-management-service-impl/src/main/java/io/mosip/esignet/services/ClientManagementServiceImpl.java +++ b/client-management-service-impl/src/main/java/io/mosip/esignet/services/ClientManagementServiceImpl.java @@ -201,7 +201,7 @@ public io.mosip.esignet.core.dto.ClientDetail getClientDetails(String clientId) @CacheEvict(value = Constants.CLIENT_DETAIL_CACHE, key = "#clientDetailCreateRequestV2.getClientId()") @Override - public ClientDetailResponse createOIDCClientV2(ClientDetailCreateRequestV2 clientDetailCreateRequestV2) throws EsignetException { + public ClientDetailResponse createOauthClient(ClientDetailCreateRequestV2 clientDetailCreateRequestV2) throws EsignetException { Optional result = clientDetailRepository.findById(clientDetailCreateRequestV2.getClientId()); if (result.isPresent()) { log.error("Duplicate Client Id : {}", ErrorConstants.DUPLICATE_CLIENT_ID); @@ -231,7 +231,7 @@ public ClientDetailResponse createOIDCClientV2(ClientDetailCreateRequestV2 clien @CacheEvict(value = Constants.CLIENT_DETAIL_CACHE, key = "#clientId") @Override - public ClientDetailResponse updateOIDCClientV2(String clientId, ClientDetailUpdateRequestV2 clientDetailUpdateRequestV2) throws EsignetException { + public ClientDetailResponse updateOauthClient(String clientId, ClientDetailUpdateRequestV2 clientDetailUpdateRequestV2) throws EsignetException { Optional result = clientDetailRepository.findById(clientId); if (!result.isPresent()) { log.error("Invalid Client Id : {}", ErrorConstants.INVALID_CLIENT_ID); diff --git a/client-management-service-impl/src/test/java/io/mosip/esignet/ClientManagementServiceTest.java b/client-management-service-impl/src/test/java/io/mosip/esignet/ClientManagementServiceTest.java index 7133cb9a9..343801f8d 100644 --- a/client-management-service-impl/src/test/java/io/mosip/esignet/ClientManagementServiceTest.java +++ b/client-management-service-impl/src/test/java/io/mosip/esignet/ClientManagementServiceTest.java @@ -116,7 +116,7 @@ public void createClientV2_withValidDetail_thenPass() throws Exception { entity.setId("mock_id_v1"); entity.setStatus("active"); Mockito.when(clientDetailRepository.save(Mockito.any(ClientDetail.class))).thenReturn(entity); - ClientDetailResponse clientDetailResponse = clientManagementService.createOIDCClientV2(clientCreateV2ReqDto); + ClientDetailResponse clientDetailResponse = clientManagementService.createOauthClient(clientCreateV2ReqDto); Assert.assertNotNull(clientDetailResponse); Assert.assertTrue(clientDetailResponse.getClientId().equals("mock_id_v1")); Assert.assertTrue(clientDetailResponse.getStatus().equals("active")); @@ -128,7 +128,7 @@ public void createClientV2_withExistingClientId_thenFail() { ClientDetailCreateRequestV2 clientCreateV2ReqDto = new ClientDetailCreateRequestV2(); clientCreateV2ReqDto.setClientId("client_id_v1"); try { - clientManagementService.createOIDCClientV2(clientCreateV2ReqDto); + clientManagementService.createOauthClient(clientCreateV2ReqDto); } catch (EsignetException ex) { Assert.assertEquals(ex.getErrorCode(), ErrorConstants.DUPLICATE_CLIENT_ID); } @@ -180,7 +180,7 @@ public void updateClient_withValidClientId_thenPass() throws EsignetException { public void updateClientV2_withNonExistingClientId_thenFail() { Mockito.when(clientDetailRepository.findById("client_id_v1")).thenReturn(Optional.empty()); try { - clientManagementService.updateOIDCClientV2("client_id_v1", null); + clientManagementService.updateOauthClient("client_id_v1", null); } catch (EsignetException ex) { Assert.assertEquals(ex.getErrorCode(), ErrorConstants.INVALID_CLIENT_ID); } @@ -213,7 +213,7 @@ public void updateClientV2_withValidClientId_thenPass() throws EsignetException entity.setId("client_id_v1"); entity.setStatus("inactive"); Mockito.when(clientDetailRepository.save(Mockito.any(ClientDetail.class))).thenReturn(entity); - ClientDetailResponse clientDetailResponse = clientManagementService.updateOIDCClientV2("client_id_v1", updateV2Request); + ClientDetailResponse clientDetailResponse = clientManagementService.updateOauthClient("client_id_v1", updateV2Request); Assert.assertNotNull(clientDetailResponse); Assert.assertTrue(clientDetailResponse.getClientId().equals("client_id_v1")); Assert.assertTrue(clientDetailResponse.getStatus().equals("inactive")); diff --git a/esignet-core/src/main/java/io/mosip/esignet/core/spi/ClientManagementService.java b/esignet-core/src/main/java/io/mosip/esignet/core/spi/ClientManagementService.java index a73d21e89..f8c30f171 100644 --- a/esignet-core/src/main/java/io/mosip/esignet/core/spi/ClientManagementService.java +++ b/esignet-core/src/main/java/io/mosip/esignet/core/spi/ClientManagementService.java @@ -45,7 +45,7 @@ public interface ClientManagementService { * @return * @throws EsignetException */ - ClientDetailResponse createOIDCClientV2(ClientDetailCreateRequestV2 clientDetailCreateRequestV2) throws EsignetException; + ClientDetailResponse createOauthClient(ClientDetailCreateRequestV2 clientDetailCreateRequestV2) throws EsignetException; /** * API to update registered relying party client version 2 @@ -59,6 +59,6 @@ public interface ClientManagementService { * @return * @throws EsignetException */ - ClientDetailResponse updateOIDCClientV2(String clientId, ClientDetailUpdateRequestV2 clientDetailUpdateRequestV2) throws EsignetException; + ClientDetailResponse updateOauthClient(String clientId, ClientDetailUpdateRequestV2 clientDetailUpdateRequestV2) throws EsignetException; } diff --git a/esignet-service/src/main/java/io/mosip/esignet/controllers/ClientManagementController.java b/esignet-service/src/main/java/io/mosip/esignet/controllers/ClientManagementController.java index c3282fb46..514b1c8f7 100644 --- a/esignet-service/src/main/java/io/mosip/esignet/controllers/ClientManagementController.java +++ b/esignet-service/src/main/java/io/mosip/esignet/controllers/ClientManagementController.java @@ -86,11 +86,11 @@ public ResponseWrapper updateClient(@Valid @PathVariable(" return response; } - @PostMapping(value = "/client-mgmt/v2/oidc-client", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseWrapper createClientV2(@Valid @RequestBody RequestWrapper requestWrapper) throws Exception { + @PostMapping(value = "/client-mgmt/oauth-client", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseWrapper createOauthClient(@Valid @RequestBody RequestWrapper requestWrapper) throws Exception { ResponseWrapper response = new ResponseWrapper(); try { - response.setResponse(clientManagementService.createOIDCClientV2(requestWrapper.getRequest())); + response.setResponse(clientManagementService.createOauthClient(requestWrapper.getRequest())); } catch (EsignetException ex) { auditWrapper.logAudit(AuditHelper.getClaimValue(SecurityContextHolder.getContext(), claimName), Action.OIDC_CLIENT_CREATE, ActionStatus.ERROR, AuditHelper.buildAuditDto(requestWrapper.getRequest().getClientId()), ex); @@ -101,12 +101,12 @@ public ResponseWrapper createClientV2(@Valid @RequestBody } - @PutMapping(value = "/client-mgmt/v2/oidc-client/{client_id}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseWrapper updateClientV2(@Valid @PathVariable("client_id") String clientId, + @PutMapping(value = "/client-mgmt/oauth-client/{client_id}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseWrapper updateOauthClient(@Valid @PathVariable("client_id") String clientId, @Valid @RequestBody RequestWrapper requestWrapper) throws Exception { ResponseWrapper response = new ResponseWrapper(); try { - response.setResponse(clientManagementService.updateOIDCClientV2(clientId, requestWrapper.getRequest())); + response.setResponse(clientManagementService.updateOauthClient(clientId, requestWrapper.getRequest())); } catch (EsignetException ex) { auditWrapper.logAudit(AuditHelper.getClaimValue(SecurityContextHolder.getContext(), claimName), Action.OIDC_CLIENT_UPDATE, ActionStatus.ERROR, AuditHelper.buildAuditDto(clientId), ex); diff --git a/esignet-service/src/main/resources/application-dev.properties b/esignet-service/src/main/resources/application-dev.properties index 7d0301734..373624233 100644 --- a/esignet-service/src/main/resources/application-dev.properties +++ b/esignet-service/src/main/resources/application-dev.properties @@ -140,9 +140,9 @@ mosip.esignet.cache.expire-in-seconds={'clientdetails' : 86400, 'preauth': 180, 'linked': 60 , 'linkedcode': ${mosip.esignet.link-code-expire-in-secs}, 'linkedauth' : ${mosip.esignet.authentication-expire-in-secs}, 'consented': 120 } ## ------------------------------------------ Discovery openid-configuration ------------------------------------------- mosipbox.public.url=http://localhost:8088 -mosip.esignet.discovery.issuer-id=${mosipbox.public.url} +mosip.esignet.discovery.issuer-id=${mosipbox.public.url}${server.servlet.path} -mosip.esignet.oauth.key-values={'issuer': '${mosip.esignet.discovery.issuer-id}' ,\ +mosip.esignet.oauth.key-values={'issuer': '${mosipbox.public.url}' ,\ \ 'authorization_endpoint': '${mosipbox.public.url}${server.servlet.path}/authorize' , \ \ 'token_endpoint': '${mosipbox.public.url}${server.servlet.path}/oauth/token' , \ \ 'jwks_uri' : '${mosipbox.public.url}${server.servlet.path}/oauth/jwks.json' , \ @@ -153,7 +153,7 @@ mosip.esignet.oauth.key-values={'issuer': '${mosip.esignet.discovery.issuer-id}' \ 'grant_types_supported' : ${mosip.esignet.supported.grant.types},\ \ 'response_types_supported' : ${mosip.esignet.supported.response.types}} -mosip.esignet.discovery.key-values={'issuer': '${mosip.esignet.discovery.issuer-id}' ,\ +mosip.esignet.discovery.key-values={'issuer': '${mosipbox.public.url}' ,\ \ 'authorization_endpoint': '${mosipbox.public.url}${server.servlet.path}/authorize' , \ \ 'token_endpoint': '${mosipbox.public.url}${server.servlet.path}/oauth/token' ,\ \ 'userinfo_endpoint' : '${mosipbox.public.url}${server.servlet.path}/oidc/userinfo' ,\ diff --git a/esignet-service/src/main/resources/application-local.properties b/esignet-service/src/main/resources/application-local.properties index 9bd40b09d..9f67f471b 100644 --- a/esignet-service/src/main/resources/application-local.properties +++ b/esignet-service/src/main/resources/application-local.properties @@ -146,9 +146,9 @@ mosip.esignet.cache.expire-in-seconds={'clientdetails' : 86400, 'preauth': 180, ## ------------------------------------------ Discovery openid-configuration ------------------------------------------- mosipbox.public.url=http://localhost:8088 -mosip.esignet.discovery.issuer-id=${mosipbox.public.url} +mosip.esignet.discovery.issuer-id=${mosipbox.public.url}${server.servlet.path} -mosip.esignet.oauth.key-values={'issuer': '${mosip.esignet.discovery.issuer-id}' ,\ +mosip.esignet.oauth.key-values={'issuer': '${mosipbox.public.url}' ,\ \ 'authorization_endpoint': '${mosipbox.public.url}${server.servlet.path}/authorize' , \ \ 'token_endpoint': '${mosipbox.public.url}${server.servlet.path}/oauth/token' , \ \ 'jwks_uri' : '${mosipbox.public.url}${server.servlet.path}/oauth/jwks.json' , \ @@ -159,7 +159,7 @@ mosip.esignet.oauth.key-values={'issuer': '${mosip.esignet.discovery.issuer-id}' \ 'grant_types_supported' : ${mosip.esignet.supported.grant.types},\ \ 'response_types_supported' : ${mosip.esignet.supported.response.types}} -mosip.esignet.discovery.key-values={'issuer': '${mosip.esignet.discovery.issuer-id}' ,\ +mosip.esignet.discovery.key-values={'issuer': '${mosipbox.public.url}' ,\ \ 'authorization_endpoint': '${mosipbox.public.url}${server.servlet.path}/authorize' , \ \ 'token_endpoint': '${mosipbox.public.url}${server.servlet.path}/oauth/token' ,\ \ 'userinfo_endpoint' : '${mosipbox.public.url}${server.servlet.path}/oidc/userinfo' ,\ diff --git a/esignet-service/src/main/resources/logback.xml b/esignet-service/src/main/resources/logback.xml new file mode 100644 index 000000000..b9dfc23e6 --- /dev/null +++ b/esignet-service/src/main/resources/logback.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/esignet-service/src/test/java/io/mosip/esignet/controllers/ClientMgmtControllerParameterizedTest.java b/esignet-service/src/test/java/io/mosip/esignet/controllers/ClientMgmtControllerParameterizedTest.java index 0a8c64ed3..006b890ac 100644 --- a/esignet-service/src/test/java/io/mosip/esignet/controllers/ClientMgmtControllerParameterizedTest.java +++ b/esignet-service/src/test/java/io/mosip/esignet/controllers/ClientMgmtControllerParameterizedTest.java @@ -233,7 +233,7 @@ public void setup() throws Exception { @Test public void testClientManagementEndpoints() throws Exception { if(this.clientDetailCreateRequestV2 != null) { - ResultActions createResultActions = mockMvc.perform(post("/client-mgmt/v2/oidc-client") + ResultActions createResultActions = mockMvc.perform(post("/client-mgmt/oauth-client") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(getRequestWrapper(this.clientDetailCreateRequestV2))); evaluateResultActions(createResultActions, this.clientDetailCreateRequestV2.getClientId(), @@ -241,7 +241,7 @@ public void testClientManagementEndpoints() throws Exception { } if(this.clientDetailUpdateRequestV2 != null) { - ResultActions updateResultActions = mockMvc.perform(put("/client-mgmt/v2/oidc-client/"+this.clientIdQueryParam) + ResultActions updateResultActions = mockMvc.perform(put("/client-mgmt/oauth-client/"+this.clientIdQueryParam) .contentType(MediaType.APPLICATION_JSON_UTF8) .content(getRequestWrapper(this.clientDetailUpdateRequestV2))); evaluateResultActions(updateResultActions, this.clientIdQueryParam,