Skip to content

Commit

Permalink
MOSIP-35353 : merged code of release-1.3.0-dp.1 with develop
Browse files Browse the repository at this point in the history
Signed-off-by: sudeep <[email protected]>
  • Loading branch information
Sudeep7353 committed Sep 20, 2024
1 parent 34cecf3 commit 3ea003f
Show file tree
Hide file tree
Showing 32 changed files with 627 additions and 536 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
import io.mosip.pms.common.response.dto.ResponseWrapperV2;
import io.mosip.pms.device.util.AuditUtil;
import io.mosip.pms.oidc.client.contant.ClientServiceAuditEnum;
import org.springframework.http.HttpStatus;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import io.mosip.pms.oauth.client.service.ClientManagementService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -22,7 +19,7 @@
import io.mosip.pms.oauth.client.dto.ClientDetailResponse;
import io.mosip.pms.oauth.client.dto.ClientDetailUpdateRequest;
import io.mosip.pms.oauth.client.dto.ClientDetailUpdateRequestV2;
import io.mosip.pms.oauth.client.dto.OidcClientDto;
import io.mosip.pms.oauth.client.dto.OauthClientDto;

import jakarta.validation.Valid;

Expand All @@ -41,11 +38,6 @@ public class ClientManagementController {
@Autowired
AuditUtil auditUtil;

@Value("${mosip.pms.api.id.all.oidc.clients.get}")
private String getClientsId;

public static final String VERSION = "1.0";

@RequestMapping(value = "/oauth/client", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseWrapper<ClientDetailResponse> createOAUTHClient(
@Valid @RequestBody RequestWrapper<ClientDetailCreateRequestV2> requestWrapper) throws Exception {
Expand Down Expand Up @@ -103,18 +95,14 @@ public ResponseWrapper<ClientDetail> getOIDCClient(@PathVariable("client_id") St
return response;
}

@PreAuthorize("hasAnyRole(@authorizedRoles.getGetalloidcclients())")
@PreAuthorize("hasAnyRole(@authorizedRoles.getGetoauthclients())")
@GetMapping(value = "/oauth/clients")
@Operation(summary = "Get all Oidc clients", description = "fetch all oidc clients")
@Operation(summary = "Get all clients", description = "fetch all clients")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))})
public ResponseWrapperV2<List<OidcClientDto>> getClients() {
ResponseWrapperV2<List<OidcClientDto>> responseWrapper = new ResponseWrapperV2<>();
responseWrapper.setId(getClientsId);
responseWrapper.setVersion(VERSION);
responseWrapper.setResponse(clientManagementService.getClients());
return responseWrapper;
public ResponseWrapperV2<List<OauthClientDto>> getClients() {
return clientManagementService.getClients();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import java.util.List;

@Data
public class OidcClientDto {
public class OauthClientDto {
private String UserId;
private String partnerId;
private String oidcClientId;
private String oidcClientName;
private String clientId;
private String clientName;
private String policyGroupId;
private String policyGroupName;
private String policyGroupDescription;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.mosip.pms.oauth.client.service;

import io.mosip.pms.common.response.dto.ResponseWrapperV2;
import io.mosip.pms.oauth.client.dto.ClientDetail;
import io.mosip.pms.oauth.client.dto.ClientDetailCreateRequest;
import io.mosip.pms.oauth.client.dto.ClientDetailCreateRequestV2;
import io.mosip.pms.oauth.client.dto.ClientDetailResponse;
import io.mosip.pms.oauth.client.dto.ClientDetailUpdateRequest;
import io.mosip.pms.oauth.client.dto.ClientDetailUpdateRequestV2;
import io.mosip.pms.oauth.client.dto.OidcClientDto;
import io.mosip.pms.oauth.client.dto.OauthClientDto;

import java.util.List;

Expand Down Expand Up @@ -59,5 +60,5 @@ public interface ClientManagementService {
ClientDetailResponse updateOAuthClient(String clientId, ClientDetailUpdateRequestV2 updateRequest)
throws Exception;

List<OidcClientDto> getClients();
ResponseWrapperV2<List<OauthClientDto>> getClients();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import java.util.Set;
import java.util.Objects;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import io.mosip.kernel.openid.bridge.model.AuthUserDetails;
import io.mosip.pms.common.response.dto.ResponseWrapperV2;
import io.mosip.pms.device.util.AuditUtil;
import io.mosip.pms.oidc.client.contant.ClientServiceAuditEnum;
import io.mosip.pms.partner.util.PartnerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.http.MediaType;
import org.springframework.security.core.context.SecurityContextHolder;
Expand Down Expand Up @@ -65,7 +67,7 @@
import io.mosip.pms.oauth.client.dto.UpdateClientRequestDto;
import io.mosip.pms.oauth.client.dto.UpdateClientRequestDtoV2;
import io.mosip.pms.oauth.client.service.ClientManagementService;
import io.mosip.pms.oauth.client.dto.OidcClientDto;
import io.mosip.pms.oauth.client.dto.OauthClientDto;
import io.mosip.pms.partner.constant.ErrorCode;
import io.mosip.pms.partner.constant.PartnerConstants;
import io.mosip.pms.partner.exception.PartnerServiceException;
Expand Down Expand Up @@ -102,6 +104,11 @@ public class ClientManagementServiceImpl implements ClientManagementService {
public static final String NONE_LANG_KEY = "@none";
public static final String ENG_KEY = "eng";

@Value("${mosip.pms.api.id.oauth.clients.get}")
private String getClientsId;

public static final String VERSION = "1.0";

@Autowired
ObjectMapper objectMapper;

Expand Down Expand Up @@ -656,11 +663,12 @@ private String getClientNameLanguageMapAsJsonString(Map<String, String> clientNa
}

@Override
public List<OidcClientDto> getClients() {
List<OidcClientDto> oidcClientDtoList = new ArrayList<>();
public ResponseWrapperV2<List<OauthClientDto>> getClients() {
ResponseWrapperV2<List<OauthClientDto>> responseWrapper = new ResponseWrapperV2<>();
try {
String userId = getUserId();
List<Partner> partnerList = partnerServiceRepository.findByUserId(userId);
List<OauthClientDto> oauthClientDtoList = new ArrayList<>();
for (Partner partner : partnerList) {
String partnerId = partner.getId();
if (Objects.isNull(partnerId) || partnerId.equals(BLANK_STRING)) {
Expand All @@ -683,37 +691,46 @@ public List<OidcClientDto> getClients() {
throw new PartnerServiceException(ErrorCode.POLICY_GROUP_NOT_EXISTS.getErrorCode(),
ErrorCode.POLICY_GROUP_NOT_EXISTS.getErrorMessage());
}
OidcClientDto oidcClientDto = new OidcClientDto();
oidcClientDto.setPartnerId(partnerId);
oidcClientDto.setUserId(userId);
oidcClientDto.setOidcClientId(clientDetail.getId());
oidcClientDto.setOidcClientName(getOidcClientName(clientDetail.getName()));
oidcClientDto.setPolicyGroupId(policyGroup.getId());
oidcClientDto.setPolicyGroupName(policyGroup.getName());
oidcClientDto.setPolicyGroupDescription(policyGroup.getDesc());
oidcClientDto.setPolicyId(authPolicy.get().getId());
oidcClientDto.setPolicyName(authPolicy.get().getName());
oidcClientDto.setPolicyDescription(authPolicy.get().getDescr());
oidcClientDto.setRelyingPartyId(clientDetail.getRpId());
oidcClientDto.setLogoUri(clientDetail.getLogoUri());
oidcClientDto.setRedirectUris(convertStringToList(clientDetail.getRedirectUris()));
oidcClientDto.setPublicKey(clientDetail.getPublicKey());
oidcClientDto.setStatus(clientDetail.getStatus());
oidcClientDto.setGrantTypes(convertStringToList(clientDetail.getGrantTypes()));
oidcClientDto.setCreatedDateTime(clientDetail.getCreatedDateTime());
oidcClientDto.setUpdatedDateTime(clientDetail.getUpdatedDateTime());
oidcClientDto.setClientAuthMethods(convertStringToList(clientDetail.getClientAuthMethods()));
oidcClientDtoList.add(oidcClientDto);
OauthClientDto oauthClientDto = new OauthClientDto();
oauthClientDto.setPartnerId(partnerId);
oauthClientDto.setUserId(userId);
oauthClientDto.setClientId(clientDetail.getId());
oauthClientDto.setClientName(getOidcClientName(clientDetail.getName()));
oauthClientDto.setPolicyGroupId(policyGroup.getId());
oauthClientDto.setPolicyGroupName(policyGroup.getName());
oauthClientDto.setPolicyGroupDescription(policyGroup.getDesc());
oauthClientDto.setPolicyId(authPolicy.get().getId());
oauthClientDto.setPolicyName(authPolicy.get().getName());
oauthClientDto.setPolicyDescription(authPolicy.get().getDescr());
oauthClientDto.setRelyingPartyId(clientDetail.getRpId());
oauthClientDto.setLogoUri(clientDetail.getLogoUri());
oauthClientDto.setRedirectUris(convertStringToList(clientDetail.getRedirectUris()));
oauthClientDto.setPublicKey(clientDetail.getPublicKey());
oauthClientDto.setStatus(clientDetail.getStatus());
oauthClientDto.setGrantTypes(convertStringToList(clientDetail.getGrantTypes()));
oauthClientDto.setCreatedDateTime(clientDetail.getCreatedDateTime());
oauthClientDto.setUpdatedDateTime(clientDetail.getUpdatedDateTime());
oauthClientDto.setClientAuthMethods(convertStringToList(clientDetail.getClientAuthMethods()));
oauthClientDtoList.add(oauthClientDto);
}
}
responseWrapper.setResponse(oauthClientDtoList);
} catch (PartnerServiceException ex) {
LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace());
LOGGER.error("sessionId", "idType", "id",
"In getClients method of ClientManagementServiceImpl - " + ex.getMessage());
responseWrapper.setErrors(PartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText()));
} catch (Exception ex) {
LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace());
LOGGER.error("sessionId", "idType", "id",
"In getClients method of ClientManagementServiceImpl - " + ex.getMessage());
throw new PartnerServiceException(ErrorCode.OIDC_CLIENTS_FETCH_ERROR.getErrorCode(),
ErrorCode.OIDC_CLIENTS_FETCH_ERROR.getErrorMessage());
String errorCode = ErrorCode.OIDC_CLIENTS_FETCH_ERROR.getErrorCode();
String errorMessage = ErrorCode.OIDC_CLIENTS_FETCH_ERROR.getErrorMessage();
responseWrapper.setErrors(PartnerUtil.setErrorResponse(errorCode, errorMessage));
}
return oidcClientDtoList;
responseWrapper.setId(getClientsId);
responseWrapper.setVersion(VERSION);
return responseWrapper;
}

private String getUserId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,93 +26,56 @@
@Api(tags = { "Multi Partner Service Controller" })
public class MultiPartnerServiceController {

@Value("${mosip.pms.api.id.all.certificates.details.get}")
private String getPartnerCertificatesId;

@Value("${mosip.pms.api.id.all.requested.policies.get}")
private String getAllRequestedPoliciesId;

@Value("${mosip.pms.api.id.all.approved.auth.partners.policies.get}")
private String getAuthPartnersPoliciesId;

@Value("${mosip.pms.api.id.all.approved.partner.ids.with.policy.groups.get}")
private String getApprovedPartnerIdsWithPolicyGroupsId;

@Value("${mosip.pms.api.id.all.api.keys.for.auth.partners.get}")
private String getApiKeysForAuthPartners;

public static final String VERSION = "1.0";

@Autowired
MultiPartnerService multiPartnerService;

@PreAuthorize("hasAnyRole(@authorizedRoles.getGetallcertificatedetails())")
@PreAuthorize("hasAnyRole(@authorizedRoles.getGetpartnercertificates())")
@GetMapping(value = "/partner-certificates")
@Operation(summary = "Get partner certificates", description = "fetch partner certificates")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))})
public ResponseWrapperV2<List<CertificateDto>> getPartnerCertificates() {
ResponseWrapperV2<List<CertificateDto>> responseWrapper = new ResponseWrapperV2<>();
responseWrapper.setId(getPartnerCertificatesId);
responseWrapper.setVersion(VERSION);
responseWrapper.setResponse(multiPartnerService.getPartnerCertificates());
return responseWrapper;
return multiPartnerService.getPartnerCertificates();
}

@PreAuthorize("hasAnyRole(@authorizedRoles.getGetallrequestedpolicies())")
@PreAuthorize("hasAnyRole(@authorizedRoles.getGetpolicyrequests())")
@GetMapping(value = "/policy-requests")
@Operation(summary = "Get all policies", description = "fetch all policies")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))})
public ResponseWrapperV2<List<PolicyDto>> getPolicyRequests() {
ResponseWrapperV2<List<PolicyDto>> responseWrapper = new ResponseWrapperV2<>();
responseWrapper.setId(getAllRequestedPoliciesId);
responseWrapper.setVersion(VERSION);
responseWrapper.setResponse(multiPartnerService.getPolicyRequests());
return responseWrapper;
return multiPartnerService.getPolicyRequests();
}

