From 02b0600d61fc8fd0f68b725b63c7e7463b6432c7 Mon Sep 17 00:00:00 2001 From: ase-101 Date: Wed, 31 Jan 2024 09:07:56 +0530 Subject: [PATCH] ES-715 ES-641 Signed-off-by: ase-101 --- .../java/io/mosip/signup/SignUpServiceApplication.java | 5 ++++- .../src/main/java/io/mosip/signup/dto/Identity.java | 6 ++++++ .../io/mosip/signup/services/CacheUtilService.java | 10 +++++----- .../io/mosip/signup/services/RegistrationService.java | 9 +++++++-- .../java/io/mosip/signup/util/SignUpConstants.java | 2 +- .../src/main/resources/application-default.properties | 7 ++++--- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/signup-service/src/main/java/io/mosip/signup/SignUpServiceApplication.java b/signup-service/src/main/java/io/mosip/signup/SignUpServiceApplication.java index 2bdf1986..4ec15691 100644 --- a/signup-service/src/main/java/io/mosip/signup/SignUpServiceApplication.java +++ b/signup-service/src/main/java/io/mosip/signup/SignUpServiceApplication.java @@ -1,5 +1,7 @@ package io.mosip.signup; +import io.mosip.esignet.core.config.RedisCacheConfig; +import io.mosip.esignet.core.config.SimpleCacheConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCaching; @@ -10,7 +12,8 @@ @SpringBootApplication(scanBasePackages = "io.mosip.signup.*," + "io.mosip.esignet.core.config.RedisCacheConfig," + "io.mosip.esignet.core.config.SimpleCacheConfig,"+ - "${mosip.auth.adapter.impl.basepackage}") + "${mosip.auth.adapter.impl.basepackage}", + scanBasePackageClasses = {SimpleCacheConfig.class, RedisCacheConfig.class}) public class SignUpServiceApplication { public static void main(String[] args) { diff --git a/signup-service/src/main/java/io/mosip/signup/dto/Identity.java b/signup-service/src/main/java/io/mosip/signup/dto/Identity.java index 2ae16610..eb501fb2 100644 --- a/signup-service/src/main/java/io/mosip/signup/dto/Identity.java +++ b/signup-service/src/main/java/io/mosip/signup/dto/Identity.java @@ -33,4 +33,10 @@ public class Identity implements Serializable { @JsonInclude(JsonInclude.Include.NON_NULL) private List selectedHandles; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Boolean phoneVerified; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Long updatedAt; } diff --git a/signup-service/src/main/java/io/mosip/signup/services/CacheUtilService.java b/signup-service/src/main/java/io/mosip/signup/services/CacheUtilService.java index e4f1c08e..e26bb831 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/CacheUtilService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/CacheUtilService.java @@ -16,6 +16,7 @@ @Slf4j @Service public class CacheUtilService { + @Autowired CacheManager cacheManager; @@ -40,9 +41,9 @@ public RegistrationTransaction setRegisteredTransaction(String transactionId, return registrationTransaction; } - @Cacheable(value = SignUpConstants.BLOCKED_IDENTIFIER, key = "#identifierHash") - public String blockIdentifier(String identifierHash) { - return identifierHash; + @Cacheable(value = SignUpConstants.BLOCKED_IDENTIFIER, key = "#key") + public String blockIdentifier(String key, String value) { + return value; } @Cacheable(value = SignUpConstants.KEYSTORE, key = "#key") @@ -71,8 +72,7 @@ public RegistrationTransaction getRegisteredTransaction(String transactionId) { public boolean isIdentifierBlocked(String identifier) { String identifierHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256, identifier.toLowerCase(Locale.ROOT)); - String value = cacheManager.getCache(SignUpConstants.BLOCKED_IDENTIFIER).get(identifierHash, String.class); - return value == null ? false : true; + return cacheManager.getCache(SignUpConstants.BLOCKED_IDENTIFIER).get(identifierHash, String.class) != null; } public String getSecretKey(String keyAlias) { diff --git a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java index 4688cec7..40099678 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java @@ -31,6 +31,8 @@ import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.*; import java.util.stream.Collectors; @@ -157,8 +159,8 @@ public GenerateChallengeResponse generateChallenge(GenerateChallengeRequest gene cacheUtilService.setChallengeGeneratedTransaction(transactionId, transaction); //Resend attempts exhausted, block the identifier for configured time. - if(transaction.getChallengeRetryAttempts() > resendAttempts + 1) - cacheUtilService.blockIdentifier(transaction.getIdentifier()); + if(transaction.getChallengeRetryAttempts() > resendAttempts) + cacheUtilService.blockIdentifier(transaction.getIdentifier(), "blocked"); notificationHelper.sendSMSNotificationAsync(generateChallengeRequest.getIdentifier(), transaction.getLocale(), SEND_OTP_SMS_NOTIFICATION_TEMPLATE_KEY, new HashMap<>(){{put("{challenge}", challenge);}}) @@ -274,6 +276,7 @@ public RegistrationStatusResponse updatePassword(ResetPasswordRequest resetPassw Password password = generateSaltedHash(resetPasswordRequest.getPassword(), transactionId); identity.setPassword(password); + identity.setUpdatedAt(LocalDateTime.now(ZoneOffset.UTC).toEpochSecond(ZoneOffset.UTC)); IdentityRequest identityRequest = new IdentityRequest(); identityRequest.setRegistrationId(transaction.getApplicationId()); @@ -426,6 +429,8 @@ private void saveIdentityData(RegisterRequest registerRequest, String transactio identity.setFullName(userInfoMap.getFullName()); identity.setIDSchemaVersion(idSchemaVersion); identity.setRegistrationType("L1"); + identity.setPhoneVerified(true); + identity.setUpdatedAt(LocalDateTime.now(ZoneOffset.UTC).toEpochSecond(ZoneOffset.UTC)); String uin = getUniqueIdentifier(transactionId); identity.setUIN(uin); diff --git a/signup-service/src/main/java/io/mosip/signup/util/SignUpConstants.java b/signup-service/src/main/java/io/mosip/signup/util/SignUpConstants.java index e004350f..0e98a2f8 100644 --- a/signup-service/src/main/java/io/mosip/signup/util/SignUpConstants.java +++ b/signup-service/src/main/java/io/mosip/signup/util/SignUpConstants.java @@ -4,7 +4,7 @@ public class SignUpConstants { public static final String CHALLENGE_GENERATED = "challenge_generated"; public static final String CHALLENGE_VERIFIED = "challenge_verified"; - public static final String REGISTERED_CACHE = "registered"; + public static final String REGISTERED_CACHE = "status_check"; public static final String BLOCKED_IDENTIFIER = "blocked_identifier"; public static final String KEYSTORE = "keystore"; public static final String KEY_ALIAS = "key_alias"; diff --git a/signup-service/src/main/resources/application-default.properties b/signup-service/src/main/resources/application-default.properties index 8a44e091..41262f2d 100644 --- a/signup-service/src/main/resources/application-default.properties +++ b/signup-service/src/main/resources/application-default.properties @@ -14,9 +14,10 @@ mosip.signup.fullname.pattern=^[\\u1780-\\u17FF\\u19E0-\\u19FF\\u1A00-\\u1A9F\\u ## Time given to generate and verify the challenge in seconds. ## Default resend delay is 60 seconds, with 3 attempts, so 60*3=180 seconds. -## Adding 10 seconds buffer to default 180 seconds = 190 seconds. -## so 190 seconds is the Generate and verify cookie max age. -mosip.signup.unauthenticated.txn.timeout=190 +## Adding 60 seconds for the default generate challenge 180+60=240 +## Adding 10 seconds buffer to default 240 seconds = 250 seconds. +## so 250 seconds is the Generate and verify cookie max age. +mosip.signup.unauthenticated.txn.timeout=250 mosip.signup.challenge.resend-attempt=3 mosip.signup.challenge.resend-delay=60