KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > admin > security > server > AbstractSecuritySession


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: AbstractSecuritySession.java,v $
31  * Revision 1.3.2.1 2005/10/08 17:31:03 colinmacleod
32  * Fixed initialization of SecuritySession.
33  *
34  * Revision 1.3 2005/04/10 20:09:48 colinmacleod
35  * Added new themes.
36  * Changed id type to String.
37  * Changed i tag to em and b tag to strong.
38  * Improved PicoContainerFactory with NanoContainer scripts.
39  *
40  * Revision 1.2 2005/04/09 17:19:57 colinmacleod
41  * Changed copyright text to GPL v2 explicitly.
42  *
43  * Revision 1.1.1.1 2005/03/10 17:51:41 colinmacleod
44  * Restructured ivata op around Hibernate/PicoContainer.
45  * Renamed ivata groupware.
46  *
47  * Revision 1.3 2004/11/12 18:16:07 colinmacleod
48  * Ordered imports.
49  *
50  * Revision 1.2 2004/11/12 15:57:18 colinmacleod
51  * Removed dependencies on SSLEXT.
52  * Moved Persistence classes to ivata masks.
53  *
54  * Revision 1.1 2004/09/30 15:15:58 colinmacleod
55  * Split off addressbook elements into security subproject.
56  *
57  * Revision 1.1 2004/07/13 19:41:11 colinmacleod
58  * Moved project to POJOs from EJBs.
59  * Applied PicoContainer to services layer (replacing session EJBs).
60  * Applied Hibernate to persistence layer (replacing entity EJBs).
61  * -----------------------------------------------------------------------------
62  */

63 package com.ivata.groupware.admin.security.server;
64
65 import java.io.IOException JavaDoc;
66 import java.io.ObjectInputStream JavaDoc;
67 import java.io.ObjectOutputStream JavaDoc;
68 import java.io.Serializable JavaDoc;
69 import java.util.HashMap JavaDoc;
70 import java.util.Map JavaDoc;
71
72 import org.picocontainer.MutablePicoContainer;
73 import org.picocontainer.PicoContainer;
74 import org.picocontainer.defaults.DefaultPicoContainer;
75
76 import com.ivata.groupware.admin.security.user.UserDO;
77 import com.ivata.groupware.container.PicoContainerFactory;
78 import com.ivata.mask.util.SystemException;
79
80 /**
81  * This absrtact class is a wrapper for <code>Map</code>, used to store items
82  * in the session.
83  *
84  * @author Colin MacLeod
85  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
86  * @since Mar 29, 2004
87  * @version $Revision: 1.3.2.1 $
88  */

89 public abstract class AbstractSecuritySession implements SecuritySession {
90
91     /**
92      * Access level.
93      */

94     private int access;
95     /**
96      * Stores all attributes which are persisted in this session.
97      */

98     private Map JavaDoc attributes = new HashMap JavaDoc();
99     /**
100      * <p>
101      * Container used throughout this session.
102      * </p>
103      */

104     private PicoContainer container;
105     private String JavaDoc password;
106
107     /**
108      * User who is logged in to this session.
109      */

110     private UserDO user;
111
112     /**
113      * Construct a security session for the given user.
114      *
115      * @param container container used throughout this session.
116      * @param user user who is logged in to this session.
117      */

118     public AbstractSecuritySession(PicoContainer container, UserDO user)
119             throws SystemException {
120         MutablePicoContainer mutableParent =
121             new DefaultPicoContainer(container);
122         mutableParent.registerComponentInstance(
123             SecuritySession.class, this);
124         MutablePicoContainer childContainer = PicoContainerFactory
125             .getInstance().override(mutableParent);
126         childContainer.registerComponentInstance(SecuritySession.class,
127             this);
128
129         this.container = childContainer;
130         this.user = user;
131     }
132
133     /**
134      * <p>
135      * Get the access level for the next commands.
136      * </p>
137      *
138      * @return access level for the next commands.
139      */

140     public final int getAccess() {
141         return access;
142     }
143
144     /**
145      * The security session can also be used as a container for items which
146      * should persist as long as the user is logged in.
147      *
148      * @param name name of the attribute to retrieve.
149      * @return value for this attribute.
150      * @see com.ivata.groupware.admin.security.server.SecuritySession#getAttribute(String)
151      */

152     public final Serializable JavaDoc getAttribute(final String JavaDoc name) {
153         return (Serializable JavaDoc) attributes.get(name);
154     }
155
156     /**
157      * <p>
158      * Container used throughout this session.
159      * </p>
160      * @return container used throughout this session.
161      */

162     public final PicoContainer getContainer() {
163         return container;
164     }
165
166
167     /**
168      * @return Returns the password.
169      */

170     public String JavaDoc getPassword() {
171         return password;
172     }
173
174     /**
175      * @see com.ivata.groupware.admin.security.server.SecuritySession#getUser()
176      */

177     public UserDO getUser() {
178         return user;
179     }
180
181     /**
182      * Refer to {@link SecuritySession#isGuest}.
183      * @return Refer to {@link SecuritySession#isGuest}.
184      */

185     public boolean isGuest() {
186         return ((user == null)
187                 || "guest".equals(user.getName()));
188     }
189
190     /**
191      * <p>Serialize the object from the input stream provided.</p>
192      * @exception ClassNotFoundException thrown by
193      * <code>ObjectInputStream.defaultReadObject( )</code>.
194      * @exception IOException thrown by
195      * <code>ObjectInputStream.defaultReadObject( )</code>.
196      * @param ois the input stream to serialize the object from
197      *
198      */

199     private void readObject(final ObjectInputStream JavaDoc ois) throws ClassNotFoundException JavaDoc,IOException JavaDoc {
200         ois.defaultReadObject();
201     }
202
203     /**
204      * <p>
205      * Set the access level for the next commands.
206      * </p>
207      *
208      * @param access access level for the next commands.
209      */

210     public final void setAccess(final int access) {
211         this.access = access;
212     }
213
214     /**
215      * The security session can also be used as a container for items which
216      * should persist as long as the user is logged in.
217      *
218      * @param name name of the attribute to set.
219      * @param value value for this attribute.
220      * @see com.ivata.groupware.admin.security.server.SecuritySession#setAttribute(String, java.io.Serializable)
221      */

222     public final void setAttribute(final String JavaDoc name,
223             final Serializable JavaDoc value) {
224         attributes.put(name, value);
225     }
226     /**
227      * Refer to {@link #getPassword}.
228      * @param passwordParam Refer to {@link #getPassword}.
229      */

230     public void setPassword(String JavaDoc passwordParam) {
231         password = passwordParam;
232     }
233     /**
234      * <p>Serialize the object to the output stream provided.</p>
235      * @exception IOException thrown by
236      * <code>ObjectOutputStream.defaultWriteObject( )</code>
237      * @param oos the output stream to serialize the object to
238      *
239      */

240     private void writeObject(final ObjectOutputStream JavaDoc oos) throws IOException JavaDoc {
241         oos.defaultWriteObject();
242     }
243 }
244
Popular Tags