1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.talika.tarsis.filters.security;
24
25 import javax.servlet.http.HttpSessionBindingListener;
26 import javax.servlet.http.HttpSessionBindingEvent;
27 import javax.servlet.http.HttpServletRequest;
28
29 import java.util.Map;
30 import java.util.HashMap;
31 import java.util.Enumeration;
32 import java.io.Serializable;
33
34 /**
35 * Object used to store login data during login process.
36 *
37 * @author Jose M. Palomar
38 * @version $Revision: 122 $
39 */
40 public final class LoginSession implements HttpSessionBindingListener, Serializable {
41
42
43 /**
44 * Parameters from original request.
45 */
46 private Map parameters;
47
48 /**
49 * Attributes from original request.
50 */
51 private Map attributes;
52
53 /**
54 * Current number of login tries.
55 */
56 private int tries;
57
58
59 /**
60 * Creates a new <code>LoginSession</code>. It saves attributes and parameters
61 * from original request to resume it later.
62 *
63 * @param request HttpServletRequest original request.
64 */
65 public LoginSession(HttpServletRequest request) {
66
67
68 this.parameters = new HashMap(request.getParameterMap());
69
70
71 this.attributes = new HashMap();
72
73 Enumeration atts = request.getAttributeNames();
74 while (atts.hasMoreElements()) {
75 String attName = (String) atts.nextElement();
76 Object attValue = request.getAttribute(attName);
77
78 this.attributes.put(attName, attValue);
79 }
80
81 }
82
83
84 /**
85 * Returns original client's request parameters.
86 *
87 * @return Map original request parameters.
88 */
89 public Map getParameters() {
90 return parameters;
91 }
92
93 /**
94 * Returns original client's request attributes.
95 *
96 * @return Map original request attributes.
97 */
98 public Map getAttributes() {
99 return attributes;
100 }
101
102 /**
103 * Increments number of login tries.
104 */
105 public void incTries() {
106 tries++;
107 }
108
109 /**
110 * Return number of login tries.
111 *
112 * @return int number of login tries.
113 */
114 public int getTries() {
115 return tries;
116 }
117
118 /**
119 * Notifies the object that it is being bound to a session and identifies the
120 * session. This method do nothing.
121 *
122 * @param httpSessionBindingEvent HttpSessionBindingEvent the event that
123 * identifies the session.
124 * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)
125 */
126 public void valueBound(HttpSessionBindingEvent httpSessionBindingEvent) {
127 }
128
129 /**
130 * Notifies the object that it is being unbound from a session and identifies the
131 * session.
132 *
133 * @param httpSessionBindingEvent HttpSessionBindingEvent the event that
134 * identifies the session.
135 * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(HttpSessionBindingEvent)
136 */
137 public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent) {
138 }
139
140 }