@PreAuthorize("hasAnyRole(@authorizedRoles.getGetallapprovedauthpartnerpolicies())")
@PreAuthorize("hasAnyRole(@authorizedRoles.getGetauthpartnerspolicies())")
@GetMapping(value = "/auth-partners-policies")
@Operation(summary = "Get all approved auth partner policies", description = "fetch all approved auth partner policies")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))})
public ResponseWrapperV2<List<ApprovedPolicyDto>> getAuthPartnerPolicies() {
ResponseWrapperV2<List<ApprovedPolicyDto>> responseWrapper = new ResponseWrapperV2<>();
responseWrapper.setId(getAuthPartnersPoliciesId);
responseWrapper.setVersion(VERSION);
responseWrapper.setResponse(multiPartnerService.getAuthPartnerPolicies());
return responseWrapper;
public ResponseWrapperV2<List<ApprovedPolicyDto>> getAuthPartnersPolicies() {
return multiPartnerService.getAuthPartnersPolicies();
}

@PreAuthorize("hasAnyRole(@authorizedRoles.getGetallapprovedpartneridswithpolicygroups())")
@PreAuthorize("hasAnyRole(@authorizedRoles.getGetapprovedpartneridswithpolicygroups())")
@GetMapping(value = "/approved-partner-ids-with-policy-groups")
@Operation(summary = "Get all approved partner id's with policy groups", description = "fetch all approved partner id's with policy groups")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))})
public ResponseWrapperV2<List<PolicyGroupDto>> getApprovedPartnerIdsWithPolicyGroups() {
ResponseWrapperV2<List<PolicyGroupDto>> responseWrapper = new ResponseWrapperV2<>();
responseWrapper.setId(getApprovedPartnerIdsWithPolicyGroupsId);
responseWrapper.setVersion(VERSION);
responseWrapper.setResponse(multiPartnerService.getApprovedPartnerIdsWithPolicyGroups());
return responseWrapper;
return multiPartnerService.getApprovedPartnerIdsWithPolicyGroups();
}

