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.gateway;
022:
023: import org.josso.gateway.identity.service.SSOIdentityProvider;
024:
025: /**
026: * Locates services provided by the Single Sign-On Gateway.
027: *
028: * @author <a href="mailto:gbrigand@josso.org">Gianluca Brigandi</a>
029: * @version CVS $Id: GatewayServiceLocator.java 508 2008-02-18 13:32:29Z sgonzalez $
030: */
031: public abstract class GatewayServiceLocator {
032:
033: /** The property name of the factory to be used */
034: private static final String property = "org.josso.gateway.GatewayServiceLocator";
035:
036: /** La factory por defecto a ser utilizada */
037: private static final String factory = "org.josso.gateway.WebserviceGatewayServiceLocator";
038:
039: /**
040: * We're leaving the constructor public since it need to be instantiated by
041: * the ComponentKeeper.
042: */
043: public GatewayServiceLocator() {
044: super ();
045: }
046:
047: /**
048: * Instantiates the concrete gateway service locator.
049: *
050: * @return the concrete service locator.
051: */
052: public static GatewayServiceLocator newInstance() {
053:
054: String n = factory;
055: try {
056: n = System.getProperty(property, factory);
057: } catch (SecurityException e) {
058: n = factory;
059: }
060:
061: try {
062: // Loads and instantiates the factory.
063: return (GatewayServiceLocator) Class.forName(n)
064: .newInstance();
065:
066: } catch (ClassNotFoundException e) {
067: // La factory no fue encontrada
068: throw new ServiceLocatorConfigurationError(
069: "Cannot load class "
070: + "GatewayServiceLocator class \"" + n
071: + "\"");
072: } catch (InstantiationException e) {
073: // La factory no pudo ser instanciada
074: throw new ServiceLocatorConfigurationError(
075: "Cannot instantiate the "
076: + "specified GatewayServiceLocator class \""
077: + n + "\"");
078: } catch (IllegalAccessException e) {
079: // La factory no pudo ser accedida
080: throw new ServiceLocatorConfigurationError(
081: "Cannot access the specified "
082: + "GatewayServiceLocator class \"" + n
083: + "\"");
084:
085: } catch (ClassCastException e) {
086: // La factory no era una RpsClientFactory
087: throw new ServiceLocatorConfigurationError(
088: "The specified class \""
089: + n
090: + "\" is not instance of \"org.josso.gateway.GatewayServiceLocator\"");
091: }
092:
093: }
094:
095: /**
096: * Locates the Single Sign-On Session Manager.
097: *
098: * @return an instance of the SSO Session Manager.
099: * @throws Exception
100: */
101: public abstract org.josso.gateway.session.service.SSOSessionManager getSSOSessionManager()
102: throws Exception;
103:
104: /**
105: * Locates the Single Sign-On Identity Manager.
106: *
107: * @return an instance of the SSO Identity Manager.
108: * @throws Exception
109: */
110: public abstract org.josso.gateway.identity.service.SSOIdentityManager getSSOIdentityManager()
111: throws Exception;
112:
113: /**
114: * Locates the Single Sign-On Identity Manager.
115: *
116: * @return an instance of the SSO Identity Provider.
117: * @throws Exception
118: */
119: public abstract org.josso.gateway.identity.service.SSOIdentityProvider getSSOIdentityProvider()
120: throws Exception;
121:
122: public static void main(String[] args) throws Exception {
123: String msg = GatewayServiceLocator.newInstance()
124: .getSSOSessionManager().initiateSession("user1");
125: System.out.println("msg = " + msg);
126: }
127:
128: }
|