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 bba8302a..2bdf1986 100644 --- a/signup-service/src/main/java/io/mosip/signup/SignUpServiceApplication.java +++ b/signup-service/src/main/java/io/mosip/signup/SignUpServiceApplication.java @@ -3,8 +3,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCaching; +import org.springframework.scheduling.annotation.EnableAsync; @EnableCaching +@EnableAsync @SpringBootApplication(scanBasePackages = "io.mosip.signup.*," + "io.mosip.esignet.core.config.RedisCacheConfig," + "io.mosip.esignet.core.config.SimpleCacheConfig,"+ diff --git a/signup-service/src/main/java/io/mosip/signup/controllers/RegistrationController.java b/signup-service/src/main/java/io/mosip/signup/controllers/RegistrationController.java index 64bed9f1..859471b2 100644 --- a/signup-service/src/main/java/io/mosip/signup/controllers/RegistrationController.java +++ b/signup-service/src/main/java/io/mosip/signup/controllers/RegistrationController.java @@ -30,8 +30,9 @@ public class RegistrationController { RegistrationService registrationService; @PostMapping("/generate-challenge") - public ResponseWrapper generateChallenge ( - @Valid @RequestBody RequestWrapper requestWrapper, @CookieValue(name = SignUpConstants.TRANSACTION_ID, defaultValue = "") String transactionId) throws SignUpException { + public ResponseWrapper generateChallenge (@Valid @RequestBody RequestWrapper requestWrapper, + @CookieValue(name = SignUpConstants.TRANSACTION_ID, defaultValue = "") String transactionId) + throws SignUpException { ResponseWrapper responseWrapper = new ResponseWrapper<>(); responseWrapper.setResponse(registrationService.generateChallenge(requestWrapper.getRequest(), transactionId)); responseWrapper.setResponseTime(IdentityProviderUtil.getUTCDateTime()); diff --git a/signup-service/src/main/java/io/mosip/signup/dto/NotificationRequest.java b/signup-service/src/main/java/io/mosip/signup/dto/NotificationRequest.java new file mode 100644 index 00000000..09f1106f --- /dev/null +++ b/signup-service/src/main/java/io/mosip/signup/dto/NotificationRequest.java @@ -0,0 +1,11 @@ +package io.mosip.signup.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class NotificationRequest { + private String number; + private String message; +} diff --git a/signup-service/src/main/java/io/mosip/signup/dto/NotificationResponse.java b/signup-service/src/main/java/io/mosip/signup/dto/NotificationResponse.java new file mode 100644 index 00000000..472f96f8 --- /dev/null +++ b/signup-service/src/main/java/io/mosip/signup/dto/NotificationResponse.java @@ -0,0 +1,8 @@ +package io.mosip.signup.dto; + +import lombok.Data; + +@Data +public class NotificationResponse { + private String status; +} 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 49f00bbc..0648bc49 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 @@ -19,6 +19,7 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -26,6 +27,8 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; +import java.util.concurrent.CompletableFuture; + import static io.mosip.signup.util.SignUpConstants.CONSENT_DISAGREE; @Slf4j @@ -66,6 +69,9 @@ public class RegistrationService { @Value("${mosip.signup.get-uin.endpoint}") private String getUinEndpoint; + @Value("${mosip.signup.send-notification.endpoint}") + private String sendNotificationEndpoint; + @Value("${mosip.signup.cookie.max-age}") private int cookieMaxAge; @@ -75,6 +81,18 @@ public class RegistrationService { @Value("${mosip.signup.challenge.resend-delay}") private long resendDelay; + @Value("${mosip.signup.otp-registration.sms.khm}") + private String otpRegistrationKhmMessage; + + @Value("${mosip.signup.otp-registration.sms.eng}") + private String otpRegistrationEngMessage; + + @Value("${mosip.signup.successfully.registration.sms.khm}") + private String registrationSuccessKhmMessage; + + @Value("${mosip.signup.successfully.registration.sms.eng}") + private String registrationSuccessEngMessage; + /** * Generate and regenerate challenge based on the "regenerate" flag in the request. * if regenerate is false - always creates a new transaction and set-cookie header is sent in the response. @@ -110,6 +128,11 @@ public GenerateChallengeResponse generateChallenge(GenerateChallengeRequest gene transaction.increaseAttempt(); transaction.setLocale(generateChallengeRequest.getLocale()); cacheUtilService.setChallengeGeneratedTransaction(transactionId, transaction); + + sendNotificationAsync(generateChallengeRequest.getIdentifier(), transaction.getLocale(), challenge) + .thenAccept(notificationResponseRestResponseWrapper -> { + log.debug("Send SMS response {}", notificationResponseRestResponseWrapper.toString()); + }); return new GenerateChallengeResponse(ActionStatus.SUCCESS); } @@ -265,6 +288,25 @@ private String getUniqueIdentifier(String transactionId) throws SignUpException restResponseWrapper.getErrors().get(0).getErrorCode() : ErrorConstants.GET_UIN_FAILED); } + @Async + private CompletableFuture> sendNotificationAsync + (String number, String locale, String challenge) { + + NotificationRequest notificationRequest = new NotificationRequest(number.substring(4), + locale == null || locale.equals("khm") ? otpRegistrationKhmMessage : otpRegistrationEngMessage ); + + notificationRequest.setMessage(notificationRequest.getMessage().replace("XXXXXX", challenge)); + + RestRequestWrapper restRequestWrapper = new RestRequestWrapper<>(); + restRequestWrapper.setRequest(notificationRequest); + + return CompletableFuture.supplyAsync(() -> selfTokenRestTemplate + .exchange(sendNotificationEndpoint, + HttpMethod.POST, + new HttpEntity<>(restRequestWrapper), + new ParameterizedTypeReference>(){}).getBody()); + } + private void validateTransaction(RegistrationTransaction transaction, String identifier) { if(transaction == null) { log.error("generate-challenge failed: validate transaction null"); diff --git a/signup-service/src/main/resources/application-default.properties b/signup-service/src/main/resources/application-default.properties index 3b4a91b5..4e578564 100644 --- a/signup-service/src/main/resources/application-default.properties +++ b/signup-service/src/main/resources/application-default.properties @@ -15,6 +15,7 @@ mosip.signup.status.request.delay=20 mosip.signup.status.request.limit=10 mosip.signup.fullname.pattern=^[\p{Khmer}\s]{1,30}$ mosip.signup.challenge.timeout=60 +mosip.signup.password.max-length=20 ## ------------------------------------- Cache configuration ----------------------------------------------------------- @@ -46,7 +47,7 @@ mosip.kernel.auth.appid-realm-map={admin:'mosip',crereq:'mosip',creser:'mosip',i mosip.kernel.auth.appids.realm.map={admin:'mosip',crereq:'mosip',creser:'mosip',idrepo:'mosip','regproc':'mosip', signup:'mosip'} mosip.iam.adapter.clientid=mosip-signup-client -mosip.iam.adapter.clientsecret=QdDb3zAdFDgBvto7aNasLLJjxZ1xSSvu +mosip.iam.adapter.clientsecret=LBIZwf0IGrFlkuXi mosip.iam.adapter.appid=signup mosip.iam.adapter.issuerURL=${keycloak.external.url}/auth/realms/mosip mosip.authmanager.client-token-endpoint=${mosip.kernel.authmanager.url}/v1/authmanager/authenticate/clientidsecretkey @@ -63,6 +64,7 @@ mosip.signup.generate-challenge.endpoint=${mosip.kernel.authmanager.url}/v1/otpm mosip.signup.add-identity.endpoint=https://api-internal.camdgc-dev.mosip.net/idrepository/v1/identity/ mosip.signup.generate-hash.endpoint=https://api-internal.camdgc-dev.mosip.net/v1/keymanager/generateArgon2Hash mosip.signup.get-uin.endpoint=https://api-internal.camdgc-dev.mosip.net/v1/idgenerator/uin +mosip.signup.send-notification.endpoint=https://api-internal.camdgc-dev.mosip.net/v1/notifier/sms/send mosip.signup.add-identity.request.id=mosip.id.create mosip.signup.add-identity.request.version=v1 @@ -89,6 +91,10 @@ mosip.signup.ui.config.key-values={\ 'status.request.delay': '${mosip.signup.status.request.delay}', \ 'status.request.limit': '${mosip.signup.status.request.limit}' \ } - +## ----------------------------- SMS-message ----------------------------------------------------------------------------- +mosip.signup.otp-registration.sms.khm=ប្រើ XXXXXX ដើម្បីផ្ទៀងផ្ទាត់គណនី KhID របស់អ្នក។ +mosip.signup.otp-registration.sms.eng=Use XXXXXX to verify your KhID account. +mosip.signup.successfully.registration.sms.khm=ប្រើ XXXXXX ដើម្បីផ្ទៀងផ្ទាត់គណនី KhID របស់អ្នក។ +mosip.signup.successfully.registration.sms.eng=Use XXXXXX to verify your KhID account. #------------------------------------------ Others --------------------------------------------------------------------- -logging.level.io.mosip.signup=DEBUG \ No newline at end of file +logging.level.io.mosip.signup=DEBUG diff --git a/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java b/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java index 300f7da9..44a5983f 100644 --- a/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java +++ b/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java @@ -20,6 +20,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; @@ -41,7 +42,7 @@ import java.time.LocalDateTime; @RunWith(SpringRunner.class) -@TestPropertySource(locations = "classpath:application-test.properties") +@ActiveProfiles(value = {"test"}) public class RegistrationServiceTest { @InjectMocks @@ -75,6 +76,12 @@ public void setUp(){ registrationService, "resendAttempts", 3); ReflectionTestUtils.setField( registrationService, "resendDelay", 30); + + ReflectionTestUtils.setField( + registrationService, "otpRegistrationKhmMessage", "ប្រើ XXXXXX ដើម្បីផ្ទៀងផ្ទាត់គណនី KhID របស់អ្នក។"); + + ReflectionTestUtils.setField( + registrationService, "otpRegistrationEngMessage", "Use XXXXXX to verify your KhID account."); } @Test