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
    16  package org.acegisecurity.captcha;
    17
    18  import org.acegisecurity.context.SecurityContextImpl;
    19
    20
    21  /***
    22   * Default CaptchaSecurityContext implementation
    23   *
    24   * @author mag
    25   */
    26  public class CaptchaSecurityContextImpl extends SecurityContextImpl
    27      implements CaptchaSecurityContext {
    28      //~ Instance fields ========================================================
    29
    30      private boolean human;
    31      private int humanRestrictedResourcesRequestsCount;
    32      private long lastPassedCaptchaDate;
    33
    34      //~ Constructors ===========================================================
    35
    36      /***
    37       *
    38       */
    39      public CaptchaSecurityContextImpl() {
    40          super();
    41          human = false;
    42          lastPassedCaptchaDate = 0;
    43          humanRestrictedResourcesRequestsCount = 0;
    44      }
    45
    46      //~ Methods ================================================================
    47
    48      /***
    49       * reset the lastPassedCaptchaDate and count.
    50       */
    51      public void setHuman() {
    52          this.human = true;
    53          this.lastPassedCaptchaDate = System.currentTimeMillis();
    54          this.humanRestrictedResourcesRequestsCount = 0;
    55      }
    56
    57      /*
    58       * (non-Javadoc)
    59       *
    60       * @see org.acegisecurity.context.CaptchaSecurityContext#isHuman()
    61       */
    62      public boolean isHuman() {
    63          return human;
    64      }
    65
    66      /*
    67       * (non-Javadoc)
    68       *
    69       * @see org.acegisecurity.context.CaptchaSecurityContext#getHumanRestrictedResourcesRequestsCount()
    70       */
    71      public int getHumanRestrictedResourcesRequestsCount() {
    72          return humanRestrictedResourcesRequestsCount;
    73      }
    74
    75      /*
    76       * (non-Javadoc)
    77       *
    78       * @see org.acegisecurity.context.CaptchaSecurityContext#getLastPassedCaptchaDateInMillis()
    79       */
    80      public long getLastPassedCaptchaDateInMillis() {
    81          return lastPassedCaptchaDate;
    82      }
    83
    84      /***
    85       * Method to increment the human Restricted Resrouces Requests Count;
    86       */
    87      public void incrementHumanRestrictedRessoucesRequestsCount() {
    88          humanRestrictedResourcesRequestsCount++;
    89      }
    90  }