diff --git a/.github/workflows/tag.yaml.orig b/.github/workflows/tag.yaml.orig new file mode 100644 index 00000000000..b0e5bdff4e0 --- /dev/null +++ b/.github/workflows/tag.yaml.orig @@ -0,0 +1,75 @@ +name: Tagging of repos + +<<<<<<< HEAD +on: + workflow_dispatch: + inputs: + TAG: + description: 'Tag to be published' + required: true + type: string + BODY: +======= +env: + tag: v1.2.3 + +on: + workflow_dispatch: + inputs: + tag: + description: 'Tag to be published' + required: true + default: 'v1.2.3' + type: string + body: +>>>>>>> 81681ea2e2 ([MOSIP-20028] added action for tagging) + description: 'Release body message' + required: true + default: 'Changes in this Release' + type: string +<<<<<<< HEAD + PRE_RELEASE: +======= + pre-release: +>>>>>>> 81681ea2e2 ([MOSIP-20028] added action for tagging) + description: 'Pre-release? True/False' + required: true + default: False + type: string +<<<<<<< HEAD + DRAFT: + description: 'Draft? True/False' + required: false + default: False + type: string + +jobs: + tag-branch: + uses: mosip/kattu/.github/workflows/tag.yml@master + with: + TAG: ${{ inputs.TAG }} + BODY: ${{ inputs.BODY }} + PRE_RELEASE: ${{ inputs.PRE_RELEASE }} + DRAFT: ${{ inputs.DRAFT }} +======= + +jobs: + build: + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ github.event.inputs.tag }} + release_name: ${{ github.event.inputs.tag }} + body: | + ${{ github.event.inputs.body }} + draft: false + prerelease: ${{fromJSON(github.event.inputs.pre-release)}} +>>>>>>> 81681ea2e2 ([MOSIP-20028] added action for tagging) diff --git a/README.md b/README.md index 948c2591e96..f87f75f9398 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![Maven Package upon a push](https://github.com/mosip/id-authentication/actions/workflows/push_trigger.yml/badge.svg?branch=master)](https://github.com/mosip/id-authentication/actions/workflows/push_trigger.yml) -[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mosip_id-authentication&id=mosip_id-authentication&branch=master&metric=alert_status)](https://sonarcloud.io/dashboard?id=mosip_id-authentication&branch=master) +[![Maven Package upon a push](https://github.com/mosip/id-authentication/actions/workflows/push_trigger.yml/badge.svg?branch=release-1.2.0.1)](https://github.com/mosip/id-authentication/actions/workflows/push_trigger.yml) +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mosip_id-authentication&id=mosip_id-authentication&branch=release-1.2.0.1&metric=alert_status)](https://sonarcloud.io/dashboard?id=mosip_id-authentication&branch=release-1.2.0.1) # ID-Authentication diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java index 905d2b5371c..57fc40ffed2 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java @@ -51,6 +51,7 @@ import io.mosip.kernel.core.exception.ParseException; import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.DateUtils; +import io.mosip.kernel.core.util.StringUtils; /** * Service implementation of OtpTriggerService. @@ -165,17 +166,21 @@ public OtpResponseDTO generateOtp(OtpRequestDTO otpRequestDto, String partnerId, private void validateAllowedOtpChannles(String token, List otpChannel) throws IdAuthenticationFilterException { - if(otpChannel.stream().anyMatch(channel -> OTP.equalsIgnoreCase(channel))) { + if(containsChannel(otpChannel, OTP)) { checkAuthLock(token, OTP); } - else if(otpChannel.stream().anyMatch(channel -> PHONE.equalsIgnoreCase(channel))) { + else if(containsChannel(otpChannel, PHONE)) { checkAuthLock(token, OTP_SMS); } - else if(otpChannel.stream().anyMatch(channel -> EMAIL.equalsIgnoreCase(channel))) { + else if(containsChannel(otpChannel, EMAIL)) { checkAuthLock(token, OTP_EMAIL); } } + private static boolean containsChannel(List otpChannel, String channel) { + return otpChannel.stream().anyMatch(channelItem -> channel.equalsIgnoreCase(channelItem)); + } + private void checkAuthLock(String token, String authTypeCode) throws IdAuthenticationFilterException { List authTypeLocks = authLockRepository.findByTokenAndAuthtypecode(token, authTypeCode); for(AuthtypeLock authtypeLock : authTypeLocks) { @@ -224,6 +229,28 @@ private OtpResponseDTO doGenerateOTP(OtpRequestDTO otpRequestDto, String partner valueMap.put(IdAuthCommonConstants.PHONE_NUMBER, phoneNumber); valueMap.put(IdAuthCommonConstants.EMAIL, email); + List otpChannel = otpRequestDto.getOtpChannel(); + if (StringUtils.isBlank(phoneNumber) && containsChannel(otpChannel, PHONE) && !containsChannel(otpChannel, EMAIL)) { + throw new IdAuthenticationBusinessException( + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + + ". Phone Number is not found in identity data."); + } + + if (StringUtils.isBlank(email) && containsChannel(otpChannel, EMAIL) && !containsChannel(otpChannel, PHONE)) { + throw new IdAuthenticationBusinessException( + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + + ". Email ID is not found in identity data."); + } + + if(StringUtils.isBlank(phoneNumber) && StringUtils.isBlank(email) && (containsChannel(otpChannel, PHONE) && containsChannel(otpChannel, EMAIL))) { + throw new IdAuthenticationBusinessException( + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + + ". Both Phone Number and Email ID are not found in identity data."); + } + boolean isOtpGenerated = otpManager.sendOtp(otpRequestDto, individualId, individualIdType, valueMap, templateLanguages); @@ -321,9 +348,17 @@ private boolean isOtpFlooded(String token, String requestTime) throws IdAuthenti private void processChannel(String value, String phone, String email, MaskedResponseDTO maskedResponseDTO) throws IdAuthenticationBusinessException { if (value.equalsIgnoreCase(NotificationType.SMS.getChannel())) { - maskedResponseDTO.setMaskedMobile(MaskUtil.maskMobile(phone)); + if(phone != null && !phone.isEmpty()) { + maskedResponseDTO.setMaskedMobile(MaskUtil.maskMobile(phone)); + } else { + mosipLogger.warn("Phone Number is not available in identity data. But PHONE channel is requested for OTP."); + } } else if (value.equalsIgnoreCase(NotificationType.EMAIL.getChannel())) { - maskedResponseDTO.setMaskedEmail(MaskUtil.maskEmail(email)); + if(email != null && !email.isEmpty()) { + maskedResponseDTO.setMaskedEmail(MaskUtil.maskEmail(email)); + } else { + mosipLogger.warn("Email ID is not available in identity data. But email channel is requested for OTP."); + } } } diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java index 6e6445e44b1..6115f62ef9c 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java @@ -10,13 +10,13 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; +import java.util.AbstractMap.SimpleEntry; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; -import java.util.Map.Entry; -import java.util.AbstractMap.SimpleEntry; import javax.crypto.SecretKey; import javax.security.auth.x500.X500Principal; @@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import io.mosip.kernel.cryptomanager.dto.JWTEncryptRequestDto; import io.mosip.authentication.common.service.repository.IdaUinHashSaltRepo; import io.mosip.authentication.common.service.repository.IdentityCacheRepository; import io.mosip.authentication.common.service.util.EnvUtil; @@ -50,7 +51,6 @@ import io.mosip.kernel.crypto.jce.core.CryptoCore; import io.mosip.kernel.cryptomanager.dto.CryptomanagerRequestDto; import io.mosip.kernel.cryptomanager.dto.JWTCipherResponseDto; -import io.mosip.kernel.cryptomanager.dto.JWTEncryptRequestDto; import io.mosip.kernel.cryptomanager.service.CryptomanagerService; import io.mosip.kernel.cryptomanager.util.CryptomanagerUtils; import io.mosip.kernel.keygenerator.bouncycastle.KeyGenerator; @@ -193,7 +193,7 @@ public class IdAuthSecurityManager { @Autowired private IdTypeUtil idTypeUtil; - + /** * Gets the user. * diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java index 174ebec013f..6fd9a568fa2 100644 --- a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -215,23 +216,19 @@ public void TestgenerateOtp() throws IdAuthenticationBusinessException, RestServ @SuppressWarnings("rawtypes") @Test - public void TestPhonenumberisNull() throws IdAuthenticationBusinessException, RestServiceException { + public void TestPhonenumberisNull_Phone_Channel_Alone() throws IdAuthenticationBusinessException, RestServiceException { OtpRequestDTO otpRequestDto = new OtpRequestDTO(); otpRequestDto.setId("id"); otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); otpRequestDto.setTransactionID("1234567890"); - ArrayList channelList = new ArrayList(); + List channelList = List.of("PHONE"); otpRequestDto.setOtpChannel(channelList); otpRequestDto.setIndividualId("2345678901234"); otpRequestDto.setIndividualIdType(IdType.UIN.getType()); otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); Map valueMap = new HashMap<>(); - Map> idInfo = new HashMap<>(); - List mailList = new ArrayList<>(); - IdentityInfoDTO identityInfoDTO = new IdentityInfoDTO(); - identityInfoDTO.setValue("abc@test.com"); - mailList.add(identityInfoDTO); - idInfo.put("email", mailList); + Map idInfo = new HashMap<>(); + idInfo.put("email", "abc@test.com"); valueMap.put("response", idInfo); Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) .thenReturn(valueMap); @@ -246,22 +243,134 @@ public void TestPhonenumberisNull() throws IdAuthenticationBusinessException, Re map.put("otp", "123456"); response.setResponse(map); Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); try { otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); } catch(IdAuthenticationBusinessException ex) { assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); - assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage(), ex.getErrorText()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Phone Number is not found in identity data.", ex.getErrorText()); } } - - @Test(expected = IdAuthenticationBusinessException.class) - public void TestPhoneorEmailisNull() throws IdAuthenticationBusinessException, RestServiceException { + + @SuppressWarnings("rawtypes") + @Test + public void TestPhonenumberisNull_bothChannels() throws IdAuthenticationBusinessException, RestServiceException { OtpRequestDTO otpRequestDto = new OtpRequestDTO(); otpRequestDto.setId("id"); otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); otpRequestDto.setTransactionID("1234567890"); - ArrayList channelList = new ArrayList(); + List channelList = List.of("PHONE", "EMAIL"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("email", "abc@test.com"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + } + + @SuppressWarnings("rawtypes") + @Test + public void TestEmailIdisNull_Email_Channel_Alone() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("EMAIL"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("phone", "9292292934"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + try { + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); + } + catch(IdAuthenticationBusinessException ex) { + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Email ID is not found in identity data.", ex.getErrorText()); + } + } + + @SuppressWarnings("rawtypes") + @Test + public void TestEmailIdisNull_bothChannels() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("PHONE", "EMAIL"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("phone", "9384848384"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + } + + @Test + public void TestPhoneorEmailisNull_both_channels_provided() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("PHONE", "EMAIL"); otpRequestDto.setOtpChannel(channelList); String individualId = "2345678901234"; otpRequestDto.setIndividualId(individualId); @@ -269,18 +378,6 @@ public void TestPhoneorEmailisNull() throws IdAuthenticationBusinessException, R otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); Map valueMap = new HashMap<>(); Map> idInfo = new HashMap<>(); - List mailList = new ArrayList<>(); - IdentityInfoDTO identityInfoDTO = new IdentityInfoDTO(); - identityInfoDTO.setValue("abc@bc.com"); - mailList.add(identityInfoDTO); - List phoneList = new ArrayList<>(); - IdentityInfoDTO identityInfoDTO1 = new IdentityInfoDTO(); - identityInfoDTO1.setValue("9876543210"); - phoneList.add(identityInfoDTO1); - idInfo.put("email", mailList); - idInfo.put("mobile", phoneList); - valueMap.put("uin", "426789089018"); - valueMap.put("phone", "426789089018"); valueMap.put("response", idInfo); Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) .thenReturn(valueMap); @@ -303,8 +400,210 @@ public void TestPhoneorEmailisNull() throws IdAuthenticationBusinessException, R Mockito.when(restHelper.requestSync(Mockito.any())).thenThrow(new RestServiceException( IdRepoErrorConstants.CLIENT_ERROR, response.toString(), response)); + try { + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); + } catch (IdAuthenticationBusinessException ex) { + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Both Phone Number and Email ID are not found in identity data.", ex.getErrorText()); + } + } + + + @SuppressWarnings("rawtypes") + @Test + public void TestPhonenumberisNull_Phone_Channel_Alone_lowercase() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("phone"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("email", "abc@test.com"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + try { + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); + } + catch(IdAuthenticationBusinessException ex) { + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Phone Number is not found in identity data.", ex.getErrorText()); + } + } + + @SuppressWarnings("rawtypes") + @Test + public void TestPhonenumberisNull_bothChannels_lowercase() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("phone", "email"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("email", "abc@test.com"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + } + + @SuppressWarnings("rawtypes") + @Test + public void TestEmailIdisNull_Email_Channel_Alone_lowercase() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("email"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("phone", "9292292934"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + try { + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); + } + catch(IdAuthenticationBusinessException ex) { + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Email ID is not found in identity data.", ex.getErrorText()); + } + } + + @SuppressWarnings("rawtypes") + @Test + public void TestEmailIdisNull_bothChannels_lowercase() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("phone", "email"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("phone", "9384848384"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); } + + @Test + public void TestPhoneorEmailisNull_both_channels_provided_lowercase() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("phone", "email"); + otpRequestDto.setOtpChannel(channelList); + String individualId = "2345678901234"; + otpRequestDto.setIndividualId(individualId); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map> idInfo = new HashMap<>(); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn(individualId); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + List errors = new ArrayList<>(); + ServiceError serviceError = new ServiceError(); + serviceError.setErrorCode(OtpErrorConstants.EMAILPHONENOTREGISTERED.getErrorCode()); + serviceError.setMessage(OtpErrorConstants.EMAILPHONENOTREGISTERED.getErrorMessage()); + errors.add(serviceError); + response.setErrors(errors); + + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + + Mockito.when(restHelper.requestSync(Mockito.any())).thenThrow(new RestServiceException( + IdRepoErrorConstants.CLIENT_ERROR, response.toString(), response)); + try { + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); + } catch (IdAuthenticationBusinessException ex) { + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Both Phone Number and Email ID are not found in identity data.", ex.getErrorText()); + } + } @Test(expected = IdAuthenticationBusinessException.class) public void TestOtpFloodException() throws IdAuthenticationBusinessException { @@ -363,7 +662,7 @@ private OtpRequestDTO getOtpRequestDTO() { // otpRequestDto.setRequestTime(new SimpleDateFormat(env.getDateTimePattern()).format(new Date())); otpRequestDto.setTransactionID("1234567890"); ArrayList channelList = new ArrayList(); - channelList.add("MOBILE"); + channelList.add("PHONE"); channelList.add("EMAIL"); otpRequestDto.setOtpChannel(channelList); otpRequestDto.setIndividualId("2345678901234"); diff --git a/authentication/authentication-core/pom.xml b/authentication/authentication-core/pom.xml index 48b32159874..625539c9863 100644 --- a/authentication/authentication-core/pom.xml +++ b/authentication/authentication-core/pom.xml @@ -1,194 +1,194 @@ - - 4.0.0 - - - io.mosip.authentication - authentication-parent - 1.2.1-SNAPSHOT - - 1.2.1-SNAPSHOT - - authentication-core - jar - - authentication-core - Maven project of MOSIP ID-Authentication Core - - - - - io.mosip.kernel - kernel-core - ${kernel-core.version} - - - org.springframework.boot - - spring-boot-starter-security - - - - com.fasterxml.jackson.core - jackson-databind - - - - - - - - commons-codec - commons-codec - ${commons.codec.version} - - - org.apache.commons - commons-lang3 - ${commons.lang.version} - - - - org.springframework.boot - spring-boot-starter-web - ${spring.boot.version} - - - com.fasterxml.jackson.core - jackson-databind - - - - - org.springframework.boot - spring-boot-starter-cache - ${spring.boot.version} - - - - - com.machinezoo.sourceafis - sourceafis - ${sourceafis.version} - - - com.fasterxml.jackson.core - jackson-databind - - - - - - io.mosip.idrepository - id-repository-core - ${id-repository-core.version} - - - io.mosip.kernel - kernel-auth-adapter - - - org.springframework.boot - - spring-boot-starter-security - - - - org.springframework.security - spring-security-test - - - - - io.mosip.kernel - kernel-biosdk-provider - ${kernel-biosdk-provider.version} - - - io.mosip.kernel - kernel-core - - - io.mosip.kernel - kernel-biometrics-api - - - - - io.mosip.kernel - kernel-demographics-api - ${kernel-demoapi.version} - - - com.fasterxml.jackson.core - jackson-databind - - - - - org.springframework.boot - spring-boot-starter-webflux - ${spring.boot.version} - - - com.fasterxml.jackson.core - jackson-databind - - - - - org.springdoc - springdoc-openapi-ui - ${springdoc.version} - - - com.fasterxml.jackson.core - jackson-databind - - - - - io.mosip.kernel - kernel-logger-logback - ${kernel-logger-logback.version} - - - org.springframework.boot - - spring-boot-starter-security - - - - com.fasterxml.jackson.core - jackson-databind - - - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - com.fasterxml.jackson.module - jackson-module-afterburner - ${jackson.version} - - - io.mosip.kernel - kernel-biometrics-api - ${kernel-biometrics-api.version} - - - io.mosip.kernel - kernel-core - - - com.fasterxml.jackson.core - jackson-databind - - - - - \ No newline at end of file + + 4.0.0 + + + io.mosip.authentication + authentication-parent + 1.2.1-SNAPSHOT + + 1.2.1-SNAPSHOT + + authentication-core + jar + + authentication-core + Maven project of MOSIP ID-Authentication Core + + + + + io.mosip.kernel + kernel-core + ${kernel-core.version} + + + org.springframework.boot + + spring-boot-starter-security + + + + com.fasterxml.jackson.core + jackson-databind + + + + + + + + commons-codec + commons-codec + ${commons.codec.version} + + + org.apache.commons + commons-lang3 + ${commons.lang.version} + + + + org.springframework.boot + spring-boot-starter-web + ${spring.boot.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + + org.springframework.boot + spring-boot-starter-cache + ${spring.boot.version} + + + + + com.machinezoo.sourceafis + sourceafis + ${sourceafis.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + + + io.mosip.idrepository + id-repository-core + ${id-repository-core.version} + + + io.mosip.kernel + kernel-auth-adapter + + + org.springframework.boot + + spring-boot-starter-security + + + + org.springframework.security + spring-security-test + + + + + io.mosip.kernel + kernel-biosdk-provider + ${kernel-biosdk-provider.version} + + + io.mosip.kernel + kernel-core + + + io.mosip.kernel + kernel-biometrics-api + + + + + io.mosip.kernel + kernel-demographics-api + ${kernel-demoapi.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + + org.springframework.boot + spring-boot-starter-webflux + ${spring.boot.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + + org.springdoc + springdoc-openapi-ui + ${springdoc.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + + io.mosip.kernel + kernel-logger-logback + ${kernel-logger-logback.version} + + + org.springframework.boot + + spring-boot-starter-security + + + + com.fasterxml.jackson.core + jackson-databind + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + com.fasterxml.jackson.module + jackson-module-afterburner + ${jackson.version} + + + io.mosip.kernel + kernel-biometrics-api + ${kernel-biometrics-api.version} + + + io.mosip.kernel + kernel-core + + + com.fasterxml.jackson.core + jackson-databind + + + + + diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/spi/indauth/match/MatchType.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/spi/indauth/match/MatchType.java index 9866f289c78..cc4d4343e12 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/spi/indauth/match/MatchType.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/spi/indauth/match/MatchType.java @@ -1,207 +1,207 @@ -package io.mosip.authentication.core.spi.indauth.match; - -import java.util.AbstractMap.SimpleEntry; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; -import io.mosip.authentication.core.indauth.dto.AuthRequestDTO; -import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO; -import io.mosip.authentication.core.indauth.dto.RequestDTO; - -/** - * Base interface for the match type. - * - * @author Loganathan Sekar - * @author Dinesh Karuppiah.T - */ -public interface MatchType { - - /** - * The Category Enum - */ - public enum Category { - - /** Demo category */ - DEMO("demo"), - /** OTP category */ - OTP("otp"), - /** Bio category */ - BIO("bio"), - /** s-pin category. */ - SPIN("pin"), - /** Token category */ - KBT("kbt"); - - /** The type. */ - String type; - - /** - * Instantiates a Category. - * - * @param type the type - */ - private Category(String type) { - this.type = type; - } - - /** - * Gets the type. - * - * @return the type - */ - public String getType() { - return type; - } - - /** - * Get the category for the type. - * - * @param type the type - * @return Optional of category - */ - public static Optional getCategory(String type) { - return Stream.of(values()).filter(t -> t.getType().equals(type)).findAny(); - } - - } - - /** - * Gets the IDMapping. - * - * @return ID Mapping - */ - public IdMapping getIdMapping(); - - /** - * Gets the allowed matching strategy for the MatchingStrategyType value. - * - * @param matchStrategyType the match strategy type - * @return the allowed matching strategy - */ - Optional getAllowedMatchingStrategy(MatchingStrategyType matchStrategyType); - - /** - * Get the Identity Info Function. - * - * @return the Identity Info Function - */ - public Function>> getIdentityInfoFunction(); - - /** - * Get the Identity Info Function. - * - * @return the reqest info function - */ - public default Function> getReqestInfoFunction() { - return req -> Collections.emptyMap(); - } - - /** - * Get the IdentityInfoDTO list out of the identity block for this MatchType. - * - * @param identity the IdentityDTO - * @return the list of IdentityInfoDTO - */ - public default List getIdentityInfoList(RequestDTO identity) { - return getIdentityInfoFunction().apply(identity).values().stream().filter(Objects::nonNull) - .flatMap(List::stream).collect(Collectors.toList()); - } - - /** - * Gets the Entity info mapper function. - * - * @return the Entity info mapper function - */ - public BiFunction, Map, Map> getEntityInfoMapper(); - - /** - * Get the category of this MatchType. - * - * @return the category - */ - public Category getCategory(); - - /** - * Flag to fetch Identity Info. - * - * @return boolean value true or false - */ - public default boolean hasIdEntityInfo() { - return true; - } - - /** - * Flag to fetch Request Entity Info. - * - * @return the flag - */ - public default boolean hasRequestEntityInfo() { - return false; - } - - /** - * Flag to check MultiLanguage. - * - * @return the flag - */ - public default boolean isMultiLanguage() { - return false; - } - - public default boolean isMultiLanguage(String propName, Map> identityEntity, MappingConfig mappingConfig) { - return isMultiLanguage(); - } - /** - * Returns the set of given matching strategies. - * - * @param items the matching strategies - * @return the sets the - */ - public static Set setOf(T... items) { - return Stream.of(items).collect(Collectors.toSet()); - - } - - /** - * To fetch Map Entity Info. - * - * @param idEntity the id entity - * @param idInfoHelper the id info helper - * @return the map - * @throws IdAuthenticationBusinessException the id authentication business exception - */ - public default Map>> mapEntityInfo( - Map> idEntity, IdInfoFetcher idInfoHelper) - throws IdAuthenticationBusinessException { - return idEntity.entrySet().stream() - .collect(Collectors.toMap(Entry::getKey, entry -> new SimpleEntry<>(entry.getKey(), entry.getValue()))); - } - - /** - * Check if the mapped property is of multi-language type. - * - * @param propName mapped property name - * @param cfg mapping - * @return true, if is prop multi lang - */ - public default boolean isPropMultiLang(String propName, MappingConfig cfg) { - return false; - } - - public default boolean isDynamic() { - return false; - } - -} +package io.mosip.authentication.core.spi.indauth.match; + +import java.util.AbstractMap.SimpleEntry; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; +import io.mosip.authentication.core.indauth.dto.AuthRequestDTO; +import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO; +import io.mosip.authentication.core.indauth.dto.RequestDTO; + +/** + * Base interface for the match type. + * + * @author Loganathan Sekar + * @author Dinesh Karuppiah.T + */ +public interface MatchType { + + /** + * The Category Enum + */ + public enum Category { + + /** Demo category */ + DEMO("demo"), + /** OTP category */ + OTP("otp"), + /** Bio category */ + BIO("bio"), + /** s-pin category. */ + SPIN("pin"), + /** Token category */ + KBT("kbt"); + + /** The type. */ + String type; + + /** + * Instantiates a Category. + * + * @param type the type + */ + private Category(String type) { + this.type = type; + } + + /** + * Gets the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Get the category for the type. + * + * @param type the type + * @return Optional of category + */ + public static Optional getCategory(String type) { + return Stream.of(values()).filter(t -> t.getType().equals(type)).findAny(); + } + + } + + /** + * Gets the IDMapping. + * + * @return ID Mapping + */ + public IdMapping getIdMapping(); + + /** + * Gets the allowed matching strategy for the MatchingStrategyType value. + * + * @param matchStrategyType the match strategy type + * @return the allowed matching strategy + */ + Optional getAllowedMatchingStrategy(MatchingStrategyType matchStrategyType); + + /** + * Get the Identity Info Function. + * + * @return the Identity Info Function + */ + public Function>> getIdentityInfoFunction(); + + /** + * Get the Identity Info Function. + * + * @return the reqest info function + */ + public default Function> getReqestInfoFunction() { + return req -> Collections.emptyMap(); + } + + /** + * Get the IdentityInfoDTO list out of the identity block for this MatchType. + * + * @param identity the IdentityDTO + * @return the list of IdentityInfoDTO + */ + public default List getIdentityInfoList(RequestDTO identity) { + return getIdentityInfoFunction().apply(identity).values().stream().filter(Objects::nonNull) + .flatMap(List::stream).collect(Collectors.toList()); + } + + /** + * Gets the Entity info mapper function. + * + * @return the Entity info mapper function + */ + public BiFunction, Map, Map> getEntityInfoMapper(); + + /** + * Get the category of this MatchType. + * + * @return the category + */ + public Category getCategory(); + + /** + * Flag to fetch Identity Info. + * + * @return boolean value true or false + */ + public default boolean hasIdEntityInfo() { + return true; + } + + /** + * Flag to fetch Request Entity Info. + * + * @return the flag + */ + public default boolean hasRequestEntityInfo() { + return false; + } + + /** + * Flag to check MultiLanguage. + * + * @return the flag + */ + public default boolean isMultiLanguage() { + return false; + } + + public default boolean isMultiLanguage(String propName, Map> identityEntity, MappingConfig mappingConfig) { + return isMultiLanguage(); + } + /** + * Returns the set of given matching strategies. + * + * @param items the matching strategies + * @return the sets the + */ + public static Set setOf(T... items) { + return Stream.of(items).collect(Collectors.toSet()); + + } + + /** + * To fetch Map Entity Info. + * + * @param idEntity the id entity + * @param idInfoHelper the id info helper + * @return the map + * @throws IdAuthenticationBusinessException the id authentication business exception + */ + public default Map>> mapEntityInfo( + Map> idEntity, IdInfoFetcher idInfoHelper) + throws IdAuthenticationBusinessException { + return idEntity.entrySet().stream() + .collect(Collectors.toMap(Entry::getKey, entry -> new SimpleEntry<>(entry.getKey(), entry.getValue()))); + } + + /** + * Check if the mapped property is of multi-language type. + * + * @param propName mapped property name + * @param cfg mapping + * @return true, if is prop multi lang + */ + public default boolean isPropMultiLang(String propName, MappingConfig cfg) { + return false; + } + + public default boolean isDynamic() { + return false; + } + +} diff --git a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/OtpApplication.java b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/OtpApplication.java index 1ff03c538c8..8eada82060b 100644 --- a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/OtpApplication.java +++ b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/OtpApplication.java @@ -125,4 +125,4 @@ public static void main(String[] args) { SpringApplication.run(OtpApplication.class, args); } -} \ No newline at end of file +} diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/IdAuthenticationApplication.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/IdAuthenticationApplication.java index d5f0a4600cf..1f54f60bdec 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/IdAuthenticationApplication.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/IdAuthenticationApplication.java @@ -79,6 +79,7 @@ import io.mosip.kernel.keygenerator.bouncycastle.KeyGenerator; import io.mosip.kernel.keymanager.hsm.impl.KeyStoreImpl; import io.mosip.kernel.keymanagerservice.helper.KeymanagerDBHelper; +import io.mosip.kernel.keymanagerservice.helper.PrivateKeyDecryptorHelper; import io.mosip.kernel.keymanagerservice.helper.SessionKeyDecrytorHelper; import io.mosip.kernel.keymanagerservice.service.impl.KeymanagerServiceImpl; import io.mosip.kernel.keymanagerservice.util.KeymanagerUtil; @@ -91,7 +92,7 @@ import io.mosip.kernel.tokenidgenerator.service.impl.TokenIDGeneratorServiceImpl; import io.mosip.kernel.zkcryptoservice.service.impl.ZKCryptoManagerServiceImpl; import io.mosip.kernel.keymanager.hsm.health.HSMHealthCheck; -import io.mosip.kernel.keymanagerservice.helper.PrivateKeyDecryptorHelper; + /** * Spring-boot class for ID Authentication Application. @@ -121,7 +122,7 @@ IdAuthFraudAnalysisEventManager.class, IdAuthFraudAnalysisEventPublisher.class, AuthFiltersValidator.class, AuthAnonymousProfileServiceImpl.class, AuthAnonymousEventPublisher.class, SessionKeyDecrytorHelper.class, ExternalRestHelperConfig.class, IdaRequestResponsConsumerUtil.class, PartnerCACertEventServiceImpl.class, PartnerCACertEventInitializer.class, EnvUtil.class, KeyBindedTokenMatcherUtil.class, - HSMHealthCheck.class, PrivateKeyDecryptorHelper.class, TokenValidationHelper.class, VCSchemaProviderUtil.class }) + HSMHealthCheck.class, TokenValidationHelper.class, VCSchemaProviderUtil.class, PrivateKeyDecryptorHelper.class }) @ComponentScan(basePackages = { "io.mosip.authentication.service.*", "io.mosip.kernel.core.logger.config", "io.mosip.authentication.common.service.config", "${mosip.auth.adapter.impl.basepackage}" }, excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = { "io.mosip.idrepository.core.config.IdRepoDataSourceConfig.*" })) @@ -138,4 +139,4 @@ public static void main(String[] args) { SpringApplication.run(IdAuthenticationApplication.class, args); } -} \ No newline at end of file +} diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/facade/KycFacadeImpl.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/facade/KycFacadeImpl.java index 10c2f0bac75..2b94fa585ef 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/facade/KycFacadeImpl.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/facade/KycFacadeImpl.java @@ -435,6 +435,7 @@ public KycExchangeResponseDTO processKycExchange(KycExchangeRequestDTO kycExchan String respJson = kycService.buildKycExchangeResponse(psuToken, idInfo, allowedConsentAttributes, locales, idVid, kycExchangeRequestDTO); // update kyc token status + //KycTokenData kycTokenData = kycTokenDataOpt.get(); kycTokenData.setKycTokenStatus(KycTokenStatusType.PROCESSED.getStatus()); kycTokenDataRepo.saveAndFlush(kycTokenData); KycExchangeResponseDTO kycExchangeResponseDTO = new KycExchangeResponseDTO(); @@ -458,6 +459,7 @@ public KycExchangeResponseDTO processKycExchange(KycExchangeRequestDTO kycExchan } } + // Need to move below duplicate code to common to be used by OTPService and KycExchange. private void saveToTxnTable(KycExchangeRequestDTO kycExchangeRequestDTO, boolean isInternal, boolean status, String partnerId, String token, KycExchangeResponseDTO kycExchangeResponseDTO, ObjectWithMetadata requestWithMetadata) diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/impl/KycServiceImpl.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/impl/KycServiceImpl.java index 55258f26768..5bd9d2579e3 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/impl/KycServiceImpl.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/impl/KycServiceImpl.java @@ -452,8 +452,7 @@ public boolean isKycTokenExpire(LocalDateTime tokenIssuedDateTime, String kycTok @Override public String buildKycExchangeResponse(String subject, Map> idInfo, - List consentedAttributes, List consentedLocales, String idVid, KycExchangeRequestDTO kycExchangeRequestDTO) - throws IdAuthenticationBusinessException { + List consentedAttributes, List consentedLocales, String idVid, KycExchangeRequestDTO kycExchangeRequestDTO) throws IdAuthenticationBusinessException { mosipLogger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "buildKycExchangeResponse", "Building claims response for PSU token: " + subject); diff --git a/authentication/pom.xml b/authentication/pom.xml index 2e03e2c5d38..9fd4a07c817 100644 --- a/authentication/pom.xml +++ b/authentication/pom.xml @@ -5,7 +5,7 @@ io.mosip.authentication authentication-parent - 1.2.1-SNAPSHOT + 1.2.1-SNAPSHOT pom id-authentication @@ -54,6 +54,10 @@ false + + danubetech-maven-public + https://repo.danubetech.com/repository/maven-public/ + @@ -91,7 +95,7 @@ 1.2.1-SNAPSHOT ${kernel.parent.version} - ${kernel.parent.version} + 1.2.0.1-B3-SNAPSHOT ${kernel.parent.version} ${kernel.parent.version} ${kernel.parent.version} @@ -101,15 +105,14 @@ ${kernel.parent.version} ${kernel.parent.version} ${kernel.parent.version} - 1.2.1-SNAPSHOT + ${kernel.parent.version} ${kernel.parent.version} ${kernel.parent.version} - 1.2.1-SNAPSHOT + 1.2.0.1-B1 20180130 - ${kernel.parent.version} + 1.2.0.1-SNAPSHOT ${kernel.parent.version} - ${kernel.parent.version} - ${kernel.parent.version} + 1.2.0 11 @@ -158,7 +161,6 @@ 3.1 1.5.10 - @@ -246,12 +248,6 @@ ${spring.boot.version} true - - io.mosip.kernel - kernel-openid-bridge-api - ${kernel-openid-bridge-api.version} - provided - diff --git a/db_release_scripts/mosip_ida/deploy.properties b/db_release_scripts/mosip_ida/deploy.properties deleted file mode 100644 index f3bb4178a76..00000000000 --- a/db_release_scripts/mosip_ida/deploy.properties +++ /dev/null @@ -1,12 +0,0 @@ -DB_SERVERIP= -DB_PORT=30090 -SU_USER=postgres -DEFAULT_DB_NAME=postgres -MOSIP_DB_NAME=mosip_ida -SYSADMIN_USER=sysadmin -BASEPATH=/home/madmin/database_release -LOG_PATH=/home/madmin/logs/ -ALTER_SCRIPT_FLAG=1 -ALTER_SCRIPT_FILENAME=ida-scripts_release.sql -REVOKE_SCRIPT_FLAG=1 -REVOKE_SCRIPT_FILENAME=ida-scripts_revoke.sql diff --git a/db_release_scripts/mosip_ida/deploy.sh b/db_release_scripts/mosip_ida/deploy.sh deleted file mode 100644 index 611f507a7fb..00000000000 --- a/db_release_scripts/mosip_ida/deploy.sh +++ /dev/null @@ -1,92 +0,0 @@ -### -- --------------------------------------------------------------------------------------------------------- -### -- Script Name : IDA Release DB deploy -### -- Deploy Module : MOSIP IDA -### -- Purpose : To deploy IDA Database alter scripts for the release. -### -- Create By : Sadanandegowda -### -- Created Date : 25-Oct-2019 -### -- -### -- Modified Date Modified By Comments / Remarks -### -- ----------------------------------------------------------------------------------------------------------- - -### -- ----------------------------------------------------------------------------------------------------------- - -#########Properties file ############# -set -e -properties_file="$1" -release_version="$2" - echo `date "+%m/%d/%Y %H:%M:%S"` ": Properties File Name - $properties_file" - echo `date "+%m/%d/%Y %H:%M:%S"` ": DB Deploymnet Version - $release_version" -#properties_file="./app.properties" -if [ -f "$properties_file" ] -then - echo `date "+%m/%d/%Y %H:%M:%S"` ": Property file \"$properties_file\" found." - while IFS='=' read -r key value - do - key=$(echo $key | tr '.' '_') - eval ${key}=\${value} - done < "$properties_file" -else - echo `date "+%m/%d/%Y %H:%M:%S"` ": Property file not found, Pass property file name as argument." -fi -echo `date "+%m/%d/%Y %H:%M:%S"` ": ------------------ Database server and service status check for ${MOSIP_DB_NAME}------------------------" - -today=`date '+%d%m%Y_%H%M%S'`; -LOG="${LOG_PATH}${MOSIP_DB_NAME}-release-${release_version}-${today}.log" -touch $LOG - -SERVICE=$(PGPASSWORD=$SU_USER_PWD psql --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -t -c "select count(1) from pg_roles where rolname IN('sysadmin')";exit; > /dev/null) - -if [ "$SERVICE" -eq 0 ] || [ "$SERVICE" -eq 1 ] -then -echo `date "+%m/%d/%Y %H:%M:%S"` ": Postgres database server and service is up and running" | tee -a $LOG 2>&1 -else -echo `date "+%m/%d/%Y %H:%M:%S"` ": Postgres database server or service is not running" | tee -a $LOG 2>&1 -fi - -echo `date "+%m/%d/%Y %H:%M:%S"` ": ----------------------------------------------------------------------------------------" - -echo `date "+%m/%d/%Y %H:%M:%S"` ": Started sourcing the $MOSIP_DB_NAME Database Alter scripts" | tee -a $LOG 2>&1 - -echo `date "+%m/%d/%Y %H:%M:%S"` ": Database Alter scripts are sourcing from :$BASEPATH/$MOSIP_DB_NAME/" | tee -a $LOG 2>&1 - -#========================================DB Alter Scripts deployment process begins on IDMAP DB SERVER================================== - -echo `date "+%m/%d/%Y %H:%M:%S"` ": Alter scripts deployment on $MOSIP_DB_NAME database is started....Deployment Version...$release_version" | tee -a $LOG 2>&1 - -ALTER_SCRIPT_FILENAME_VERSION="sql/${release_version}_${ALTER_SCRIPT_FILENAME}" - -echo `date "+%m/%d/%Y %H:%M:%S"` ": Alter scripts file which is considered for release deployment - $ALTER_SCRIPT_FILENAME_VERSION" | tee -a $LOG 2>&1 - -cd /$BASEPATH/$MOSIP_DB_NAME/ - -pwd | tee -a $LOG 2>&1 - -CONN=$(PGPASSWORD=$SYSADMIN_PWD psql --username=$SYSADMIN_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -t -c "SELECT count(pg_terminate_backend(pg_stat_activity.pid)) FROM pg_stat_activity WHERE datname = '$MOSIP_DB_NAME' AND pid <> pg_backend_pid()";exit; >> $LOG 2>&1) - -if [ ${CONN} == 0 ] -then - echo `date "+%m/%d/%Y %H:%M:%S"` ": No active database connections exist on ${MOSIP_DB_NAME}" | tee -a $LOG 2>&1 -else - echo `date "+%m/%d/%Y %H:%M:%S"` ": Active connections exist on the database server and active connection will be terminated for DB deployment." | tee -a $LOG 2>&1 -fi - -if [ ${ALTER_SCRIPT_FLAG} == 1 ] -then - echo `date "+%m/%d/%Y %H:%M:%S"` ": Deploying Alter scripts for ${MOSIP_DB_NAME} database" | tee -a $LOG 2>&1 - PGPASSWORD=$SYSADMIN_PWD psql --username=$SYSADMIN_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -a -b -f $ALTER_SCRIPT_FILENAME_VERSION >> $LOG 2>&1 -else - echo `date "+%m/%d/%Y %H:%M:%S"` ": There are no alter scripts available for this deployment at ${MOSIP_DB_NAME}" | tee -a $LOG 2>&1 -fi - -if [ $(grep -c ERROR $LOG) -ne 0 ] -then - echo `date "+%m/%d/%Y %H:%M:%S"` ": Database Alter scripts deployment version $release_version is completed with ERRORS, Please check the logs for more information" | tee -a $LOG 2>&1 - echo `date "+%m/%d/%Y %H:%M:%S"` ": END of Alter scripts MOSIP database deployment" | tee -a $LOG 2>&1 -else - echo `date "+%m/%d/%Y %H:%M:%S"` ": Database Alter scripts deployment version $release_version completed successfully, Please check the logs for more information" | tee -a $LOG 2>&1 - echo `date "+%m/%d/%Y %H:%M:%S"` ": END of MOSIP \"${MOSIP_DB_NAME}\" database alter scripts deployment" | tee -a $LOG 2>&1 -fi - -echo "******************************************"`date "+%m/%d/%Y %H:%M:%S"` "*****************************************************" >> $LOG 2>&1 - - diff --git a/db_release_scripts/mosip_ida/revoke.sh b/db_release_scripts/mosip_ida/revoke.sh deleted file mode 100644 index 1402058d641..00000000000 --- a/db_release_scripts/mosip_ida/revoke.sh +++ /dev/null @@ -1,92 +0,0 @@ -### -- --------------------------------------------------------------------------------------------------------- -### -- Script Name : IDA Revoke DB deploy -### -- Deploy Module : MOSIP IDA -### -- Purpose : To revoke IDA Database alter scripts for the release. -### -- Create By : Sadanandegowda -### -- Created Date : 25-Oct-2019 -### -- -### -- Modified Date Modified By Comments / Remarks -### -- ----------------------------------------------------------------------------------------------------------- - -### -- ----------------------------------------------------------------------------------------------------------- - -#########Properties file ############# -set -e -properties_file="$1" -revoke_version="$2" - echo `date "+%m/%d/%Y %H:%M:%S"` ": $properties_file" - echo `date "+%m/%d/%Y %H:%M:%S"` ": DB Revoke Version - $revoke_version" -#properties_file="./app.properties" -if [ -f "$properties_file" ] -then - echo `date "+%m/%d/%Y %H:%M:%S"` ": Property file \"$properties_file\" found." - while IFS='=' read -r key value - do - key=$(echo $key | tr '.' '_') - eval ${key}=\${value} - done < "$properties_file" -else - echo `date "+%m/%d/%Y %H:%M:%S"` ": Property file not found, Pass property file name as argument." -fi -echo `date "+%m/%d/%Y %H:%M:%S"` ": ------------------ Database server and service status check for ${MOSIP_DB_NAME}------------------------" - -today=`date '+%d%m%Y_%H%M%S'`; -LOG="${LOG_PATH}${MOSIP_DB_NAME}-revoke-${today}.log" -touch $LOG - -SERVICE=$(PGPASSWORD=$SU_USER_PWD psql --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -t -c "select count(1) from pg_roles where rolname IN('sysadmin')";exit; > /dev/null) - -if [ "$SERVICE" -eq 0 ] || [ "$SERVICE" -eq 1 ] -then -echo `date "+%m/%d/%Y %H:%M:%S"` ": Postgres database server and service is up and running" | tee -a $LOG 2>&1 -else -echo `date "+%m/%d/%Y %H:%M:%S"` ": Postgres database server or service is not running" | tee -a $LOG 2>&1 -fi - -echo `date "+%m/%d/%Y %H:%M:%S"` ": ----------------------------------------------------------------------------------------" - -echo `date "+%m/%d/%Y %H:%M:%S"` ": Started sourcing the $MOSIP_DB_NAME Database Deployment Revoke scripts" | tee -a $LOG 2>&1 - -echo `date "+%m/%d/%Y %H:%M:%S"` ": Database revoke scripts are sourcing from :$BASEPATH/$MOSIP_DB_NAME/alter-scripts" | tee -a $LOG 2>&1 - -#========================================DB Alter Scripts deployment process begins on IDMAP DB SERVER================================== - -echo `date "+%m/%d/%Y %H:%M:%S"` ": Revoke scripts for DB deployment on $MOSIP_DB_NAME database is started....Revoke Version...$revoke_version" | tee -a $LOG 2>&1 - -REVOKE_SCRIPT_FILENAME_VERSION="sql/${revoke_version}_${REVOKE_SCRIPT_FILENAME}" - -echo `date "+%m/%d/%Y %H:%M:%S"` ": Alter scripts file which is considered for deployment revoke - $REVOKE_SCRIPT_FILENAME_VERSION" | tee -a $LOG 2>&1 - -cd /$BASEPATH/$MOSIP_DB_NAME/ - -pwd | tee -a $LOG 2>&1 - -CONN=$(PGPASSWORD=$SYSADMIN_PWD psql --username=$SYSADMIN_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -t -c "SELECT count(pg_terminate_backend(pg_stat_activity.pid)) FROM pg_stat_activity WHERE datname = '$MOSIP_DB_NAME' AND pid <> pg_backend_pid()";exit; >> $LOG 2>&1) - -if [ ${CONN} == 0 ] -then - echo `date "+%m/%d/%Y %H:%M:%S"` ": No active database connections exist on ${MOSIP_DB_NAME}" | tee -a $LOG 2>&1 -else - echo `date "+%m/%d/%Y %H:%M:%S"` ": Active connections exist on the database server and active connection will be terminated for DB deployment." | tee -a $LOG 2>&1 -fi - -if [ ${REVOKE_SCRIPT_FLAG} == 1 ] -then - echo `date "+%m/%d/%Y %H:%M:%S"` ": Executing revoke scripts for ${MOSIP_DB_NAME} database" | tee -a $LOG 2>&1 - PGPASSWORD=$SYSADMIN_PWD psql --username=$SYSADMIN_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -a -b -f $REVOKE_SCRIPT_FILENAME_VERSION >> $LOG 2>&1 -else - echo `date "+%m/%d/%Y %H:%M:%S"` ": There are no revoke scripts available for this deployment at ${MOSIP_DB_NAME}" | tee -a $LOG 2>&1 -fi - -if [ $(grep -c ERROR $LOG) -ne 0 ] -then - echo `date "+%m/%d/%Y %H:%M:%S"` ": Database deployment revoke version $revoke_version is completed with ERRORS, Please check the logs for more information" | tee -a $LOG 2>&1 - echo `date "+%m/%d/%Y %H:%M:%S"` ": END of Alter scripts MOSIP database deployment" | tee -a $LOG 2>&1 -else - echo `date "+%m/%d/%Y %H:%M:%S"` ": Database deployment revoke version $revoke_version completed successfully, Please check the logs for more information" | tee -a $LOG 2>&1 - echo `date "+%m/%d/%Y %H:%M:%S"` ": END of MOSIP \"${MOSIP_DB_NAME}\" database deployment revoke" | tee -a $LOG 2>&1 -fi - -echo "******************************************"`date "+%m/%d/%Y %H:%M:%S"` "*****************************************************" >> $LOG 2>&1 - - diff --git a/db_release_scripts/mosip_ida/sql/1.1.0_release.sql b/db_release_scripts/mosip_ida/sql/1.1.0_release.sql deleted file mode 100644 index 67be4d6aa13..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.1.0_release.sql +++ /dev/null @@ -1,38 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name: mosip_ida --- Release Version : 1.1 --- Purpose : Database Alter scripts for the release for ID Authentication DB. --- Create By : Sadanandegowda DM --- Created Date : May-2020 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- - -\c mosip_ida sysadmin - ----------------- KEY MANAGER DDL DEPLOYMENT ------------------ - -\ir ../ddl/ida-key_alias.sql -\ir ../ddl/ida-key_store.sql -\ir ../ddl/ida-key_policy_def.sql -\ir ../ddl/ida-key_policy_def_h.sql - -\ir ../ddl/ida-identity_cache.sql -\ir ../ddl/ida-data_encrypt_keystore.sql - - --------------- Level 1 data load scripts ------------------------ - ------ TRUNCATE ida.key_policy_def TABLE Data and It's reference Data and COPY Data from CSV file ----- -TRUNCATE TABLE ida.key_policy_def cascade ; - -\COPY ida.key_policy_def (app_id,key_validity_duration,is_active,cr_by,cr_dtimes) FROM './dml/ida-key_policy_def.csv' delimiter ',' HEADER csv; - - ------ TRUNCATE ida.key_policy_def_h TABLE Data and It's reference Data and COPY Data from CSV file ----- -TRUNCATE TABLE ida.key_policy_def_h cascade ; - -\COPY ida.key_policy_def_h (app_id,key_validity_duration,is_active,cr_by,cr_dtimes,eff_dtimes) FROM './dml/ida-key_policy_def_h.csv' delimiter ',' HEADER csv; - - ----------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/db_release_scripts/mosip_ida/sql/1.1.0_revoke.sql b/db_release_scripts/mosip_ida/sql/1.1.0_revoke.sql deleted file mode 100644 index 6f16edd83d3..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.1.0_revoke.sql +++ /dev/null @@ -1,21 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name: mosip_ida --- Release Version : 1.1 --- Purpose : Revoking Database Alter deployement done for release in ID Authentication DB. --- Create By : Sadanandegowda DM --- Created Date : May-2020 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- - -\c mosip_ida sysadmin - -DROP TABLE IF EXISTS ida.key_alias; -DROP TABLE IF EXISTS ida.key_store; -DROP TABLE IF EXISTS ida.key_policy_def; -DROP TABLE IF EXISTS ida.key_policy_def_h; - -DROP TABLE IF EXISTS ida.identity_cache; -DROP TABLE IF EXISTS ida.data_encrypt_keystore; - --- ------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/db_release_scripts/mosip_ida/sql/1.1.3_release.sql b/db_release_scripts/mosip_ida/sql/1.1.3_release.sql deleted file mode 100644 index fce33f9864c..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.1.3_release.sql +++ /dev/null @@ -1,18 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name : mosip_ida --- Release Version : 1.1.3 --- Purpose : Database Alter scripts for the release for ID Authentication DB. --- Create By : Sadanandegowda DM --- Created Date : Nov-2020 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- - -\c mosip_ida sysadmin - ------------------------------- ID Auth Alter Scripts Deploymnet ------------------------------------ - -ALTER TABLE ida.auth_transaction ADD COLUMN IF NOT EXISTS request_signature character varying; -ALTER TABLE ida.auth_transaction ADD COLUMN IF NOT EXISTS response_signature character varying; - ------------------------------------------------------------------------------------------------------ \ No newline at end of file diff --git a/db_release_scripts/mosip_ida/sql/1.1.3_revoke.sql b/db_release_scripts/mosip_ida/sql/1.1.3_revoke.sql deleted file mode 100644 index 407ef35d842..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.1.3_revoke.sql +++ /dev/null @@ -1,13 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name: mosip_ida --- Release Version : 1.1.3 --- Purpose : Revoking Database Alter deployement done for release in ID Authentication DB. --- Create By : Sadanandegowda DM --- Created Date : Nov-2020 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- - -\c mosip_ida sysadmin - --- ------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/db_release_scripts/mosip_ida/sql/1.1.4_release.sql b/db_release_scripts/mosip_ida/sql/1.1.4_release.sql deleted file mode 100644 index 0c76eef90a1..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.1.4_release.sql +++ /dev/null @@ -1,17 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name : mosip_ida --- Release Version : 1.1.4 --- Purpose : Database Alter scripts for the release for ID Authentication DB. --- Create By : Sadanandegowda DM --- Created Date : Dec-2020 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- - -\c mosip_ida sysadmin - ----------------- KEY MANAGER DDL DEPLOYMENT ------------------ - -\ir ../ddl/ida-ca_cert_store.sql - ----------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/db_release_scripts/mosip_ida/sql/1.1.4_revoke.sql b/db_release_scripts/mosip_ida/sql/1.1.4_revoke.sql deleted file mode 100644 index 77d891410a5..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.1.4_revoke.sql +++ /dev/null @@ -1,14 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name: mosip_ida --- Release Version : 1.1.4 --- Purpose : Revoking Database Alter deployement done for release in ID Authentication DB. --- Create By : Sadanandegowda DM --- Created Date : Sep-2020 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- - -\c mosip_ida sysadmin - -DROP TABLE IF EXISTS ida.ca_cert_store; --- ------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/db_release_scripts/mosip_ida/sql/1.1.5_release.sql b/db_release_scripts/mosip_ida/sql/1.1.5_release.sql deleted file mode 100644 index f8c4d2832b4..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.1.5_release.sql +++ /dev/null @@ -1,69 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name : mosip_ida --- Release Version : 1.1.5 --- Purpose : Database Alter scripts for the release for ID Authentication DB. --- Create By : Sadanandegowda DM --- Created Date : Jan-2021 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- --- Jan-2021 Ram Bhatt Set is_deleted flag to not null and default false --- Feb-2021 Ram Bhatt Added hotlist table in ida --- Feb-2021 Ram Bhatt Changed size of auth_type_code from 32 to 128 --- Mar-2021 Ram Bhatt Reverting is_deleted not null changes ----------------------------------------------------------------------------------------------------- -\c mosip_ida sysadmin - ----------------- KEY MANAGER DDL DEPLOYMENT ------------------ - -\ir ../ddl/ida-credential_event_store.sql - - -\ir ../ddl/ida-batch_job_execution.sql -\ir ../ddl/ida-batch_job_execution_context.sql -\ir ../ddl/ida-batch_job_execution_params.sql -\ir ../ddl/ida-batch_job_instance.sql -\ir ../ddl/ida-batch_step_execution.sql -\ir ../ddl/ida-batch_step_execution_context.sql - -\ir ../ddl/ida-fk.sql - ----------------------------------------------------------------------------------------------------- - ---------- --------------ALTER TABLE SCRIPT DEPLOYMENT ------------------------------------------------ - ---ALTER TABLE ida.auth_transaction ALTER COLUMN is_deleted SET NOT NULL; ---ALTER TABLE ida.identity_cache ALTER COLUMN is_deleted SET NOT NULL; ---ALTER TABLE ida.key_policy_def_h ALTER COLUMN is_deleted SET NOT NULL; ---ALTER TABLE ida.key_policy_def ALTER COLUMN is_deleted SET NOT NULL; ---ALTER TABLE ida.key_store ALTER COLUMN is_deleted SET NOT NULL; ---ALTER TABLE ida.key_alias ALTER COLUMN is_deleted SET NOT NULL; ---ALTER TABLE ida.uin_auth_lock ALTER COLUMN is_deleted SET NOT NULL; ---ALTER TABLE ida.otp_transaction ALTER COLUMN is_deleted SET NOT NULL; ---ALTER TABLE ida.credential_event_store ALTER COLUMN is_deleted SET NOT NULL; ---ALTER TABLE ida.ca_cert_store ALTER COLUMN is_deleted SET NOT NULL; - ---ALTER TABLE ida.auth_transaction ALTER COLUMN is_deleted SET DEFAULT FALSE; ---ALTER TABLE ida.identity_cache ALTER COLUMN is_deleted SET DEFAULT FALSE; ---ALTER TABLE ida.key_policy_def_h ALTER COLUMN is_deleted SET DEFAULT FALSE; ---ALTER TABLE ida.key_policy_def ALTER COLUMN is_deleted SET DEFAULT FALSE; ---ALTER TABLE ida.key_store ALTER COLUMN is_deleted SET DEFAULT FALSE; ---ALTER TABLE ida.key_alias ALTER COLUMN is_deleted SET DEFAULT FALSE; ---ALTER TABLE ida.uin_auth_lock ALTER COLUMN is_deleted SET DEFAULT FALSE; ---ALTER TABLE ida.otp_transaction ALTER COLUMN is_deleted SET DEFAULT FALSE; ---ALTER TABLE ida.credential_event_store ALTER COLUMN is_deleted SET DEFAULT FALSE; ---ALTER TABLE ida.ca_cert_store ALTER COLUMN is_deleted SET DEFAULT FALSE; -------------------------------------------------------------------------------------------------------- ---------------------------------------HOTLISTING TABLE DEPLOYMENT----------------------------------------- - -\ir ../ddl/ida-hotlist_cache.sql - ----------------------------------------------------------------------------------------------------------- ---------------------------------------AUTH TYPE CODE SIZE CHANGE----------------------------------------- - - -ALTER TABLE ida.auth_transaction ALTER COLUMN auth_type_code TYPE character varying(128); - ----------------------------------------------------------------------------------------------------------- - - diff --git a/db_release_scripts/mosip_ida/sql/1.1.5_revoke.sql b/db_release_scripts/mosip_ida/sql/1.1.5_revoke.sql deleted file mode 100644 index 0c8f7947ea9..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.1.5_revoke.sql +++ /dev/null @@ -1,15 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name: mosip_ida --- Release Version : 1.1.5 --- Purpose : Revoking Database Alter deployement done for release in ID Authentication DB. --- Create By : Sadanandegowda DM --- Created Date : Sep-2020 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- - -\c mosip_ida sysadmin - -DROP TABLE IF EXISTS ida.credential_event_store; - --- ------------------------------------------------------------------------------------------------- diff --git a/db_release_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1_revoke.sql b/db_release_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1_revoke.sql deleted file mode 100644 index c2fe3b98215..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1_revoke.sql +++ /dev/null @@ -1,22 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name: mosip_ida --- Release Version : 1.1.5 --- Purpose : Revoking Database Alter deployement done for release in ID Authentication DB. --- Create By : Ram Bhatt --- Created Date : Apr-2021 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- --- Apr-2021 Ram Bhatt create tables to store partner details --- Sep-2021 Loganathan Sekar create anonymous_profile table -------------------------------------------------------------------------------------------------- - -\c mosip_ida sysadmin - -ALTER TABLE ida.misp_license_data DROP COLUMN policy_id; - -ALTER TABLE ida.partner_mapping ALTER COLUMN api_key_id TYPE varchar(36); - -DROP TABLE IF EXISTS ida.oidc_client_data CASCADE; - -DROP TABLE IF EXISTS ida.kyc_token_store CASCADE; \ No newline at end of file diff --git a/db_release_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B2_revoke.sql b/db_release_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B2_revoke.sql deleted file mode 100644 index 1bff942e6bf..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B2_revoke.sql +++ /dev/null @@ -1,20 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name : mosip_ida --- Release Version : 1.2 --- Purpose : Database Alter scripts for the release for ID Authentication DB. --- Create By : Ram Bhatt --- Created Date : Apr-2021 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------- -\c mosip_ida sysadmin - -ALTER TABLE ida.kyc_token_store DROP COLUMN request_trn_id; - -DROP TABLE IF EXISTS ida.ident_binding_cert_store CASCADE; - -DELETE FROM ida.key_policy_def WHERE app_id='IDA_KYC_EXCHANGE'; - -DELETE FROM ida.key_policy_def WHERE app_id='IDA_KEY_BINDING' - diff --git a/db_release_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.1_upgrade.sql b/db_release_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.1_upgrade.sql deleted file mode 100644 index efb74c3babe..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.1_upgrade.sql +++ /dev/null @@ -1,47 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name : mosip_ida --- Release Version : 1.2.1 --- Purpose : Database Alter scripts for the release for ID Authentication DB. --- Create By : Mahammed Taheer --- Created Date : Aug-2023 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------- -\c mosip_ida sysadmin - -CREATE TABLE ida.cred_subject_id_store( - id character varying(36) NOT NULL, - id_vid_hash character varying(128) NOT NULL, - token_id character varying(128) NOT NULL, - cred_subject_id character varying(2000) NOT NULL, - csid_key_hash character varying(128) NOT NULL, - oidc_client_id character varying(128), - csid_status character varying(36), - cr_by character varying(256) NOT NULL, - cr_dtimes timestamp NOT NULL, - upd_by character varying(256), - upd_dtimes timestamp, - is_deleted boolean DEFAULT FALSE, - del_dtimes timestamp, - CONSTRAINT key_hash_unique UNIQUE (id_vid_hash, csid_key_hash) -); -COMMENT ON TABLE ida.cred_subject_id_store IS 'Credential Subject Id Store: To store and maintain the input credential subject ids to identify the individual.'; -COMMENT ON COLUMN ida.cred_subject_id_store.id IS 'ID: Id is a unique identifier (UUID) used to map uniqueness to the credential subject id.'; -COMMENT ON COLUMN ida.cred_subject_id_store.id_vid_hash IS 'IdVidHash: SHA 256 Hash value of the Id/VID.'; -COMMENT ON COLUMN ida.cred_subject_id_store.token_id IS 'Token ID: Token ID generated in reference to UIN/VID'; -COMMENT ON COLUMN ida.cred_subject_id_store.cred_subject_id IS 'Credential Subject ID : DID format holder id.'; -COMMENT ON COLUMN ida.cred_subject_id_store.csid_key_hash IS 'Credential Subject ID Public Key Hash: Derived hash value of the public key.'; -COMMENT ON COLUMN ida.cred_subject_id_store.oidc_client_id IS 'OIDC Client ID: An Id assigned to specific OIDC Client.'; -COMMENT ON COLUMN ida.cred_subject_id_store.csid_status IS 'Credential Subject Id Status: To identify the current status of the credential subject id.'; -COMMENT ON COLUMN ida.cred_subject_id_store.cr_by IS 'Created By : ID or name of the user who create / insert record'; -COMMENT ON COLUMN ida.cred_subject_id_store.cr_dtimes IS 'Created DateTimestamp : Date and Timestamp when the record is created/inserted'; -COMMENT ON COLUMN ida.cred_subject_id_store.upd_by IS 'Updated By : ID or name of the user who update the record with new values'; -COMMENT ON COLUMN ida.cred_subject_id_store.upd_dtimes IS 'Updated DateTimestamp : Date and Timestamp when any of the fields in the record is updated with new values.'; -COMMENT ON COLUMN ida.cred_subject_id_store.is_deleted IS 'IS_Deleted : Flag to mark whether the record is Soft deleted.'; -COMMENT ON COLUMN ida.cred_subject_id_store.del_dtimes IS 'Deleted DateTimestamp : Date and Timestamp when the record is soft deleted with is_deleted=TRUE'; - -CREATE INDEX ind_csid_key_hash ON ida.cred_subject_id_store (csid_key_hash); - -INSERT INTO ida.key_policy_def (app_id, key_validity_duration, is_active, cr_by, cr_dtimes, upd_by, upd_dtimes, is_deleted, del_dtimes, pre_expire_days, access_allowed) -VALUES('IDA_VCI_EXCHANGE', 1095, true, 'mosipadmin', now(), NULL, NULL, false, NULL, 60, 'NA'); \ No newline at end of file diff --git a/db_release_scripts/mosip_ida/sql/1.2.0_release.sql b/db_release_scripts/mosip_ida/sql/1.2.0_release.sql deleted file mode 100644 index 66684f4aeaa..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.2.0_release.sql +++ /dev/null @@ -1,69 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name : mosip_ida --- Release Version : 1.1.2 --- Purpose : Database Alter scripts for the release for ID Authentication DB. --- Create By : Sadanandegowda DM --- Created Date : Sep-2020 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- - -DROP TABLE IF EXISTS ida.api_key_data CASCADE; -DROP TABLE IF EXISTS ida.partner_data CASCADE; -DROP TABLE IF EXISTS ida.partner_mapping CASCADE; -DROP TABLE IF EXISTS ida.policy_data CASCADE; -DROP TABLE IF EXISTS ida.misp_license_data CASCADE; -ALTER TABLE ida.uin_auth_lock ADD COLUMN unlock_expiry_datetime timestamp; -------------------------------------------------------------------------------------------------------- - -\ir ../ddl/ida-api_key_data.sql -\ir ../ddl/ida-partner_data.sql -\ir ../ddl/ida-partner_mapping.sql -\ir ../ddl/ida-policy_data.sql - - -\ir ../ddl/ida-misp_license_data.sql ----------------------------------------------------------------------------------------------------------- - -\ir ../ddl/ida-anonymous_profile.sql - -ALTER TABLE ida.identity_cache ADD COLUMN identity_expiry timestamp; --------------------------------------------------------------------------------------------------------------- - -CREATE INDEX ind_akd_apkeyid ON ida.api_key_data (api_key_id); -CREATE INDEX ind_pm_pid ON ida.partner_mapping (partner_id); -CREATE INDEX ind_pd_pid ON ida.partner_data (partner_id); -CREATE INDEX ind_mld_lk ON ida.misp_license_data (license_key); -CREATE INDEX ind_pd_pyid ON ida.policy_data (policy_id); -CREATE INDEX ind_reqtrnid_dtimes_tknid ON ida.auth_transaction (request_trn_id, request_dtimes, token_id, cr_dtimes, auth_type_code); -CREATE INDEX ind_ces_id ON ida.credential_event_store (cr_dtimes); -CREATE INDEX ind_hc_idhsh_etp ON ida.hotlist_cache (id_hash, expiry_timestamp); -CREATE INDEX ind_id ON ida.identity_cache (id); -CREATE INDEX ind_otphsh ON ida.otp_transaction (otp_hash,status_code); -CREATE INDEX ind_ual_id ON ida.uin_auth_lock (token_id); -CREATE INDEX ind_uhs_id ON ida.uin_hash_salt (id); - - ------------------------------------------------------------------------------------------------------------ -ALTER TABLE ida.key_alias ADD COLUMN cert_thumbprint character varying(100); -ALTER TABLE ida.ca_cert_store ADD CONSTRAINT cert_thumbprint_unique UNIQUE (cert_thumbprint,partner_domain); - - - --------------------------------------------------------------------------------------------------------------- -ALTER TABLE ida.key_alias ADD COLUMN uni_ident character varying(50); -ALTER TABLE ida.key_alias ADD CONSTRAINT uni_ident_const UNIQUE (uni_ident); - -ALTER TABLE ida.key_policy_def ADD COLUMN pre_expire_days smallint; -ALTER TABLE ida.key_policy_def ADD COLUMN access_allowed character varying(1024); - -ALTER TABLE ida.key_policy_def_h ADD COLUMN pre_expire_days smallint; -ALTER TABLE ida.key_policy_def_h ADD COLUMN access_allowed character varying(1024); ---------------------------------------------------------------------------------------------------------------- - -ALTER TABLE ida.uin_auth_lock ALTER COLUMN is_deleted SET DEFAULT FALSE; - - -update ida.key_policy_def set pre_expire_days=90, access_allowed='NA' where app_id='ROOT'; -update ida.key_policy_def set pre_expire_days=30, access_allowed='NA' where app_id='BASE'; -update ida.key_policy_def set pre_expire_days=60, access_allowed='NA' where app_id='IDA'; diff --git a/db_release_scripts/mosip_ida/sql/1.2.0_revoke.sql b/db_release_scripts/mosip_ida/sql/1.2.0_revoke.sql deleted file mode 100644 index e1771d4d242..00000000000 --- a/db_release_scripts/mosip_ida/sql/1.2.0_revoke.sql +++ /dev/null @@ -1,30 +0,0 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name: mosip_ida --- Release Version : 1.1.5 --- Purpose : Revoking Database Alter deployement done for release in ID Authentication DB. --- Create By : Ram Bhatt --- Created Date : Apr-2021 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- --- Apr-2021 Ram Bhatt create tables to store partner details --- Sep-2021 Loganathan Sekar create anonymous_profile table -------------------------------------------------------------------------------------------------- - -\c mosip_ida sysadmin - -ALTER TABLE ida.uin_auth_lock DROP COLUMN unlock_expiry_datetime; - --- ------------------------------------------------------------------------------------------------- - - -DROP TABLE IF EXISTS ida.partner_data; -DROP TABLE IF EXISTS ida.policy_data; -DROP TABLE IF EXISTS ida.api_key_data; -DROP TABLE IF EXISTS ida.partner_mapping; - -DROP TABLE IF EXISTS ida.misp_license_data; - ------------------------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS ida.anonymous_profile; diff --git a/db_release_scripts/README.MD b/db_upgrade_scripts/README.MD similarity index 100% rename from db_release_scripts/README.MD rename to db_upgrade_scripts/README.MD diff --git a/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql new file mode 100644 index 00000000000..3ed43408f22 --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql @@ -0,0 +1,40 @@ +\c mosip_ida + +REASSIGN OWNED BY postgres TO sysadmin; + +GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA ida TO sysadmin; + +ALTER TABLE ida.uin_auth_lock DROP COLUMN unlock_expiry_datetime; + +-- ------------------------------------------------------------------------------------------------- + + +DROP TABLE IF EXISTS ida.partner_data; +DROP TABLE IF EXISTS ida.policy_data; +DROP TABLE IF EXISTS ida.api_key_data; +DROP TABLE IF EXISTS ida.partner_mapping; + +DROP TABLE IF EXISTS ida.misp_license_data; + +----------------------------------------------------------------------------------------------- + +DROP TABLE IF EXISTS ida.anonymous_profile; + + +------------------------------------------------------------------------------- + +ALTER TABLE ida.identity_cache DROP COLUMN identity_expiry; +ALTER TABLE ida.ca_cert_store DROP CONSTRAINT cert_thumbprint_unique; + +ALTER TABLE ida.key_alias DROP COLUMN uni_ident; +ALTER TABLE ida.key_alias DROP CONSTRAINT uni_ident_const; + +ALTER TABLE ida.key_policy_def DROP COLUMN pre_expire_days; +ALTER TABLE ida.key_policy_def DROP COLUMN access_allowed; + +ALTER TABLE ida.key_policy_def DROP COLUMN pre_expire_days; +ALTER TABLE ida.key_policy_def DROP COLUMN access_allowed; + + +---------------------------------------------------------- + diff --git a/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql new file mode 100644 index 00000000000..61344dd4876 --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql @@ -0,0 +1,200 @@ +\c mosip_ida + +REASSIGN OWNED BY sysadmin TO postgres; + +REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA ida FROM idauser; + +REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA ida FROM sysadmin; + +GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE ON ALL TABLES IN SCHEMA ida TO idauser; + +GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA ida TO postgres; + +DROP TABLE IF EXISTS ida.api_key_data CASCADE; +DROP TABLE IF EXISTS ida.partner_data CASCADE; +DROP TABLE IF EXISTS ida.partner_mapping CASCADE; +DROP TABLE IF EXISTS ida.policy_data CASCADE; +DROP TABLE IF EXISTS ida.misp_license_data CASCADE; +ALTER TABLE ida.uin_auth_lock ADD COLUMN unlock_expiry_datetime timestamp; +------------------------------------------------------------------------------------------------------- + +-- object: ida.api_key_data | type: TABLE -- +CREATE TABLE ida.api_key_data ( + api_key_id character varying(36) NOT NULL, + api_key_commence_on timestamp NOT NULL, + api_key_expires_on timestamp, + api_key_status character varying(36) NOT NULL, + cr_by character varying(256) NOT NULL, + cr_dtimes timestamp NOT NULL, + upd_by character varying(256), + upd_dtimes timestamp, + is_deleted bool DEFAULT false, + del_dtimes timestamp, + CONSTRAINT api_key_data_pk PRIMARY KEY (api_key_id) + +); + +GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE + ON ida.api_key_data + TO idauser; + +--index section starts---- +CREATE INDEX ind_akd_apkeyid ON ida.api_key_data (api_key_id); +--index section ends------ + + + +-- object: ida.partner_data | type: TABLE -- +CREATE TABLE ida.partner_data ( + partner_id character varying(36) NOT NULL, + partner_name character varying(128) NOT NULL, + certificate_data bytea , + partner_status character varying(36) NOT NULL, + cr_by character varying(256) NOT NULL, + cr_dtimes timestamp NOT NULL, + upd_by character varying(256), + upd_dtimes timestamp, + is_deleted boolean DEFAULT false, + del_dtimes timestamp, + CONSTRAINT partner_data_pk PRIMARY KEY (partner_id) + +); + +GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE + ON ida.partner_data + TO idauser; +--index section starts---- +CREATE INDEX ind_pd_pid ON ida.partner_data (partner_id); +--index section ends------ + + + + +-- object: ida.partner_mapping | type: TABLE -- +CREATE TABLE ida.partner_mapping ( + partner_id character varying(36) NOT NULL, + policy_id character varying(36) NOT NULL, + api_key_id character varying(36) NOT NULL, + cr_by character varying(256) NOT NULL, + cr_dtimes timestamp NOT NULL, + upd_by character varying(256), + upd_dtimes timestamp, + is_deleted bool DEFAULT false, + del_dtimes timestamp, + CONSTRAINT partner_mapping_pk PRIMARY KEY (partner_id,policy_id,api_key_id) + +); + +GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE + ON ida.partner_mapping + TO idauser; +--index section starts---- +CREATE INDEX ind_pm_pid ON ida.partner_mapping (partner_id); +--index section ends------ + + + +-- object: ida.policy_data | type: TABLE -- +CREATE TABLE ida.policy_data ( + policy_id character varying(36) NOT NULL, + policy_data bytea NOT NULL, + policy_name character varying(128) NOT NULL, + policy_status character varying(36) NOT NULL, + policy_description character varying(256), + policy_commence_on timestamp NOT NULL, + policy_expires_on timestamp, + cr_by character varying(256) NOT NULL, + cr_dtimes timestamp NOT NULL, + upd_by character varying(256), + upd_dtimes timestamp, + is_deleted bool DEFAULT false, + del_dtimes timestamp, + CONSTRAINT policy_data_pk PRIMARY KEY (policy_id) + +); + +GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE + ON ida.policy_data + TO idauser; + +--index section starts---- +CREATE INDEX ind_pl_pid ON ida.policy_data (policy_id); +--index section ends------ + + +-- object: ida.misp_license_data | type: TABLE -- +CREATE TABLE ida.misp_license_data ( + misp_id character varying(36) NOT NULL, + license_key character varying(128) NOT NULL, + misp_commence_on timestamp NOT NULL, + misp_expires_on timestamp, + misp_status character varying(36) NOT NULL, + cr_by character varying(256) NOT NULL, + cr_dtimes timestamp NOT NULL, + upd_by character varying(256), + upd_dtimes timestamp, + is_deleted bool DEFAULT false, + del_dtimes timestamp, + CONSTRAINT misp_license_data_pk PRIMARY KEY (misp_id) + +); + +GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE + ON ida.misp_license_data + TO idauser; +--index section starts---- +CREATE INDEX ind_mld_lk ON ida.misp_license_data (license_key); +--index section ends------ + + + +-- object: ida.anonymous_profile | type: TABLE -- +-- DROP TABLE IF EXISTS ida.anonymous_profile CASCADE; +CREATE TABLE ida.anonymous_profile( + id character varying(36) NOT NULL, + profile character varying NOT NULL, + cr_by character varying(256) NOT NULL, + cr_dtimes timestamp NOT NULL, + upd_by character varying(256), + upd_dtimes timestamp, + is_deleted boolean DEFAULT FALSE, + del_dtimes timestamp, + CONSTRAINT pk_profile PRIMARY KEY (id) +); + +GRANT SELECT, INSERT, TRUNCATE, REFERENCES, UPDATE, DELETE + ON ida.anonymous_profile + TO idauser; +-- ddl-end -- +COMMENT ON TABLE ida.anonymous_profile IS 'anonymous_profile: Anonymous profiling information for reporting purpose.'; +COMMENT ON COLUMN ida.anonymous_profile.id IS 'Reference ID: System generated id for references in the system.'; +COMMENT ON COLUMN ida.anonymous_profile.profile IS 'Profile : Contains complete anonymous profile data generated by ID-Repository and stored in plain json text format.'; +COMMENT ON COLUMN ida.anonymous_profile.cr_by IS 'Created By : ID or name of the user who create / insert record'; +COMMENT ON COLUMN ida.anonymous_profile.cr_dtimes IS 'Created DateTimestamp : Date and Timestamp when the record is created/inserted'; +COMMENT ON COLUMN ida.anonymous_profile.upd_by IS 'Updated By : ID or name of the user who update the record with new values'; +COMMENT ON COLUMN ida.anonymous_profile.upd_dtimes IS 'Updated DateTimestamp : Date and Timestamp when any of the fields in the record is updated with new values.'; +COMMENT ON COLUMN ida.anonymous_profile.is_deleted IS 'IS_Deleted : Flag to mark whether the record is Soft deleted.'; +COMMENT ON COLUMN ida.anonymous_profile.del_dtimes IS 'Deleted DateTimestamp : Date and Timestamp when the record is soft deleted with is_deleted=TRUE'; + +-------------------------------------------------------------------------------------------------------------- + + +ALTER TABLE ida.identity_cache ADD COLUMN identity_expiry timestamp; + + +ALTER TABLE ida.ca_cert_store ADD CONSTRAINT cert_thumbprint_unique UNIQUE (cert_thumbprint,partner_domain); + + +ALTER TABLE ida.key_alias ADD COLUMN uni_ident character varying(50); +ALTER TABLE ida.key_alias ADD CONSTRAINT uni_ident_const UNIQUE (uni_ident); + +ALTER TABLE ida.key_policy_def ADD COLUMN pre_expire_days smallint; +ALTER TABLE ida.key_policy_def ADD COLUMN access_allowed character varying(1024); + +--------------------------------------------------------------------------------------------------------------- + +ALTER TABLE ida.uin_auth_lock ALTER COLUMN is_deleted SET DEFAULT FALSE; + +update ida.key_policy_def set pre_expire_days=90, access_allowed='NA' where app_id='ROOT'; +update ida.key_policy_def set pre_expire_days=30, access_allowed='NA' where app_id='BASE'; +update ida.key_policy_def set pre_expire_days=60, access_allowed='NA' where app_id='IDA'; diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_rollback.sql new file mode 100644 index 00000000000..45325dd4de5 --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_rollback.sql @@ -0,0 +1,9 @@ +\c mosip_ida + +ALTER TABLE ida.misp_license_data DROP COLUMN policy_id; + +ALTER TABLE ida.partner_mapping ALTER COLUMN api_key_id TYPE varchar(36); + +DROP TABLE IF EXISTS ida.oidc_client_data CASCADE; + +DROP TABLE IF EXISTS ida.kyc_token_store CASCADE; \ No newline at end of file diff --git a/db_release_scripts/mosip_ida/sql/1.2.0.1_to_1.2.0.1-B2_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_upgrade.sql similarity index 60% rename from db_release_scripts/mosip_ida/sql/1.2.0.1_to_1.2.0.1-B2_upgrade.sql rename to db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_upgrade.sql index 8cba60ce711..4d19ecafd48 100644 --- a/db_release_scripts/mosip_ida/sql/1.2.0.1_to_1.2.0.1-B2_upgrade.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B1_to_1.2.0.1-B2_upgrade.sql @@ -1,20 +1,4 @@ --- ------------------------------------------------------------------------------------------------- --- Database Name : mosip_ida --- Release Version : 1.2 --- Purpose : Database Alter scripts for the release for ID Authentication DB. --- Create By : Ram Bhatt --- Created Date : Apr-2021 --- --- Modified Date Modified By Comments / Remarks --- ------------------------------------------------------------------------------------------------- --- Apr-2021 Ram Bhatt create tables to store partner details --- Jul-2021 Ram Bhatt creation of failed message store table --- Jul-2021 Ram Bhatt Adding a new nullable column identity_expiry in IDA table identity_cache --- Sep-2021 Loganathan Sekar Adding Anonymous Profile Table --- Sep-2021 Ram Bhatt Adding indices to multiple tables --- Oct-2021 Loganathan Sekar Removed failed_message_store table ----------------------------------------------------------------------------------------------------- -\c mosip_ida sysadmin +\c mosip_ida ALTER TABLE ida.misp_license_data ADD policy_id character varying(50); @@ -39,6 +23,10 @@ CREATE TABLE ida.oidc_client_data ( ); +GRANT SELECT, INSERT, REFERENCES, UPDATE, DELETE + ON ida.oidc_client_data + TO idauser; + -- DROP TABLE IF EXISTS ida.kyc_token_store CASCADE; CREATE TABLE ida.kyc_token_store( id character varying(36) NOT NULL, @@ -57,4 +45,8 @@ CREATE TABLE ida.kyc_token_store( del_dtimes timestamp, CONSTRAINT pk_key_id PRIMARY KEY (id), CONSTRAINT kyc_token_const UNIQUE (kyc_token) -); \ No newline at end of file +); + +GRANT SELECT, INSERT, REFERENCES, UPDATE, DELETE + ON ida.kyc_token_store + TO idauser; \ No newline at end of file diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_rollback.sql new file mode 100644 index 00000000000..23b12cc2acf --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_rollback.sql @@ -0,0 +1,10 @@ +\c mosip_ida + +ALTER TABLE ida.kyc_token_store DROP COLUMN request_trn_id; + +DROP TABLE IF EXISTS ida.ident_binding_cert_store CASCADE; + +DELETE FROM ida.key_policy_def WHERE app_id='IDA_KYC_EXCHANGE'; + +DELETE FROM ida.key_policy_def WHERE app_id='IDA_KEY_BINDING' + diff --git a/db_release_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_upgrade.sql similarity index 94% rename from db_release_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_upgrade.sql rename to db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_upgrade.sql index bd73af0acd7..6cc241fcd29 100644 --- a/db_release_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_upgrade.sql +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B2_to_1.2.0.1-B3_upgrade.sql @@ -8,7 +8,7 @@ -- Modified Date Modified By Comments / Remarks -- ------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- -\c mosip_ida sysadmin +\c mosip_ida ALTER TABLE ida.kyc_token_store ADD request_trn_id character varying(64); @@ -30,6 +30,10 @@ CREATE TABLE ida.ident_binding_cert_store ( del_dtimes timestamp, CONSTRAINT uni_public_key_hash_const UNIQUE (public_key_hash) ); + +GRANT SELECT, INSERT, REFERENCES, UPDATE, DELETE + ON ida.ident_binding_cert_store + TO idauser; -- ddl-end -- INSERT INTO ida.key_policy_def (app_id, key_validity_duration, is_active, cr_by, cr_dtimes, upd_by, upd_dtimes, is_deleted, del_dtimes, pre_expire_days, access_allowed) diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B4_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B4_rollback.sql new file mode 100644 index 00000000000..5548b94e9cb --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B4_rollback.sql @@ -0,0 +1 @@ +\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION' diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B4_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B4_upgrade.sql new file mode 100644 index 00000000000..e19d945e657 --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B3_to_1.2.0.1-B4_upgrade.sql @@ -0,0 +1,3 @@ +\c mosip_ida + +DROP TABLE IF EXISTS ida.key_policy_def_h; diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_rollback.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_rollback.sql new file mode 100644 index 00000000000..03dac26391f --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_rollback.sql @@ -0,0 +1 @@ +\echo 'Upgrade Queries not required for transition from 1.2.0.1-B4 to 1.2.0.1' diff --git a/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_upgrade.sql b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_upgrade.sql new file mode 100644 index 00000000000..03dac26391f --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/sql/1.2.0.1-B4_to_1.2.0.1_upgrade.sql @@ -0,0 +1 @@ +\echo 'Upgrade Queries not required for transition from 1.2.0.1-B4 to 1.2.0.1' diff --git a/db_upgrade_scripts/mosip_ida/upgrade.properties b/db_upgrade_scripts/mosip_ida/upgrade.properties new file mode 100644 index 00000000000..6226f1194f0 --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/upgrade.properties @@ -0,0 +1,12 @@ +MOSIP_DB_NAME= +DB_SERVERIP= +DB_PORT= +SU_USER=postgres +SU_USER_PWD= +SYS_ADMIN_USER= +SYS_ADMIN_PWD= +DEFAULT_DB_NAME=postgres +DBUSER_PWD= +ACTION= +CURRENT_VERSION= +UPGRADE_VERSION= diff --git a/db_upgrade_scripts/mosip_ida/upgrade.sh b/db_upgrade_scripts/mosip_ida/upgrade.sh new file mode 100644 index 00000000000..fe7b2f03d2f --- /dev/null +++ b/db_upgrade_scripts/mosip_ida/upgrade.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +set -e +properties_file="$1" +echo `date "+%m/%d/%Y %H:%M:%S"` ": $properties_file" +if [ -f "$properties_file" ] +then + echo `date "+%m/%d/%Y %H:%M:%S"` ": Property file \"$properties_file\" found." + while IFS='=' read -r key value + do + key=$(echo $key | tr '.' '_') + eval ${key}=\${value} + done < "$properties_file" +else + echo `date "+%m/%d/%Y %H:%M:%S"` ": Property file not found, Pass property file name as argument." +fi + +echo "Current version: $CURRENT_VERSION" +echo "UPGRADE version: $UPGRADE_VERSION" +echo "Action: $ACTION" + +# Terminate existing connections +echo "Terminating active connections" +CONN=$(PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -t -c "SELECT count(pg_terminate_backend(pg_stat_activity.pid)) FROM pg_stat_activity WHERE datname = '$MOSIP_DB_NAME' AND pid <> pg_backend_pid()";exit;) +echo "Terminated connections" + +# Execute upgrade or rollback +if [ "$ACTION" == "upgrade" ]; then + echo "Upgrading database from $CURRENT_VERSION to $UPGRADE_VERSION" + UPGRADE_SCRIPT_FILE="sql/${CURRENT_VERSION}_to_${UPGRADE_VERSION}_upgrade.sql" + if [ -f "$UPGRADE_SCRIPT_FILE" ]; then + echo "Executing upgrade script $UPGRADE_SCRIPT_FILE" + PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -a -b -f $UPGRADE_SCRIPT_FILE + else + echo "Upgrade script not found, exiting." + exit 1 + fi +elif [ "$ACTION" == "rollback" ]; then + echo "Rolling back database for $CURRENT_VERSION to $UPGRADE_VERSION" + REVOKE_SCRIPT_FILE="sql/${CURRENT_VERSION}_to_${UPGRADE_VERSION}_rollback.sql" + if [ -f "$REVOKE_SCRIPT_FILE" ]; then + echo "Executing rollback script $REVOKE_SCRIPT_FILE" + PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -a -b -f $REVOKE_SCRIPT_FILE + else + echo "rollback script not found, exiting." + exit 1 + fi +else + echo "Unknown action: $ACTION, must be 'upgrade' or 'rollback'." + exit 1 +fi