1 16 17 package org.apache.jetspeed.services.security; 18 19 import java.util.Date ; 20 21 28 public class UserLogonStats 29 { 30 private int failures = 0; 31 private int total = 0; 32 private long firstLogon = 0; 33 private final String username; 34 private boolean disabled = false; 35 private Object sem; 36 37 UserLogonStats(String username) 38 { 39 this.username = username; 40 sem = new Object (); 41 } 42 43 public int getFailures() 44 { 45 return failures; 46 } 47 48 public int getTotalFailures() 49 { 50 return total; 51 } 52 53 public long getFirstLogon() 54 { 55 return firstLogon; 56 } 57 58 public String getUserName() 59 { 60 return username; 61 } 62 63 public boolean failCheck(int allowed, long secondsAllowed, int max) 64 { 65 synchronized(sem) 66 { 67 if (disabled) 68 return true; 69 70 failures = failures + 1; 71 total = total + 1; 72 73 if (total >= max) 74 { 75 reset(); 76 disabled = true; 77 return true; 78 } 79 80 long msAllowed = secondsAllowed * 1000; 81 long now = new Date ().getTime(); 82 83 if (firstLogon == 0) 84 firstLogon = now; 85 86 long diff = now - firstLogon; 87 88 if (diff > msAllowed) 89 reset(); 90 91 if (failures >= allowed) 92 { 93 reset(); 94 disabled = true; 95 return true; 96 } 97 return false; 98 } 99 } 100 101 public void reset() 102 { 103 synchronized(sem) 104 { 105 failures = 0; 106 Date now = new Date (); 107 firstLogon = now.getTime(); 108 disabled = false; 109 } 110 } 111 } 112 | Popular Tags |