From c55025f07fc7ded21ec78b26e76aecc7f1d9b449 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 3 Feb 2022 21:27:43 -0800 Subject: [PATCH] Fix NPE on recapcha validation --- .../main/java/com/wisemapping/rest/UserController.java | 10 +++++----- .../java/com/wisemapping/service/RecaptchaService.java | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/UserController.java b/wise-webapp/src/main/java/com/wisemapping/rest/UserController.java index b2eef9a8..4332ce2e 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/UserController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/UserController.java @@ -62,7 +62,7 @@ public class UserController extends BaseController { // If tomcat is behind a reverse proxy, ip needs to be found in other header. String remoteIp = request.getHeader(REAL_IP_ADDRESS_HEADER); - if(remoteIp==null || remoteIp.isEmpty()){ + if (remoteIp == null || remoteIp.isEmpty()) { remoteIp = request.getRemoteAddr(); } logger.debug("Remote address" + remoteIp); @@ -85,7 +85,7 @@ public class UserController extends BaseController { public void resetPassword(@RequestParam String email) throws InvalidAuthSchemaException, EmailNotExistsException { try { userService.resetPassword(email); - }catch (InvalidUserEmailException e){ + } catch (InvalidUserEmailException e) { throw new EmailNotExistsException(e); } } @@ -101,14 +101,14 @@ public class UserController extends BaseController { if (recatchaEnabled) { final String recaptcha = registration.getRecaptcha(); if (recaptcha != null) { - final String reCaptchaResponse = captchaService.verifyRecaptcha(remoteAddress,recaptcha); - if (!reCaptchaResponse.isEmpty()) { + final String reCaptchaResponse = captchaService.verifyRecaptcha(remoteAddress, recaptcha); + if (reCaptchaResponse != null && !reCaptchaResponse.isEmpty()) { errors.rejectValue("recaptcha", reCaptchaResponse); } } else { errors.rejectValue("recaptcha", Messages.CAPTCHA_LOADING_ERROR); } - }else { + } else { logger.warn("captchaEnabled is enabled.Recommend to enable it for production environments."); } diff --git a/wise-webapp/src/main/java/com/wisemapping/service/RecaptchaService.java b/wise-webapp/src/main/java/com/wisemapping/service/RecaptchaService.java index b63190cc..041a5384 100644 --- a/wise-webapp/src/main/java/com/wisemapping/service/RecaptchaService.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/RecaptchaService.java @@ -6,6 +6,7 @@ import org.apache.http.NameValuePair; import org.apache.http.client.fluent.Form; import org.apache.http.client.fluent.Request; import org.apache.log4j.Logger; +import org.jetbrains.annotations.Nullable; import javax.validation.constraints.NotNull; import java.io.IOException; @@ -23,6 +24,7 @@ public class RecaptchaService { private final static ObjectMapper objectMapper = new ObjectMapper(); private String recaptchaSecret; + @Nullable public String verifyRecaptcha(@NotNull String ip, @NotNull String recaptcha) { final List build = Form.form()