KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > AccountLock


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.security;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.struts.Globals;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30 import org.apache.struts.action.ActionMessages;
31
32 import com.sslexplorer.core.CoreUtil;
33 import com.sslexplorer.core.RedirectWithMessages;
34 import com.sslexplorer.core.actions.AuthenticatedAction;
35
36
37 /**
38  * Encapsulate an <i>Account Lock</i>. These occur in two stages. The first
39  * when a preset number of <i>Invalid Credentials</i> errors have occured,
40  * the lock will become <i>Locked</i>.
41  * <p>
42  * The user then cannot attempt further
43  * authentication until a timeout has occured. Once this timeout has
44  * expired, the lock is <i>Unlocked</i> and the user may try again.
45  * <p>
46  * The first stage is then repeated until either the user manages to logon
47  * or the lock has be <i>Locked</i> for a preset number numbers.
48  * <p>
49  * If this occurs then the account is <i>Disable</i> and intervention is then
50  * required by an adminstrator to unlock the account.
51  *
52  *
53  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
54  */

55 public class AccountLock {
56
57     final static Log log = LogFactory.getLog(AccountLock.class);
58
59     // Private instance variables
60

61     private String JavaDoc username;
62     private int attempts;
63     private long lockedTime;
64     private int locks;
65
66     /**
67      * Constructor.
68      *
69      * @param username
70      */

71     public AccountLock(String JavaDoc username) {
72         this.username = username;
73         attempts = 0;
74         lockedTime = -1;
75         locks = 0;
76     }
77
78     /**
79      * Get the number of locks this locks has had. When maximum is
80      * reached account should be disabled.
81      *
82      * @return locks
83      */

84     public int getLocks() {
85         return locks;
86     }
87
88     /**
89      * Set the number of locks this locks has had. When maximum is
90      * reached account should be disabled.
91      *
92      * @param locks locks
93      */

94     protected void setLocks(int locks) {
95         this.locks = locks;
96     }
97
98     /**
99      * Get if this lock is in the <i>Locked</i> state.
100      *
101      * @return locked
102      */

103     public boolean isLocked() {
104         return lockedTime != -1;
105     }
106
107     /**
108      * Get the number of authentication attempts since this lock was
109      * created or reset.
110      *
111      * @return attempts
112      */

113     public int getAttempts() {
114         return attempts;
115     }
116
117     /**
118      * Set the number of authentication attempts since this lock was
119      * created or reset.
120      *
121      * @param attempts attempts
122      */

123     protected void setAttempts(int attempts) {
124         this.attempts = attempts;
125     }
126
127     /**
128      * Get the time this lock was last made <i>Locked</i>.
129      *
130      * @return locked time
131      */

132     public long getLockedTime() {
133         return lockedTime;
134     }
135
136     /**
137      * Set the time this lock was last made <i>Locked</i>.
138      *
139      * @param lockedTime locked time
140      */

141     protected void setLockedTime(long lockedTime) {
142         this.lockedTime = lockedTime;
143     }
144
145     /**
146      * Get the username of the user that this lock is for.
147      *
148      * @return username
149      */

150     public String JavaDoc getUsername() {
151         return username;
152     }
153 }
Popular Tags