| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.acegisecurity.captcha; |
| 17 |
|
|
| 18 |
|
import org.acegisecurity.context.SecurityContextImpl; |
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
public class CaptchaSecurityContextImpl extends SecurityContextImpl implements CaptchaSecurityContext { |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
private boolean human; |
| 30 |
|
private int humanRestrictedResourcesRequestsCount; |
| 31 |
|
private long lastPassedCaptchaDate; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
public CaptchaSecurityContextImpl() { |
| 36 |
22 |
super(); |
| 37 |
22 |
human = false; |
| 38 |
22 |
lastPassedCaptchaDate = 0; |
| 39 |
22 |
humanRestrictedResourcesRequestsCount = 0; |
| 40 |
22 |
} |
| 41 |
|
|
| 42 |
|
|
| 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 |
|
|
| 88 |
|
|
| 89 |
|
public void incrementHumanRestrictedRessoucesRequestsCount() { |
| 90 |
13 |
humanRestrictedResourcesRequestsCount++; |
| 91 |
13 |
} |
| 92 |
|
|
| 93 |
|
public boolean isHuman() { |
| 94 |
38 |
return human; |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
public void setHuman() { |
| 101 |
12 |
this.human = true; |
| 102 |
12 |
this.lastPassedCaptchaDate = System.currentTimeMillis(); |
| 103 |
12 |
this.humanRestrictedResourcesRequestsCount = 0; |
| 104 |
12 |
} |
| 105 |
|
} |