Skip to content

Commit

Permalink
Merge pull request #64 from ase-101/develop
Browse files Browse the repository at this point in the history
ES-756
  • Loading branch information
ase-101 authored Feb 2, 2024
2 parents 0a5fd93 + 01e719a commit d32fedb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

Expand All @@ -28,16 +29,16 @@ public RegistrationTransaction setChallengeGeneratedTransaction(String transacti
}

@CacheEvict(value = SignUpConstants.CHALLENGE_GENERATED, key = "#transactionId")
@Cacheable(value = SignUpConstants.CHALLENGE_VERIFIED, key = "#transactionId")
public RegistrationTransaction setChallengeVerifiedTransaction(String transactionId,
@Cacheable(value = SignUpConstants.CHALLENGE_VERIFIED, key = "#verifiedTransactionId")
public RegistrationTransaction setChallengeVerifiedTransaction(String transactionId, String verifiedTransactionId,
RegistrationTransaction registrationTransaction) {
return registrationTransaction;
}

@CacheEvict(value = SignUpConstants.CHALLENGE_VERIFIED, key = "#transactionId")
@Cacheable(value = SignUpConstants.REGISTERED_CACHE, key = "#transactionId")
public RegistrationTransaction setRegisteredTransaction(String transactionId,
RegistrationTransaction registrationTransaction) {
@CachePut(value = SignUpConstants.STATUS_CHECK, key = "#transactionId")
public RegistrationTransaction setStatusCheckTransaction(String transactionId,
RegistrationTransaction registrationTransaction) {
return registrationTransaction;
}

Expand Down Expand Up @@ -65,8 +66,8 @@ public RegistrationTransaction getChallengeVerifiedTransaction(String transactio
return cacheManager.getCache(SignUpConstants.CHALLENGE_VERIFIED).get(transactionId, RegistrationTransaction.class);
}

public RegistrationTransaction getRegisteredTransaction(String transactionId) {
return cacheManager.getCache(SignUpConstants.REGISTERED_CACHE).get(transactionId, RegistrationTransaction.class);
public RegistrationTransaction getStatusCheckTransaction(String transactionId) {
return cacheManager.getCache(SignUpConstants.STATUS_CHECK).get(transactionId, RegistrationTransaction.class);
}

public boolean isIdentifierBlocked(String identifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import javax.crypto.SecretKey;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

Expand Down Expand Up @@ -208,11 +207,11 @@ public VerifyChallengeResponse verifyChallenge(VerifyChallengeRequest verifyChal
fetchAndCheckIdentity(transactionId, transaction, verifyChallengeRequest);

//After successful verification of the user, change the transactionId
transactionId = IdentityProviderUtil.createTransactionId(null);
addVerifiedCookieInResponse(transactionId, registerTransactionTimeout+statusCheckTransactionTimeout);
String verifiedTransactionId = IdentityProviderUtil.createTransactionId(null);
addVerifiedCookieInResponse(verifiedTransactionId, registerTransactionTimeout+statusCheckTransactionTimeout);

cacheUtilService.setChallengeVerifiedTransaction(transactionId, transaction);
log.debug("Transaction {} : verify challenge status {}", transactionId, ActionStatus.SUCCESS);
cacheUtilService.setChallengeVerifiedTransaction(transactionId, verifiedTransactionId, transaction);
log.debug("Transaction {} : verify challenge status {}", verifiedTransactionId, ActionStatus.SUCCESS);
return new VerifyChallengeResponse(ActionStatus.SUCCESS);
}

Expand Down Expand Up @@ -241,7 +240,7 @@ public RegisterResponse register(RegisterRequest registerRequest, String transac
saveIdentityData(registerRequest, transactionId, transaction);

transaction.setRegistrationStatus(RegistrationStatus.PENDING);
cacheUtilService.setRegisteredTransaction(transactionId, transaction);
cacheUtilService.setStatusCheckTransaction(transactionId, transaction);

notificationHelper.sendSMSNotificationAsync(registerRequest.getUserInfo().getPhone(), transaction.getLocale(),
REGISTRATION_SMS_NOTIFICATION_TEMPLATE_KEY, null)
Expand Down Expand Up @@ -309,7 +308,7 @@ public RegistrationStatusResponse updatePassword(ResetPasswordRequest resetPassw
transaction.getHandlesStatus().put(getHandleRequestId(transaction.getApplicationId(),
"phone", resetPasswordRequest.getIdentifier()), RegistrationStatus.PENDING);
transaction.setRegistrationStatus(RegistrationStatus.PENDING);
cacheUtilService.setRegisteredTransaction(transactionId, transaction);
cacheUtilService.setStatusCheckTransaction(transactionId, transaction);

notificationHelper.sendSMSNotificationAsync(resetPasswordRequest.getIdentifier(), transaction.getLocale(),
FORGOT_PASSWORD_SMS_NOTIFICATION_TEMPLATE_KEY, null)
Expand All @@ -327,7 +326,7 @@ public RegistrationStatusResponse getRegistrationStatus(String transactionId)
if (transactionId == null || transactionId.isEmpty())
throw new InvalidTransactionException();

RegistrationTransaction registrationTransaction = cacheUtilService.getRegisteredTransaction(
RegistrationTransaction registrationTransaction = cacheUtilService.getStatusCheckTransaction(
transactionId);
if (registrationTransaction == null)
throw new InvalidTransactionException();
Expand All @@ -340,9 +339,10 @@ public RegistrationStatusResponse getRegistrationStatus(String transactionId)
registrationTransaction.getHandlesStatus().put(handleRequestId, registrationStatus);
//TODO This is temporary fix, we need to remove this field later from registrationTransaction DTO.
registrationTransaction.setRegistrationStatus(registrationStatus);
cacheUtilService.setStatusCheckTransaction(transactionId, registrationTransaction);
}
}
registrationTransaction = cacheUtilService.setRegisteredTransaction(transactionId, registrationTransaction);
registrationTransaction = cacheUtilService.getStatusCheckTransaction(transactionId);
RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse();
registrationStatusResponse.setStatus(registrationTransaction.getRegistrationStatus());
return registrationStatusResponse;
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 = "status_check";
public static final String STATUS_CHECK = "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 @@ -33,14 +33,14 @@ public void test_RegistrationTransaction_cache() {

Assert.assertEquals(cacheUtilService.setChallengeGeneratedTransaction("mock",
registrationTransaction), registrationTransaction);
Assert.assertEquals(cacheUtilService.setChallengeVerifiedTransaction("mock",
Assert.assertEquals(cacheUtilService.setChallengeVerifiedTransaction("mock", "vmock",
registrationTransaction), registrationTransaction);
Assert.assertEquals(cacheUtilService.setRegisteredTransaction("mock",
Assert.assertEquals(cacheUtilService.setStatusCheckTransaction("mock",
registrationTransaction), registrationTransaction);

Assert.assertNotNull(cacheUtilService.getChallengeGeneratedTransaction("mock"));
Assert.assertNotNull(cacheUtilService.getChallengeVerifiedTransaction("mock"));
Assert.assertNotNull(cacheUtilService.getRegisteredTransaction("mock"));
Assert.assertNotNull(cacheUtilService.getStatusCheckTransaction("mock"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1862,8 +1862,8 @@ public void doGetRegistrationStatus_withCompletedTransaction_thenPass() {
String transactionId = "TRAN-1234";
RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", Purpose.REGISTRATION);
registrationTransaction.setRegistrationStatus(RegistrationStatus.COMPLETED);
when(cacheUtilService.getRegisteredTransaction(transactionId)).thenReturn(registrationTransaction);
when(cacheUtilService.setRegisteredTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction);
when(cacheUtilService.getStatusCheckTransaction(transactionId)).thenReturn(registrationTransaction);
when(cacheUtilService.setStatusCheckTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction);
RegistrationStatusResponse registrationStatusResponse = registrationService.getRegistrationStatus(transactionId);

Assert.assertNotNull(registrationStatusResponse);
Expand All @@ -1875,8 +1875,8 @@ public void doGetRegistrationStatus_withPendingTransaction_thenPass() {
String transactionId = "TRAN-1234";
RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", Purpose.REGISTRATION);
registrationTransaction.setRegistrationStatus(RegistrationStatus.PENDING);
when(cacheUtilService.getRegisteredTransaction(transactionId)).thenReturn(registrationTransaction);
when(cacheUtilService.setRegisteredTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction);
when(cacheUtilService.getStatusCheckTransaction(transactionId)).thenReturn(registrationTransaction);
when(cacheUtilService.setStatusCheckTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction);
RegistrationStatusResponse registrationStatusResponse = registrationService.getRegistrationStatus(transactionId);

Assert.assertNotNull(registrationStatusResponse);
Expand All @@ -1888,8 +1888,8 @@ public void doGetRegistrationStatus_withFailedTransaction_thenPass() {
String transactionId = "TRAN-1234";
RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", Purpose.REGISTRATION);
registrationTransaction.setRegistrationStatus(RegistrationStatus.FAILED);
when(cacheUtilService.getRegisteredTransaction(transactionId)).thenReturn(registrationTransaction);
when(cacheUtilService.setRegisteredTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction);
when(cacheUtilService.getStatusCheckTransaction(transactionId)).thenReturn(registrationTransaction);
when(cacheUtilService.setStatusCheckTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction);
RegistrationStatusResponse registrationStatusResponse = registrationService.getRegistrationStatus(transactionId);

Assert.assertNotNull(registrationStatusResponse);
Expand Down

0 comments on commit d32fedb

Please sign in to comment.