log.error("ReCaptcha service is enabled, however, private or public keys are not defined.");
return true;
}
boolean secure = request.isSecure();
ReCaptcha captcha;
if (secure) {
captcha = ReCaptchaFactory.newSecureReCaptcha(publicKey, privateKey, createNoScript);
} else {
captcha = ReCaptchaFactory.newReCaptcha(publicKey, privateKey, createNoScript);
}
String response = request.getParameter(PARAM_CAPTCHA_RESPONSE);
String challenge = request.getParameter(PARAM_CAPTCHA_CHALLENGE);
String remoteAddress = request.getRemoteAddr();
// validate:
ReCaptchaResponse captchaResponse = captcha.checkAnswer(remoteAddress, challenge, response);
boolean valid = captchaResponse.isValid();
if (valid) {
return true;
}
log.warn("Invalid captcha response: {}", captchaResponse.getErrorMessage());