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: /*
17: * Copyright (c) 2005 Your Corporation. All Rights Reserved.
18: */
19: package org.acegisecurity.captcha;
20:
21: /**
22: * <p>return false if ny CaptchaChannelProcessorTemplate of mapped urls has been requested more than thresold; <br>
23: * Default keyword : REQUIRES_CAPTCHA_ABOVE_THRESOLD_REQUESTS</p>
24: *
25: * @author Marc-Antoine Garrigue
26: * @version $Id: AlwaysTestAfterMaxRequestsCaptchaChannelProcessor.java 1496 2006-05-23 13:38:33Z benalex $
27: */
28: public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessor extends
29: CaptchaChannelProcessorTemplate {
30: //~ Static fields/initializers =====================================================================================
31:
32: /** Keyword for this channelProcessor */
33: public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_ABOVE_THRESOLD_REQUESTS";
34:
35: //~ Constructors ===================================================================================================
36:
37: /**
38: * Constructor
39: */
40: public AlwaysTestAfterMaxRequestsCaptchaChannelProcessor() {
41: super ();
42: this .setKeyword(DEFAULT_KEYWORD);
43: }
44:
45: //~ Methods ========================================================================================================
46:
47: /**
48: * Verify wheter the context is valid concerning humanity
49: *
50: * @param context
51: *
52: * @return true if valid, false otherwise
53: */
54: boolean isContextValidConcerningHumanity(
55: CaptchaSecurityContext context) {
56: if (context.getHumanRestrictedResourcesRequestsCount() < getThresold()) {
57: logger.debug("context is valid : request count < thresold");
58:
59: return true;
60: } else {
61: logger
62: .debug("context is not valid : request count > thresold");
63:
64: return false;
65: }
66: }
67: }
|