Hi,
I am writing a custom Captcha, it generates an random Text, saves it the session and is suppose to verify it against the formData.
When validating the Session attribute is always null, and I don’t see why:
The setup is from the recaptcha example:
In the validate method session.getAttribute(“captchaText”) is always null.
public class RegistrationRecaptcha implements FormAction, FormActionFactory, ConfiguredProvider
{
@Override
public void buildPage(FormContext context, LoginFormsProvider form) {
form.setAttribute("captchaRequired", true);
String captchaText = Captcha.generateText();
context.getSession().setAttribute("captchaText", captchaText);
form.setAttribute("captchaImage", Captcha.generateImage(captchaText));
}
@Override
public void validate(ValidationContext context) {
MultivaluedMap<String, String> formData =
context.getHttpRequest().getDecodedFormParameters();
log.info("Attribute captchaText: " + context.getSession().getAttribute("captchaText"));
if (!formData.getFirst("captcha").equals(session.getAttribute("captchaText"))) {
log.info("validate fails");
return;
}
context.success();
}
..}