Skip to content

Commit

Permalink
[ES-904] updated reviewed comments
Browse files Browse the repository at this point in the history
Signed-off-by: Venkata Saidurga Polamraju <saidurgacsea@gmail.com>
  • Loading branch information
pvsaidurga committed Jun 25, 2024
1 parent d8eb191 commit 6a13f8b
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public class CaptchaHelper {
@Autowired
private RestTemplate restTemplate;

@Value("mosip.esignet.captcha.module-name")
@Value("${mosip.esignet.captcha.module-name}")
private String moduleName;

@Value("${mosip.esignet.captcha.module-name}")
@Value("${mosip.esignet.captcha.validator-name}")
private String validatorUrl;

public boolean validateCaptcha(String captchaToken) {

if (captchaToken == null) {
if (captchaToken == null || captchaToken.isEmpty()) {
throw new EsignetException(ErrorConstants.INVALID_CAPTCHA);
}

Expand All @@ -53,23 +53,22 @@ public boolean validateCaptcha(String captchaToken) {
.headers(headers)
.body(requestWrapper);

ResponseEntity<?> response = restTemplate.exchange(
ResponseEntity<?> responseEntity = restTemplate.exchange(
requestEntity,
ResponseEntity.class
);

if (!response.getStatusCode().is2xxSuccessful() || response.getBody() == null) {
log.error("Errors received from CaptchaService: " + response.getStatusCode());
if (responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.getBody() != null) {
ResponseWrapper<?> responseWrapper = (ResponseWrapper<?>) responseEntity.getBody();
if (responseWrapper != null && responseWrapper.getResponse() != null) {
log.info("Captcha Validation Successful");
return true;
}
log.error("Errors received from CaptchaService: {}", responseWrapper.getErrors()); //NOSONAR responseWrapper is already evaluated to be not null
throw new EsignetException(ErrorConstants.INVALID_CAPTCHA);
}

ResponseWrapper<?> responseWrapper = (ResponseWrapper<?>) response.getBody();
if (responseWrapper != null && responseWrapper.getErrors().isEmpty()) {
log.info("Captcha Validation Successful");
return true;
}

log.error("Errors received from CaptchaService: " + response.getStatusCode());
log.error("Errors received from CaptchaService: {}",responseEntity.getStatusCode());
throw new EsignetException(ErrorConstants.INVALID_CAPTCHA);
}

}

0 comments on commit 6a13f8b

Please sign in to comment.