Skip to content

Commit

Permalink
Merge pull request #43 from ase-101/develop
Browse files Browse the repository at this point in the history
ES-715 ES-641
  • Loading branch information
ase-101 authored Jan 31, 2024
2 parents f7b9413 + 02b0600 commit c44e91c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ public class Identity implements Serializable {

@JsonInclude(JsonInclude.Include.NON_NULL)
private List<String> selectedHandles;

@JsonInclude(JsonInclude.Include.NON_NULL)
private Boolean phoneVerified;

@JsonInclude(JsonInclude.Include.NON_NULL)
private Long updatedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@Slf4j
@Service
public class CacheUtilService {

@Autowired
CacheManager cacheManager;

Expand All @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);}})
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c44e91c

Please sign in to comment.