Skip to content

Commit

Permalink
Merge pull request #118 from ADORSYS-GIS/feat/optimize-online-banking
Browse files Browse the repository at this point in the history
chore:optimize online banking
  • Loading branch information
Elwizzy12 authored Jan 16, 2025
2 parents 7bbc03c + e24067d commit 06b28ab
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface ObsOtpRestApi {
@ApiResponse(responseCode = "500", description = "Unexpected server error")
})
@PostMapping(value = "/validate", consumes = "application/json", produces = "application/json")
boolean validateOtp(@RequestBody OtpValidationRequest request);
String validateOtp(@RequestBody OtpValidationRequest request);
}


Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ResponseEntity<String> sendOtp(OtpRequest request) {
}

@Override
public boolean validateOtp(OtpValidationRequest request) {
public String validateOtp(OtpValidationRequest request) {
return otpService.validateOtp(request.getPhoneNumber(), request.getPublicKey() ,request.getOtpInput(), request.getOtpHash() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
public interface ObsOtpServiceApi {
String sendOtp(String phoneNumber, String publicKey);

boolean validateOtp(String phoneNumber, String publicKey, String otpInput , String otpHash);
String validateOtp(String phoneNumber, String publicKey, String otpInput , String otpHash);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PhoneNumberCache {

public PhoneNumberCache() {
this.cache = Caffeine.newBuilder()
.expireAfterWrite(1, TimeUnit.MINUTES)
.expireAfterWrite(10, TimeUnit.SECONDS)
.maximumSize(1000)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.adorsys.webank.obs.serviceimpl;

import com.adorsys.webank.obs.config.PhoneNumberCache;
import com.adorsys.webank.obs.dto.RegistrationRequest;
import com.adorsys.webank.obs.service.ObsOtpServiceApi;
import com.adorsys.webank.obs.service.RegistrationServiceApi;
import com.adorsys.webank.service.OtpServiceApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -19,6 +21,9 @@ public class ObsOtpServiceImpl implements ObsOtpServiceApi {
@Autowired
private PhoneNumberCache phoneNumberCache;

@Autowired
private RegistrationServiceApi registrationServiceApi;

@Override
public String sendOtp(String phoneNumber, String publicKey) {
// Check cache for phone number
Expand All @@ -37,18 +42,26 @@ public String sendOtp(String phoneNumber, String publicKey) {
}

@Override
public boolean validateOtp(String phoneNumber, String publicKey, String otpInput, String otpHash) {
public String validateOtp(String phoneNumber, String publicKey, String otpInput, String otpHash) {
// Perform OTP validation
boolean isValid = otpServiceApi.validateOtp(phoneNumber, publicKey, otpInput, otpHash);

// If validation is successful, clear the phone number from the cache
if (isValid) {
logger.info("OTP validation successful for phone number: {}. Clearing from cache.", phoneNumber);
RegistrationRequest registrationRequest = new RegistrationRequest();
registrationRequest.setPhoneNumber(phoneNumber);
registrationRequest.setPublicKey(publicKey);


String registrationResult = registrationServiceApi.registerAccount(registrationRequest);
logger.info("Registration result: {}", registrationResult);
phoneNumberCache.removeFromCache(phoneNumber);
return registrationResult;
} else {
logger.warn("OTP validation failed for phone number: {}.", phoneNumber);
return "OTP validation failed for phone number: " + phoneNumber;
}

return isValid;
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<!-- Spring-related versions -->
<spring-boot-dependencies.version>3.3.5</spring-boot-dependencies.version>
<spring-cloud-starter-openfeign.version>4.1.0</spring-cloud-starter-openfeign.version>
<spring-security.version>6.1.9</spring-security.version>
<spring-security.version>6.4.2</spring-security.version>
<spring-plugin.version>3.0.0</spring-plugin.version>
<spring-test.version>6.1.3</spring-test.version>

Expand Down

0 comments on commit 06b28ab

Please sign in to comment.