diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/KeycloakUserDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/KeycloakUserDto.java new file mode 100644 index 0000000000..cecc4a8198 --- /dev/null +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/KeycloakUserDto.java @@ -0,0 +1,16 @@ +package io.mosip.pms.partner.dto; + +import lombok.Data; + +/** + * DTO is used for fetching user details from Keycloak. + */ +@Data +public class KeycloakUserDto { + + private String username; + private String email; + private String firstName; + private String lastName; + +} diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/dto/PartnerDetailsV3Dto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/dto/PartnerDetailsV3Dto.java index 49bd01312a..510373704e 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/dto/PartnerDetailsV3Dto.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/dto/PartnerDetailsV3Dto.java @@ -16,6 +16,12 @@ public class PartnerDetailsV3Dto { @Schema(description = "Unique identifier for the partner", example = "partner123") private String partnerId; + @Schema(description = "First name of the partner", example = "John") + private String firstName; + + @Schema(description = "Last name of the partner", example = "Doe") + private String lastName; + @Schema(description = "Status of the partner", example = "approved") private String approvalStatus; diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java index 5054c97974..19095c7ae8 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java @@ -20,6 +20,7 @@ import io.mosip.pms.common.repository.*; import io.mosip.pms.common.request.dto.RequestWrapper; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.partner.dto.KeycloakUserDto; import io.mosip.pms.partner.manager.dto.CaCertificateFilterDto; import io.mosip.pms.partner.exception.PartnerServiceException; import io.mosip.pms.partner.manager.dto.*; @@ -824,6 +825,11 @@ public ResponseWrapperV2 getPartnerDetails(String partnerId partnerDetailsV3Dto.setCertificateExpiryDateTime(cert.getNotAfter()); partnerDetailsV3Dto.setIsCertificateAvailable(true); } + Optional keycloakUserDto = partnerHelper.getUserDetailsByPartnerId(partnerId); + if (keycloakUserDto.isPresent()){ + partnerDetailsV3Dto.setFirstName(keycloakUserDto.get().getFirstName()); + partnerDetailsV3Dto.setLastName(keycloakUserDto.get().getLastName()); + } responseWrapper.setResponse(partnerDetailsV3Dto); } catch (PartnerServiceException ex) { LOGGER.info("sessionId", "idType", "id", diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/util/PartnerHelper.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/util/PartnerHelper.java index 3ba55c5ce6..71b2e4e0ad 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/util/PartnerHelper.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/util/PartnerHelper.java @@ -15,13 +15,16 @@ import io.mosip.pms.device.authdevice.repository.SecureBiometricInterfaceRepository; import io.mosip.pms.partner.constant.ErrorCode; import io.mosip.pms.partner.constant.PartnerConstants; +import io.mosip.pms.partner.dto.KeycloakUserDto; import io.mosip.pms.partner.exception.PartnerServiceException; import io.mosip.pms.partner.response.dto.FtmCertificateDownloadResponseDto; import io.mosip.pms.partner.response.dto.OriginalCertDownloadResponseDto; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.data.domain.Sort; +import org.springframework.http.MediaType; import org.springframework.stereotype.Component; +import org.springframework.web.util.UriComponentsBuilder; import java.security.cert.X509Certificate; import java.time.LocalDate; @@ -31,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Objects; @Component public class PartnerHelper { @@ -333,4 +337,32 @@ public void checkIfPartnerIsNotActive(Partner partner) { ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage()); } } + + public Optional getUserDetailsByPartnerId(String partnerId) throws Exception { + try { + Map pathSegments = Map.of("username", partnerId); + + String apiUrl = UriComponentsBuilder + .fromHttpUrl(Objects.requireNonNull(environment.getProperty("mosip.iam.admin-url"))) + .path(Objects.requireNonNull(environment.getProperty("mosip.iam.users-extn-url"))) + .queryParam("username", "{username}") + .build() + .toUriString(); + MediaType mediaType = MediaType.APPLICATION_JSON; + + List> getApiResponse = restUtil.getApiWithContentType(apiUrl, pathSegments, List.class, mediaType); + + // Check if the response is empty or null + if (getApiResponse == null || getApiResponse.isEmpty()) { + LOGGER.error("Error while fetching user details for partnerId:", partnerId); + return Optional.empty(); + } + + return Optional.ofNullable(mapper.readValue(mapper.writeValueAsString(getApiResponse.get(0)), KeycloakUserDto.class)); + } catch (Exception e) { + LOGGER.error("Error while fetching user details for partnerId: {}", partnerId, e.getStackTrace()); + return Optional.empty(); + } + } + } diff --git a/partner/partner-management-service/src/main/resources/bootstrap.properties b/partner/partner-management-service/src/main/resources/bootstrap.properties index ad5933012a..983f84b1a1 100644 --- a/partner/partner-management-service/src/main/resources/bootstrap.properties +++ b/partner/partner-management-service/src/main/resources/bootstrap.properties @@ -67,6 +67,7 @@ auth.allowed.urls=https://${mosip.pmp.host}/,https://${mosip.pmp.reactjs.ui.host #auth.allowed.urls=http://${mosip.pmp.host}/,http://${mosip.pmp.reactjs.ui.host}/ mosip.kernel.keymanager.url=https://dev.mosip.net + pmp.partner.original.certificate.get.rest.uri=${mosip.kernel.keymanager.url}/v1/keymanager/getPartnerSignedCertificate/{partnerCertId} pmp.ca.certificates.post.rest.uri=${mosip.kernel.keymanager.url}/v1/keymanager/getCaCertificates @@ -146,4 +147,3 @@ mosip.pms.api.id.all.sbi.details.get=mosip.pms.all.sbi.details.get mosip.pms.api.id.get.all.device.details.get=mosip.pms.get.all.device.details.get mosip.pms.api.id.all.ca.certificates.get=mosip.pms.all.ca.certificates.get ##END properties are for PMS Revamp DP1 release - diff --git a/partner/pms-common/src/main/java/io/mosip/pms/common/util/RestUtil.java b/partner/pms-common/src/main/java/io/mosip/pms/common/util/RestUtil.java index 1d15098384..9f00683216 100644 --- a/partner/pms-common/src/main/java/io/mosip/pms/common/util/RestUtil.java +++ b/partner/pms-common/src/main/java/io/mosip/pms/common/util/RestUtil.java @@ -239,6 +239,37 @@ public T getApi(String apiUrl, Map pathsegments, Class re return result; } + /** + * + * @param + * @param apiUrl + * @param pathsegments + * @param responseType + * @return + */ + @SuppressWarnings("unchecked") + public T getApiWithContentType(String apiUrl, Map pathsegments, Class responseType, MediaType mediaType) { + T result = null; + UriComponentsBuilder builder = null; + if (apiUrl != null) { + builder = UriComponentsBuilder.fromUriString(apiUrl); + URI urlWithPath = builder.build(pathsegments); + RestTemplate restTemplate; + try { + restTemplate = getRestTemplate(); + result = (T) restTemplate + .exchange(urlWithPath, HttpMethod.GET, setRequestHeader(null, mediaType), responseType).getBody(); + } catch (Exception e) { + logger.error("Error occurred while calling {}", urlWithPath, e.getStackTrace()); + throw new ApiAccessibleException( + ApiAccessibleExceptionConstant.API_NOT_ACCESSIBLE_EXCEPTION.getErrorCode(), + ApiAccessibleExceptionConstant.API_NOT_ACCESSIBLE_EXCEPTION.getErrorMessage()); + } + + } + return result; + } + /** * * @return