001: /*
002: * JOSSO: Java Open Single Sign-On
003: *
004: * Copyright 2004-2008, Atricore, Inc.
005: *
006: * This is free software; you can redistribute it and/or modify it
007: * under the terms of the GNU Lesser General Public License as
008: * published by the Free Software Foundation; either version 2.1 of
009: * the License, or (at your option) any later version.
010: *
011: * This software is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this software; if not, write to the Free
018: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
020: */
021: package org.josso;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.josso.agent.SSOAgent;
026: import org.josso.gateway.SSOWebConfiguration;
027: import org.josso.gateway.identity.service.SSOIdentityProvider;
028: import org.josso.gateway.identity.service.SSOIdentityProviderImpl;
029: import org.josso.gateway.assertion.AssertionManager;
030: import org.josso.gateway.assertion.AssertionManagerImpl;
031: import org.josso.gateway.event.client.SSOEventManagerClient;
032: import org.josso.gateway.event.client.SSOEventManagerClientImpl;
033: import org.josso.gateway.reverseproxy.ReverseProxyConfiguration;
034:
035: /**
036: * This class provides a singleton interface to the SSO components
037: * This class should be used by any client that needs a reference to a
038: * component.
039: *
040: * @author <a href="mailto:gbrigand@josso.org">Gianluca Brigandi</a>
041: * @version CVS $Id: Lookup.java 508 2008-02-18 13:32:29Z sgonzalez $
042: */
043:
044: public class Lookup {
045:
046: private static final Log logger = LogFactory.getLog(Lookup.class);
047:
048: /** Single statically instantiated instance of lookup. */
049: private static final Lookup INSTANCE = new Lookup();
050: private String _resourceName;
051: /** Reference to the component keeper. */
052: private ComponentKeeper _componentKeeper;
053:
054: /** Reference to the Cached component instances */
055: private SecurityDomain _securityDomain;
056: private SSOAgent _ssoAgent;
057: private ReverseProxyConfiguration _reverseProxyConfiguration;
058: private SSOWebConfiguration _ssoWebConfiguration;
059: private AssertionManager _assertionManager;
060: private SSOIdentityProvider _ssoIdentityProvider;
061:
062: /**
063: * Private constructor so that this class can only be instantiated by the singleton.
064: */
065: private Lookup() {
066: }
067:
068: /**
069: * Static factory method for getting a reference to the singleton
070: * Lookup.
071: *
072: * @return Lookup
073: */
074: public static Lookup getInstance() {
075: return Lookup.INSTANCE;
076: }
077:
078: public void init(String resourceName) {
079: logger.info("Init resourceName <" + resourceName + ">");
080: this ._resourceName = resourceName;
081: }
082:
083: /**
084: * Fetches the security domain component.
085: *
086: * @return a reference to the component specified by name
087: */
088: public SecurityDomain lookupSecurityDomain() throws Exception {
089:
090: if (_securityDomain == null) {
091:
092: _securityDomain = getComponentKeeper()
093: .fetchSecurityDomain();
094:
095: // This compoment should be initialized first ...
096: logger.info("Initializing SSOEventManager ...");
097: _securityDomain.getEventManager().initialize();
098: logger.info("Initializing SSOEventManager ... DONE");
099:
100: logger.info("Initializing SSOIdentityManager ...");
101: _securityDomain.getIdentityManager().initialize();
102: logger.info("Initializing SSOIdentityManager ... DONE");
103:
104: logger.info("Initializing SSOSessionManager ...");
105: _securityDomain.getSessionManager().initialize();
106: logger.info("Initializing SSOSessionManager ... DONE");
107:
108: logger.info("Initializing SSOAuditManager ...");
109: _securityDomain.getAuditManager().initialize();
110: logger.info("Initializing SSOAuditManager ... DONE");
111: }
112:
113: return _securityDomain;
114: }
115:
116: /**
117: * Fetches the Single Sign-On agent component.
118: *
119: * @return a reference to the agent component.
120: */
121: public SSOAgent lookupSSOAgent() throws Exception {
122: if (_ssoAgent == null)
123: _ssoAgent = getComponentKeeper().fetchSSOAgent();
124:
125: return _ssoAgent;
126: }
127:
128: public SSOEventManagerClient lookupSSOEventManagerClient() {
129: // TODO : Make this configurable :
130: return new SSOEventManagerClientImpl();
131: }
132:
133: /**
134: * Fetches the Reverse Proxy Configuration.
135: *
136: * @return a reference to the reverse proxy configuration.
137: */
138: public ReverseProxyConfiguration lookupReverseProxyConfiguration()
139: throws Exception {
140: if (_reverseProxyConfiguration == null)
141: _reverseProxyConfiguration = getComponentKeeper()
142: .fetchReverseProxyConfiguration();
143:
144: return _reverseProxyConfiguration;
145: }
146:
147: /**
148: * Fetches the SSO web configuration.
149: */
150: public SSOWebConfiguration lookupSSOWebConfiguration()
151: throws Exception {
152: if (_ssoWebConfiguration == null)
153: _ssoWebConfiguration = getComponentKeeper()
154: .fetchSSOWebConfiguration();
155:
156: return _ssoWebConfiguration;
157: }
158:
159: /**
160: * Obtains the Identity Provider
161: */
162: public SSOIdentityProvider lookupSSOIdentityProvider()
163: throws Exception {
164: if (_ssoIdentityProvider == null)
165: _ssoIdentityProvider = new SSOIdentityProviderImpl();
166:
167: return _ssoIdentityProvider;
168: }
169:
170: /**
171: * Obtains the Assertion Manager
172: */
173: public AssertionManager lookupAssertionManager() throws Exception {
174: if (_assertionManager == null)
175: _assertionManager = new AssertionManagerImpl();
176:
177: return _assertionManager;
178: }
179:
180: /**
181: * Gets the ComponentKeeper for the system.
182: * The first time a component keeper is required. This method tries to get a ComponentKeeperFactory instance
183: * to build the ComponentKeeper.
184: *
185: * If no factory can be found, the default component keeper is used.
186: *
187: * @return the ComponentKeeper
188: *
189: * @see ComponentKeeperImpl
190: * @see ComponentKeeperFactory
191: *
192: */
193: public ComponentKeeper getComponentKeeper() throws Exception {
194:
195: if (this ._componentKeeper == null) {
196: ComponentKeeperFactory factory = ComponentKeeperFactory
197: .getInstance();
198: factory.setResourceFileName(this ._resourceName);
199: _componentKeeper = factory.newComponentKeeper();
200: logger.info("Using ComponentKeeper : "
201: + this ._componentKeeper.getClass().getName());
202: }
203:
204: return this ._componentKeeper;
205: }
206:
207: public static void main(String args[]) throws Exception {
208: Lookup.getInstance().lookupSecurityDomain();
209: }
210:
211: }
|