Skip to content

Commit

Permalink
ES-328 (#434)
Browse files Browse the repository at this point in the history
* ES-4 (#432)

Co-authored-by: ase-101 <>

* ES-328

---------

Co-authored-by: ase-101 <>
  • Loading branch information
ase-101 authored Oct 9, 2023
1 parent a526f60 commit d4c00f6
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClientDetail> result = clientDetailRepository.findById(clientDetailCreateRequestV2.getClientId());
if (result.isPresent()) {
log.error("Duplicate Client Id : {}", ErrorConstants.DUPLICATE_CLIENT_ID);
Expand Down Expand Up @@ -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<ClientDetail> result = clientDetailRepository.findById(clientId);
if (!result.isPresent()) {
log.error("Invalid Client Id : {}", ErrorConstants.INVALID_CLIENT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public ResponseWrapper<ClientDetailResponse> updateClient(@Valid @PathVariable("
return response;
}

@PostMapping(value = "/client-mgmt/v2/oidc-client", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseWrapper<ClientDetailResponse> createClientV2(@Valid @RequestBody RequestWrapper<ClientDetailCreateRequestV2> requestWrapper) throws Exception {
@PostMapping(value = "/client-mgmt/oauth-client", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseWrapper<ClientDetailResponse> createOauthClient(@Valid @RequestBody RequestWrapper<ClientDetailCreateRequestV2> requestWrapper) throws Exception {
ResponseWrapper response = new ResponseWrapper<ClientDetailResponse>();
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);
Expand All @@ -101,12 +101,12 @@ public ResponseWrapper<ClientDetailResponse> createClientV2(@Valid @RequestBody
}


@PutMapping(value = "/client-mgmt/v2/oidc-client/{client_id}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseWrapper<ClientDetailResponse> 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<ClientDetailResponse> updateOauthClient(@Valid @PathVariable("client_id") String clientId,
@Valid @RequestBody RequestWrapper<ClientDetailUpdateRequestV2> requestWrapper) throws Exception {
ResponseWrapper response = new ResponseWrapper<ClientDetailResponse>();
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);
Expand Down
6 changes: 3 additions & 3 deletions esignet-service/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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' , \
Expand All @@ -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' ,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' , \
Expand All @@ -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' ,\
Expand Down
11 changes: 11 additions & 0 deletions esignet-service/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<configuration>
<springProperty scope="context" name="appName" source="spring.application.name"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ 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(),
Constants.CLIENT_ACTIVE_STATUS, this.errorCode);
}

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,
Expand Down

0 comments on commit d4c00f6

Please sign in to comment.