View Javadoc

1   /* Copyright 2004, 2005 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.acegisecurity.captcha;
16  
17  /***
18   * <p>
19   * return false if thresold is greater than millis since last captcha test has occured;<br>
20   * Default keyword : REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS
21   * </p>
22   *
23   * @author Marc-Antoine Garrigue
24   * @version $Id: AlwaysTestAfterTimeInMillisCaptchaChannelProcessor.java,v 1.2 2005/11/17 00:55:49 benalex Exp $
25   */
26  public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessor
27      extends CaptchaChannelProcessorTemplate {
28      //~ Static fields/initializers =============================================
29  
30      /*** Keyword for this channelProcessor */
31      public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS";
32  
33      //~ Constructors ===========================================================
34  
35      /***
36       * Constructor
37       */
38      public AlwaysTestAfterTimeInMillisCaptchaChannelProcessor() {
39          super();
40          this.setKeyword(DEFAULT_KEYWORD);
41      }
42  
43      //~ Methods ================================================================
44  
45      /***
46       * Verify wheter the context is valid concerning humanity
47       *
48       * @param context the CaptchaSecurityContext
49       *
50       * @return true if valid, false otherwise
51       */
52      boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
53          if ((System.currentTimeMillis()
54              - context.getLastPassedCaptchaDateInMillis()) < getThresold()) {
55              logger.debug(
56                  "context is valid : last passed captcha date - current time < thresold");
57  
58              return true;
59          } else {
60              logger.debug(
61                  "context is not valid : last passed captcha date - current time > thresold");
62  
63              return false;
64          }
65      }
66  }