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