@Override
  public void validate(FacesContext facesContext, UIComponent uiComponent, Object obj) throws ValidatorException {
    if (obj != null && obj instanceof String) {
      String captcha = (String) obj;
      ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
      HttpServletRequest req = (HttpServletRequest) ctx.getRequest();
      if (!captcha.equalsIgnoreCase(req.getSession().getAttribute(CaptchaServlet.SESSION_LOGIN_CAPTCHA_KEY).toString())) {
        String text = FacesContext.getCurrentInstance().getApplication().getResourceBundle(FacesContext.getCurrentInstance(), "msg").getString("captcha.error");
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, text, text);
        msg.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(msg);
      }
    }
  }