01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * 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:
16: package org.acegisecurity.captcha;
17:
18: /**
19: * <p>return false if thresold is greater than millis since last captcha test has occured;<br>
20: * Default keyword : REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS</p>
21: *
22: * @author Marc-Antoine Garrigue
23: * @version $Id: AlwaysTestAfterTimeInMillisCaptchaChannelProcessor.java 1496 2006-05-23 13:38:33Z benalex $
24: */
25: public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessor extends
26: CaptchaChannelProcessorTemplate {
27: //~ Static fields/initializers =====================================================================================
28:
29: /** Keyword for this channelProcessor */
30: public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS";
31:
32: //~ Constructors ===================================================================================================
33:
34: /**
35: * Constructor
36: */
37: public AlwaysTestAfterTimeInMillisCaptchaChannelProcessor() {
38: super ();
39: this .setKeyword(DEFAULT_KEYWORD);
40: }
41:
42: //~ Methods ========================================================================================================
43:
44: /**
45: * Verify wheter the context is valid concerning humanity
46: *
47: * @param context the CaptchaSecurityContext
48: *
49: * @return true if valid, false otherwise
50: */
51: boolean isContextValidConcerningHumanity(
52: CaptchaSecurityContext context) {
53: if ((System.currentTimeMillis() - context
54: .getLastPassedCaptchaDateInMillis()) < getThresold()) {
55: logger
56: .debug("context is valid : last passed captcha date - current time < thresold");
57:
58: return true;
59: } else {
60: logger
61: .debug("context is not valid : last passed captcha date - current time > thresold");
62:
63: return false;
64: }
65: }
66: }
|