Package com.uphea.interceptor

Source Code of com.uphea.interceptor.CaptchaInterceptor

package com.uphea.interceptor;

import jodd.bean.BeanUtil;
import jodd.madvoc.ActionRequest;
import jodd.madvoc.interceptor.ActionInterceptor;
import jodd.madvoc.interceptor.BaseActionInterceptor;
import nl.captcha.Captcha;

import javax.servlet.http.HttpSession;

/**
* Interceptor that injects captcha instance from http session if exist.
*/
public class CaptchaInterceptor extends BaseActionInterceptor {

  private static final String CAPTCHA_FIELD_NAME = "captcha";

  @Override
  public Object intercept(ActionRequest actionRequest) throws Exception {

    HttpSession session = actionRequest.getHttpServletRequest().getSession();
    Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME);

    if (captcha != null) {
      Object action = actionRequest.getAction();
      BeanUtil.setDeclaredPropertySilent(action, CAPTCHA_FIELD_NAME, captcha);
    }

    return actionRequest.invoke();
  }
}
TOP

Related Classes of com.uphea.interceptor.CaptchaInterceptor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.