org.loom.addons.recaptcha.RecaptchaInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of loom-addons Show documentation
Show all versions of loom-addons Show documentation
Uploads all artifacts belonging to configuration ':archives'.
The newest version!
package org.loom.addons.recaptcha;
import org.loom.interceptor.PopulateInterceptor;
import org.loom.mapping.ParsedAction;
import org.loom.resolution.Resolution;
import org.loom.servlet.LoomServletRequest;
/**
* Validates the Captcha. Queries the ReCaptcha service and adds a validation error message if
* the captcha value is not correct.
*
* @author icoloma
*/
public class RecaptchaInterceptor implements PopulateInterceptor {
private RecaptchaService service;
public Resolution beforePopulate(ParsedAction action) {
LoomServletRequest request = action.getRequest();
String challenge = request.getStringParameter(RecaptchaTag.CHALLENGE_PARAM);
String response = request.getStringParameter(RecaptchaTag.RESPONSE_PARAM);
request.getRequestParameters().setAssigned(RecaptchaTag.CHALLENGE_PARAM);
request.getRequestParameters().setAssigned(RecaptchaTag.RESPONSE_PARAM);
String messageKey = service.validate(request.getRemoteAddr(), challenge, response);
if (messageKey != null) {
request.setAttribute(RecaptchaTag.RECAPTCHA_ERROR_MESSAGE, messageKey);
request.getParsedAction().getMessages().error("captcha.error.incorrect");
}
return null;
}
public void setRecaptchaService(RecaptchaService captchaService) {
this.service = captchaService;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy