View Javadoc

1   /* Copyright 2004, 2005, 2006 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  
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 CaptchaChannelProcessorTemplate {
29      //~ Static fields/initializers =====================================================================================
30  
31      /** Keyword for this channelProcessor */
32      public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_ABOVE_THRESOLD_REQUESTS";
33  
34      //~ Constructors ===================================================================================================
35  
36  /**
37       * Constructor
38       */
39      public AlwaysTestAfterMaxRequestsCaptchaChannelProcessor() {
40          super();
41          this.setKeyword(DEFAULT_KEYWORD);
42      }
43  
44      //~ Methods ========================================================================================================
45  
46      /**
47       * Verify wheter the context is valid concerning humanity
48       *
49       * @param context
50       *
51       * @return true if valid, false otherwise
52       */
53      boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
54          if (context.getHumanRestrictedResourcesRequestsCount() < getThresold()) {
55              logger.debug("context is valid : request count < thresold");
56  
57              return true;
58          } else {
59              logger.debug("context is not valid : request count > thresold");
60  
61              return false;
62          }
63      }
64  }