Skip to content

Commit

Permalink
reverted usage of Map in-place of MultiValueMap (#57)
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Rana <[email protected]>
  • Loading branch information
sacrana0 authored Feb 5, 2025
1 parent 8922ea3 commit ca23f37
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.mosip.captcha.service;

import java.util.HashMap;
import java.util.Map;

import io.mosip.captcha.util.ErrorConstants;
Expand All @@ -12,6 +11,8 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

Expand Down Expand Up @@ -52,11 +53,11 @@ public class CaptchaServiceImpl implements CaptchaService {
public ResponseWrapper<CaptchaResponseDTO> validateCaptcha(CaptchaRequestDTO captchaRequest) throws CaptchaException {
String moduleName = captchaRequest.getModuleName();

Map<String, String> param = new HashMap<>();
param.put("secret", secret.get(moduleName == null? defaultModuleName : moduleName));
param.put("response", captchaRequest.getCaptchaToken().trim());
MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
param.add("secret", secret.get(moduleName == null? defaultModuleName : moduleName));
param.add("response", captchaRequest.getCaptchaToken().trim());

if(param.get("secret") == null) {
if(param.get("secret").getFirst() == null) {
log.error("Failed to find secret for module {}", moduleName);
throw new CaptchaException(ErrorConstants.CAPTCHA_VALIDATION_FAILED);
}
Expand All @@ -65,7 +66,7 @@ public ResponseWrapper<CaptchaResponseDTO> validateCaptcha(CaptchaRequestDTO cap
try {
log.info("validate the token request via {}", captchaVerifyUrl);
captchaResponse = this.restTemplate.postForObject(captchaVerifyUrl, param, GoogleReCaptchaV2Response.class);
log.debug(" captchaResponse -> {}", captchaResponse);
log.info(" captchaResponse -> {}", captchaResponse);
} catch (RestClientException ex) {
log.error("captcha token validation request failed", ex);
}
Expand Down

0 comments on commit ca23f37

Please sign in to comment.