View Javadoc

1   /*
2    * $Id: SecuritySessionImpl.java 124 2004-11-01 18:09:40Z 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.security;
24  
25  import java.io.Serializable;
26  
27  import javax.servlet.http.HttpSessionBindingEvent;
28  import javax.servlet.http.HttpSessionBindingListener;
29  
30  /**
31   * Implementation of <code>SecuritySession</code> interface.
32   *
33   * @author  Jose M. Palomar
34   * @version $Revision: 124 $
35   */
36  public final class SecuritySessionImpl implements SecuritySession, HttpSessionBindingListener, Serializable {
37  
38      // Fields
39      /**
40       * User of session.
41       */
42      private User user;
43  
44      /**
45       * Is session valid?.
46       */
47      private boolean valid;
48  
49      // Constructors
50      /**
51       * Creates a new <code>SecuritySessionImpl</code>.
52       *
53       * @param user User user of session.
54       */
55      public SecuritySessionImpl(User user) {
56          this.user = user;
57          this.valid = true;
58      }
59  
60      // Methods
61      /**
62       * Returns <code>User</code> of session.
63       *
64       * @return User <code>User</code> of session.
65       * @see org.talika.tarsis.security.SecuritySession#getUser()
66       */
67      public User getUser() {
68          return user;
69      }
70  
71      /**
72       * Invalidates session.
73       *
74       *  @see org.talika.tarsis.security.SecuritySession#invalidate()
75       */
76      public void invalidate() {
77          this.valid = false;
78      }
79  
80      /**
81       * Returns <code>true</code> is session is valid.
82       *
83       * @return boolean <code>true</code> is session is valid.
84       * @see org.talika.tarsis.security.SecuritySession#isValid()
85       */
86      public boolean isValid() {
87          return valid;
88      }
89  
90      /**
91       * Notifies the object that it is being bound to a session and identifies the
92       * session. This method do nothing.
93       *
94       * @param httpSessionBindingEvent HttpSessionBindingEvent the event that
95       * identifies the session.
96       * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)
97       */
98      public void valueBound(HttpSessionBindingEvent httpSessionBindingEvent) {
99      }
100 
101     /**
102      * Notifies the object that it is being unbound from a session and identifies the
103      * session. Invalidates session when its unbound.
104      *
105      * @param httpSessionBindingEvent HttpSessionBindingEvent the event that
106      * identifies the session.
107      * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(HttpSessionBindingEvent)
108      */
109     public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent) {
110         invalidate();
111     }
112 
113 }