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: * UserStoreManagerAccessor.java
020: *
021: * This object is responsible for supplying access to the user store manager.
022: */
023:
024: // package path
025: package com.rift.coad.lib.security.user;
026:
027: // coadunation imports
028: import com.rift.coad.lib.configuration.Configuration;
029: import com.rift.coad.lib.configuration.ConfigurationFactory;
030: import com.rift.coad.lib.security.Validator;
031: import com.rift.coad.lib.security.AuthorizationException;
032: import com.rift.coad.lib.security.SecurityException;
033:
034: /**
035: * This object is responsible for supplying access to the user store manager.
036: *
037: * @author Brett Chaldecott
038: */
039: public class UserStoreManagerAccessor {
040:
041: // class constants
042: private final static String ROLE = "role";
043:
044: // class member variables
045: private static UserStoreManagerAccessor singleton = null;
046:
047: // private member variables
048: private UserStoreManager userStoreManager = null;
049: private String role = null;
050:
051: /**
052: * Creates a new instance of UserStoreManagerAccessor
053: *
054: * @param userStoreManager The reference to the user store object.
055: * @exception UserException
056: */
057: private UserStoreManagerAccessor(UserStoreManager userStoreManager)
058: throws UserException {
059: try {
060: this .userStoreManager = userStoreManager;
061: Configuration configuration = ConfigurationFactory
062: .getInstance().getConfig(this .getClass());
063: role = configuration.getString(ROLE);
064: } catch (Exception ex) {
065: throw new UserException(
066: "Failed to instanciate the user store manager accessor : "
067: + ex.getMessage(), ex);
068: }
069: }
070:
071: /**
072: * This method instanciates the user store manager accessor.
073: *
074: * @return A reference to the user store manager accessor.
075: * @param userStoreManager The reference to the user store manager.
076: * @exception UserException
077: */
078: public synchronized static UserStoreManagerAccessor init(
079: UserStoreManager userStoreManager) throws UserException {
080: if (singleton == null) {
081: singleton = new UserStoreManagerAccessor(userStoreManager);
082: }
083: return singleton;
084: }
085:
086: /**
087: * This method retrieves a reference to the user store manager instance.
088: *
089: * @return A reference to the user store manager accessor.
090: * @exception UserException;
091: */
092: public synchronized static UserStoreManagerAccessor getInstance()
093: throws UserException {
094: if (singleton == null) {
095: throw new UserException(
096: "The user store manager accessor has not been instanciated");
097: }
098: return singleton;
099: }
100:
101: /**
102: * This method returns a reference to the user store manager.
103: *
104: * @return A reference to the user session manager object.
105: * @exception AuthorizationException
106: * @exception SecurityException
107: */
108: public UserStoreManager getUserStoreManager()
109: throws AuthorizationException, SecurityException {
110: Validator.validate(this.getClass(), role);
111: return userStoreManager;
112: }
113: }
|