KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > security > user > UserSessionManagerAccessor


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * UserSessionManagerAccessor.java
20  *
21  * This class supplies access to the user session manager object. The calling
22  * thread has to have access to the appropriate roles before being granted
23  * access.
24  */

25
26 // package path
27
package com.rift.coad.lib.security.user;
28
29 // imports
30
import com.rift.coad.lib.configuration.Configuration;
31 import com.rift.coad.lib.configuration.ConfigurationFactory;
32 import com.rift.coad.lib.security.Validator;
33 import com.rift.coad.lib.security.AuthorizationException;
34 import com.rift.coad.lib.security.SecurityException;
35
36
37 /**
38  * This class supplies access to the user session manager object. The calling
39  * thread has to have access to the appropriate roles before being granted
40  * access.
41  *
42  * @author Brett Chaldecott
43  */

44 public class UserSessionManagerAccessor {
45     
46     // class constants
47
private final static String JavaDoc ROLE = "role";
48     
49     // singleton veriables
50
private static UserSessionManagerAccessor singleton = null;
51     
52     // private member variables
53
private UserSessionManager userSessionManager = null;
54     private String JavaDoc role = null;
55     
56     /**
57      * Creates a new instance of UserSessionManagerAccessor
58      *
59      * @param userSessionManager The reference to the class to supply access to.
60      * @exception UserException
61      */

62     private UserSessionManagerAccessor(UserSessionManager userSessionManager)
63             throws UserException {
64         try {
65             Configuration config =
66                     ConfigurationFactory.getInstance().getConfig(this.getClass());
67             this.userSessionManager = userSessionManager;
68             role = config.getString(ROLE);
69         } catch (Exception JavaDoc ex) {
70             throw new UserException(
71                     "Failed to init the user session manager accessor : "
72                     + ex.getMessage(),ex);
73         }
74     }
75     
76     
77     /**
78      * This method instanciates the user session manager accessor.
79      *
80      * @return A reference to the user session manager accessor
81      * @exception UserException
82      */

83     public synchronized static UserSessionManagerAccessor init(
84             UserSessionManager userSessionManager)
85             throws UserException {
86         if (singleton == null) {
87             singleton = new UserSessionManagerAccessor(userSessionManager);
88         }
89         return singleton;
90     }
91     
92     
93     /**
94      * This method retrieves a reference to the user session manager instance.
95      *
96      * @return A reference to the user session manager accessor.
97      * @exception UserException;
98      */

99     public synchronized static UserSessionManagerAccessor getInstance()
100             throws UserException {
101         if (singleton == null) {
102             throw new UserException(
103                     "The user session manager accessor has not been instanciated");
104         }
105         return singleton;
106     }
107     
108     
109     /**
110      * This method returns a reference to the user session manager.
111      *
112      * @return A reference to the user session manager object.
113      * @exception AuthorizationException
114      * @exception SecurityException
115      */

116     public UserSessionManager getUserSessionManager()
117             throws AuthorizationException, SecurityException JavaDoc {
118         Validator.validate(this.getClass(),role);
119         return userSessionManager;
120     }
121 }
122
Popular Tags