From 79d6d2f528a9d677d45224347c43b61861b69383 Mon Sep 17 00:00:00 2001 From: SwethaKrish4 <110164892+SwethaKrish4@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:22:50 +0530 Subject: [PATCH] MOSIP-37748: Removed checks in deactivate SBI and device for PARTNER_ADMIN (#1024) Signed-off-by: Swetha K Co-authored-by: Swetha K --- .../service/impl/DeviceDetailServiceImpl.java | 45 +++++++++--------- .../impl/FTPChipDetailServiceImpl.java | 12 +---- .../SecureBiometricInterfaceServiceImpl.java | 46 ++++++++++--------- .../mosip/pms/partner/util/PartnerHelper.java | 9 ++++ 4 files changed, 58 insertions(+), 54 deletions(-) diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java index 015514d964..86b864f22a 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java @@ -546,28 +546,10 @@ public ResponseWrapperV2 deactivateDevice(String device ErrorCode.DEVICE_NOT_EXISTS.getErrorMessage()); } DeviceDetail device = deviceDetail.get(); - // check if the device is associated with user. - String deviceProviderId = device.getDeviceProviderId(); - boolean deviceProviderExist = false; - Partner partnerDetails = new Partner(); - for (Partner partner : partnerList) { - if (partner.getId().equals(deviceProviderId)) { - validatePartnerId(partner, userId); - deviceProviderExist = true; - partnerDetails = partner; - break; - } - } - if (!deviceProviderExist) { - LOGGER.info("sessionId", "idType", "id", "Device is not associated with user."); - throw new PartnerServiceException(ErrorCode.DEVICE_NOT_ASSOCIATED_WITH_USER.getErrorCode(), - ErrorCode.DEVICE_NOT_ASSOCIATED_WITH_USER.getErrorMessage()); - } - //check if Partner is Active or not - if (!partnerDetails.getIsActive()) { - LOGGER.error("Partner is not Active with id {}", deviceProviderId); - throw new PartnerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(), - ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage()); + boolean isAdmin = partnerHelper.isPartnerAdmin(authUserDetails().getAuthorities().toString()); + if (!isAdmin) { + Partner partnerDetails = getAssociatedPartner(partnerList, device.getDeviceProviderId(), userId); + partnerHelper.checkIfPartnerIsNotActive(partnerDetails); } if (!device.getApprovalStatus().equals(APPROVED)) { LOGGER.error("Unable to deactivate device with id {}", device.getId()); @@ -608,6 +590,25 @@ public ResponseWrapperV2 deactivateDevice(String device return responseWrapper; } + public Partner getAssociatedPartner (List partnerList, String deviceProviderId, String userId) { + boolean deviceProviderExist = false; + Partner partnerDetails = null; + for (Partner partner : partnerList) { + if (partner.getId().equals(deviceProviderId)) { + validatePartnerId(partner, userId); + deviceProviderExist = true; + partnerDetails = partner; + break; + } + } + if (!deviceProviderExist) { + LOGGER.info("sessionId", "idType", "id", "Device is not associated with user."); + throw new PartnerServiceException(ErrorCode.DEVICE_NOT_ASSOCIATED_WITH_USER.getErrorCode(), + ErrorCode.DEVICE_NOT_ASSOCIATED_WITH_USER.getErrorMessage()); + } + return partnerDetails; + } + @Override public ResponseWrapperV2> getAllDeviceDetails(String sortFieldName, String sortType, int pageNo, int pageSize, DeviceDetailFilterDto filterDto) { ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/FTPChipDetailServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/FTPChipDetailServiceImpl.java index e4558cd38d..3548676ce6 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/FTPChipDetailServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/FTPChipDetailServiceImpl.java @@ -559,7 +559,7 @@ public ResponseWrapperV2 deactivateFtm(String ftmId) { boolean isAdmin = partnerHelper.isPartnerAdmin(authUserDetails().getAuthorities().toString()); if(!isAdmin){ Partner partnerDetails = getAssociatedPartner(partnerList, ftm, userId); - checkIfPartnerIsNotActive(partnerDetails); + partnerHelper.checkIfPartnerIsNotActive(partnerDetails); } if (!ftm.getApprovalStatus().equals(APPROVED)) { @@ -619,7 +619,7 @@ public ResponseWrapperV2 getOriginalFtmCertif boolean isAdmin = partnerHelper.isPartnerAdmin(authUserDetails().getAuthorities().toString()); if(!isAdmin){ Partner partnerDetails = getAssociatedPartner(partnerList, ftm, userId); - checkIfPartnerIsNotActive(partnerDetails); + partnerHelper.checkIfPartnerIsNotActive(partnerDetails); } if (!(ftm.getApprovalStatus().equals(PENDING_APPROVAL) || ftm.getApprovalStatus().equals(APPROVED))) { @@ -731,14 +731,6 @@ public static void validateFtmChipDetail(Optional ftmChipDetail) } } - public static void checkIfPartnerIsNotActive(Partner partner) { - if (!partner.getIsActive()) { - LOGGER.error("Partner is not Active with id {}", partner.getId()); - throw new PartnerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(), - ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage()); - } - } - public Partner getAssociatedPartner(List partnerList, FTPChipDetail ftm, String userId) { String ftmProviderId = ftm.getFtpProviderId(); boolean ftmProviderExist = false; diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/SecureBiometricInterfaceServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/SecureBiometricInterfaceServiceImpl.java index e4a2b4cdf3..dfcce47274 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/SecureBiometricInterfaceServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/SecureBiometricInterfaceServiceImpl.java @@ -775,28 +775,11 @@ public ResponseWrapperV2 deactivateSbi(String sbiId) { ErrorCode.SBI_NOT_EXISTS.getErrorMessage()); } SecureBiometricInterface sbi = secureBiometricInterface.get(); - // check if the SBI is associated with user. - String sbiProviderId = sbi.getProviderId(); - boolean sbiProviderExist = false; - Partner partnerDetails = new Partner(); - for (Partner partner : partnerList) { - if (partner.getId().equals(sbiProviderId)) { - validatePartnerId(partner, userId); - sbiProviderExist = true; - partnerDetails = partner; - break; - } - } - if (!sbiProviderExist) { - LOGGER.info("sessionId", "idType", "id", "SBI is not associated with user."); - throw new PartnerServiceException(ErrorCode.SBI_NOT_ASSOCIATED_WITH_USER.getErrorCode(), - ErrorCode.SBI_NOT_ASSOCIATED_WITH_USER.getErrorMessage()); - } - //check if Partner is Active or not - if (!partnerDetails.getIsActive()) { - LOGGER.error("Partner is not Active with id {}", sbiProviderId); - throw new PartnerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(), - ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage()); + + boolean isAdmin = partnerHelper.isPartnerAdmin(authUserDetails().getAuthorities().toString()); + if (!isAdmin) { + Partner partnerDetails = getAssociatedPartner(partnerList, sbi.getProviderId(), userId); + partnerHelper.checkIfPartnerIsNotActive(partnerDetails); } if (!sbi.getApprovalStatus().equals(APPROVED)) { LOGGER.error("Unable to deactivate sbi with id {}", sbi.getId()); @@ -852,6 +835,25 @@ public ResponseWrapperV2 deactivateSbi(String sbiId) { return responseWrapper; } + public Partner getAssociatedPartner (List partnerList, String sbiProviderId, String userId) { + boolean sbiProviderExist = false; + Partner partnerDetails = null; + for (Partner partner : partnerList) { + if (partner.getId().equals(sbiProviderId)) { + validatePartnerId(partner, userId); + sbiProviderExist = true; + partnerDetails = partner; + break; + } + } + if (!sbiProviderExist) { + LOGGER.info("sessionId", "idType", "id", "SBI is not associated with user."); + throw new PartnerServiceException(ErrorCode.SBI_NOT_ASSOCIATED_WITH_USER.getErrorCode(), + ErrorCode.SBI_NOT_ASSOCIATED_WITH_USER.getErrorMessage()); + } + return partnerDetails; + } + @Override public ResponseWrapperV2> getAllSbiDetails(String sortFieldName, String sortType, int pageNo, int pageSize, SbiFilterDto filterDto) { ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); 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 fabf0a39e1..a5210770c6 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 @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.pms.common.constant.ApiAccessibleExceptionConstant; +import io.mosip.pms.common.entity.Partner; import io.mosip.pms.common.exception.ApiAccessibleException; import io.mosip.pms.common.repository.DeviceDetailSbiRepository; import io.mosip.pms.common.util.PMSLogger; @@ -310,4 +311,12 @@ public void validateRequestParameters(Map aliasToColumnMap, Stri ErrorCode.INVALID_PAGE_SIZE.getErrorMessage()); } } + + public void checkIfPartnerIsNotActive(Partner partner) { + if (!partner.getIsActive()) { + LOGGER.error("Partner is not Active with id {}", partner.getId()); + throw new PartnerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(), + ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage()); + } + } }