Skip to content

Commit

Permalink
ES-328 (#435)
Browse files Browse the repository at this point in the history
Co-authored-by: ase-101 <>
  • Loading branch information
ase-101 authored Oct 9, 2023
1 parent d4c00f6 commit 34241ff
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 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 createOauthClient(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 All @@ -224,14 +224,14 @@ public ClientDetailResponse createOauthClient(ClientDetailCreateRequestV2 client
}

auditWrapper.logAudit(AuditHelper.getClaimValue(SecurityContextHolder.getContext(), claimName),
Action.OIDC_CLIENT_CREATE, ActionStatus.SUCCESS, AuditHelper.buildAuditDto(clientDetailCreateRequestV2.getClientId()), null);
Action.OAUTH_CLIENT_CREATE, ActionStatus.SUCCESS, AuditHelper.buildAuditDto(clientDetailCreateRequestV2.getClientId()), null);

return getClientDetailResponse(clientDetail);
}

@CacheEvict(value = Constants.CLIENT_DETAIL_CACHE, key = "#clientId")
@Override
public ClientDetailResponse updateOauthClient(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 All @@ -249,7 +249,7 @@ public ClientDetailResponse updateOauthClient(String clientId, ClientDetailUpdat
clientDetail = clientDetailRepository.save(clientDetail);

auditWrapper.logAudit(AuditHelper.getClaimValue(SecurityContextHolder.getContext(), claimName),
Action.OIDC_CLIENT_UPDATE, ActionStatus.SUCCESS, AuditHelper.buildAuditDto(clientId), null);
Action.OAUTH_CLIENT_UPDATE, ActionStatus.SUCCESS, AuditHelper.buildAuditDto(clientId), null);

return getClientDetailResponse(clientDetail);
}
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.createOauthClient(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.createOauthClient(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.updateOauthClient("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.updateOauthClient("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 createOauthClient(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 updateOauthClient(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 @@ -3,6 +3,8 @@
public enum Action {
OIDC_CLIENT_CREATE,
OIDC_CLIENT_UPDATE,
OAUTH_CLIENT_CREATE,
OAUTH_CLIENT_UPDATE,
GET_OAUTH_DETAILS,
TRANSACTION_STARTED,
SEND_OTP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public ResponseWrapper<ClientDetailResponse> updateClient(@Valid @PathVariable("
}

@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 {
public ResponseWrapper<ClientDetailResponse> createOAuthClient(@Valid @RequestBody RequestWrapper<ClientDetailCreateRequestV2> requestWrapper) throws Exception {
ResponseWrapper response = new ResponseWrapper<ClientDetailResponse>();
try {
response.setResponse(clientManagementService.createOauthClient(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);
Action.OAUTH_CLIENT_CREATE, ActionStatus.ERROR, AuditHelper.buildAuditDto(requestWrapper.getRequest().getClientId()), ex);
throw ex;
}
response.setResponseTime(IdentityProviderUtil.getUTCDateTime());
Expand All @@ -102,14 +102,14 @@ public ResponseWrapper<ClientDetailResponse> createOauthClient(@Valid @RequestBo


@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,
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.updateOauthClient(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);
Action.OAUTH_CLIENT_UPDATE, ActionStatus.ERROR, AuditHelper.buildAuditDto(clientId), ex);
throw ex;
}
response.setResponseTime(IdentityProviderUtil.getUTCDateTime());
Expand Down

0 comments on commit 34241ff

Please sign in to comment.