Coverage Report - org.acegisecurity.captcha.CaptchaSecurityContextImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CaptchaSecurityContextImpl
87% 
100% 
2.125
 
 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  
 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 implements CaptchaSecurityContext {
 27  
     //~ Instance fields ================================================================================================
 28  
 
 29  
     private boolean human;
 30  
     private int humanRestrictedResourcesRequestsCount;
 31  
     private long lastPassedCaptchaDate;
 32  
 
 33  
     //~ Constructors ===================================================================================================
 34  
 
 35  
     public CaptchaSecurityContextImpl() {
 36  22
         super();
 37  22
         human = false;
 38  22
         lastPassedCaptchaDate = 0;
 39  22
         humanRestrictedResourcesRequestsCount = 0;
 40  22
     }
 41  
 
 42  
     //~ Methods ========================================================================================================
 43  
 
 44  
     public boolean equals(Object obj) {
 45  2
         if (obj instanceof CaptchaSecurityContextImpl) {
 46  2
             CaptchaSecurityContextImpl rhs = (CaptchaSecurityContextImpl) obj;
 47  
 
 48  2
             if (this.isHuman() != rhs.isHuman()) {
 49  0
                 return false;
 50  
             }
 51  
 
 52  2
             if (this.getHumanRestrictedResourcesRequestsCount() != rhs.getHumanRestrictedResourcesRequestsCount()) {
 53  0
                 return false;
 54  
             }
 55  
 
 56  2
             if (this.getLastPassedCaptchaDateInMillis() != rhs.getLastPassedCaptchaDateInMillis()) {
 57  0
                 return false;
 58  
             }
 59  
 
 60  2
             return super.equals(obj);
 61  
         }
 62  
 
 63  0
         return false;
 64  
     }
 65  
 
 66  
     public int getHumanRestrictedResourcesRequestsCount() {
 67  30
         return humanRestrictedResourcesRequestsCount;
 68  
     }
 69  
 
 70  
     public long getLastPassedCaptchaDateInMillis() {
 71  12
         return lastPassedCaptchaDate;
 72  
     }
 73  
 
 74  
     public int hashCode() {
 75  6
         int code = super.hashCode();
 76  6
         code ^= this.humanRestrictedResourcesRequestsCount;
 77  6
         code ^= this.lastPassedCaptchaDate;
 78  
 
 79  6
         if (this.isHuman()) {
 80  1
             code ^= -37;
 81  
         }
 82  
 
 83  6
         return code;
 84  
     }
 85  
 
 86  
     /**
 87  
      * Method to increment the human Restricted Resrouces Requests Count;
 88  
      */
 89  
     public void incrementHumanRestrictedRessoucesRequestsCount() {
 90  13
         humanRestrictedResourcesRequestsCount++;
 91  13
     }
 92  
 
 93  
     public boolean isHuman() {
 94  38
         return human;
 95  
     }
 96  
 
 97  
     /**
 98  
      * Reset the lastPassedCaptchaDate and count.
 99  
      */
 100  
     public void setHuman() {
 101  12
         this.human = true;
 102  12
         this.lastPassedCaptchaDate = System.currentTimeMillis();
 103  12
         this.humanRestrictedResourcesRequestsCount = 0;
 104  12
     }
 105  
 }