001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * UserSessionManagerAccessor.java
020: *
021: * This class supplies access to the user session manager object. The calling
022: * thread has to have access to the appropriate roles before being granted
023: * access.
024: */
025:
026: // package path
027: package com.rift.coad.lib.security.user;
028:
029: // imports
030: import com.rift.coad.lib.configuration.Configuration;
031: import com.rift.coad.lib.configuration.ConfigurationFactory;
032: import com.rift.coad.lib.security.Validator;
033: import com.rift.coad.lib.security.AuthorizationException;
034: import com.rift.coad.lib.security.SecurityException;
035:
036: /**
037: * This class supplies access to the user session manager object. The calling
038: * thread has to have access to the appropriate roles before being granted
039: * access.
040: *
041: * @author Brett Chaldecott
042: */
043: public class UserSessionManagerAccessor {
044:
045: // class constants
046: private final static String ROLE = "role";
047:
048: // singleton veriables
049: private static UserSessionManagerAccessor singleton = null;
050:
051: // private member variables
052: private UserSessionManager userSessionManager = null;
053: private String role = null;
054:
055: /**
056: * Creates a new instance of UserSessionManagerAccessor
057: *
058: * @param userSessionManager The reference to the class to supply access to.
059: * @exception UserException
060: */
061: private UserSessionManagerAccessor(
062: UserSessionManager userSessionManager) throws UserException {
063: try {
064: Configuration config = ConfigurationFactory.getInstance()
065: .getConfig(this .getClass());
066: this .userSessionManager = userSessionManager;
067: role = config.getString(ROLE);
068: } catch (Exception ex) {
069: throw new UserException(
070: "Failed to init the user session manager accessor : "
071: + ex.getMessage(), ex);
072: }
073: }
074:
075: /**
076: * This method instanciates the user session manager accessor.
077: *
078: * @return A reference to the user session manager accessor
079: * @exception UserException
080: */
081: public synchronized static UserSessionManagerAccessor init(
082: UserSessionManager userSessionManager) throws UserException {
083: if (singleton == null) {
084: singleton = new UserSessionManagerAccessor(
085: userSessionManager);
086: }
087: return singleton;
088: }
089:
090: /**
091: * This method retrieves a reference to the user session manager instance.
092: *
093: * @return A reference to the user session manager accessor.
094: * @exception UserException;
095: */
096: public synchronized static UserSessionManagerAccessor getInstance()
097: throws UserException {
098: if (singleton == null) {
099: throw new UserException(
100: "The user session manager accessor has not been instanciated");
101: }
102: return singleton;
103: }
104:
105: /**
106: * This method returns a reference to the user session manager.
107: *
108: * @return A reference to the user session manager object.
109: * @exception AuthorizationException
110: * @exception SecurityException
111: */
112: public UserSessionManager getUserSessionManager()
113: throws AuthorizationException, SecurityException {
114: Validator.validate(this.getClass(), role);
115: return userSessionManager;
116: }
117: }
|