@PreAuthorize("hasAnyRole(@authorizedRoles.getGetallapikeysforauthpartners())")
@PreAuthorize("hasAnyRole(@authorizedRoles.getGetapikeysforauthpartners())")
@GetMapping(value = "/api-keys-for-auth-partners")
@Operation(summary = "Get all api keys for auth partners", description = "fetch all api keys for auth partners")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))})
public ResponseWrapperV2<List<ApiKeyResponseDto>> getApiKeysForAuthPartners() {
ResponseWrapperV2<List<ApiKeyResponseDto>> responseWrapper = new ResponseWrapperV2<>();
responseWrapper.setId(getApiKeysForAuthPartners);
responseWrapper.setVersion(VERSION);
responseWrapper.setResponse(multiPartnerService.getApiKeysForAuthPartners());
return responseWrapper;
return multiPartnerService.getApiKeysForAuthPartners();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ public class PartnerServiceController {

@Autowired
AuditUtil auditUtil;

@Value("${mosip.pms.api.id.original.partner.certificate.get}")
private String getOriginalPartnerCertificateId;

public static final String VERSION = "1.0";

/**
* This API would be used for self registration by partner to create Auth/E-KYC
Expand Down Expand Up @@ -369,13 +364,9 @@ public ResponseWrapper<PartnerCertDownloadResponeDto> getPartnerCertificate(
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))})
public ResponseWrapperV2<OriginalCertDownloadResponseDto> getOriginalPartnerCertificate(
@ApiParam("To download original partner certificate.") @PathVariable("partnerId") @NotNull String partnerId) throws JsonParseException, JsonMappingException, JsonProcessingException, IOException, CertificateException {
ResponseWrapperV2<OriginalCertDownloadResponseDto> response = new ResponseWrapperV2<>();
response.setId(getOriginalPartnerCertificateId);
response.setVersion(VERSION);
PartnerCertDownloadRequestDto requestDto = new PartnerCertDownloadRequestDto();
requestDto.setPartnerId(partnerId);
response.setResponse(partnerService.getOriginalPartnerCertificate(requestDto));
return response;
return partnerService.getOriginalPartnerCertificate(requestDto);
}

@ResponseFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,19 @@ public class AuthorizedRolesDto {

private List<String> postmispsearch;

//Multi Partner Service Controller
//Multi Partner Service Controller

private List<String> getallcertificatedetails;
private List<String> getpartnercertificates;

private List<String> getallrequestedpolicies;
private List<String> getpolicyrequests;

private List<String> getallapprovedauthpartnerpolicies;
private List<String> getauthpartnerspolicies;

private List<String> getallapprovedpartneridswithpolicygroups;
private List<String> getapprovedpartneridswithpolicygroups;

private List<String> getallapikeysforauthpartners;
private List<String> getapikeysforauthpartners;

private List<String> getalloidcclients;

//user consent
private List<String> getoauthclients;

private List<String> userconsent;

Expand Down
Loading

0 comments on commit 3ea003f

Please sign in to comment.