View Javadoc

1   /*
2    * $Id: LoginSession.java 122 2004-11-01 13:06:54Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      // Fields
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      // Constructors
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          // Parameters
68          this.parameters = new HashMap(request.getParameterMap());
69  
70          // Atributes
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      // Methods
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 }