예제 #1
0
  private boolean validateCaptchaChallenge(final HttpServletRequest request) {
    try {
      String captchaID = request.getSession().getId();
      String challengeResponse = request.getParameter(captchaParamterName);

      if (autoPassValue != null && autoPassValue.equals(challengeResponse)) {
        return true;
      }
      return captchaService.validateResponseForID(captchaID, challengeResponse);
    } catch (CaptchaServiceException e) {
      logger.error(e.getMessage(), e);
      return false;
    }
  }
예제 #2
0
  private void genernateCaptchaImage(
      final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    ServletOutputStream out = response.getOutputStream();
    try {
      String captchaId = request.getSession(true).getId();
      BufferedImage challenge =
          (BufferedImage) captchaService.getChallengeForID(captchaId, request.getLocale());
      ImageIO.write(challenge, "jpg", out);
      out.flush();
    } catch (CaptchaServiceException e) {
      logger.error(e.getMessage(), e);
    } finally {
      out.close();
    }
  }