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.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.josso.ComponentKeeper;
026: import org.josso.Lookup;
027: import org.josso.MBeanComponentKeeper;
028: import org.josso.gateway.session.service.ws.WebserviceSSOSessionManager;
029: import org.josso.gateway.identity.service.SSOIdentityProvider;
030:
031: /**
032: * Service Locator for Gateway Services available as Webservices.
033: *
034: * @author <a href="mailto:gbrigand@josso.org">Gianluca Brigandi</a>
035: * @version CVS $Id: WebserviceGatewayServiceLocator.java 508 2008-02-18 13:32:29Z sgonzalez $
036: */
037:
038: public class WebserviceGatewayServiceLocator extends
039: GatewayServiceLocator {
040:
041: private static final Log logger = LogFactory
042: .getLog(WebserviceGatewayServiceLocator.class);
043:
044: private static final String TRANSPORT_SECURITY_NONE = "none";
045: private static final String TRANSPORT_SECURITY_CONFIDENTIAL = "confidential";
046:
047: private String _endpoint;
048: private String _username;
049: private String _transportSecurity = TRANSPORT_SECURITY_NONE;
050: private String _servicesWebContext;
051:
052: /**
053: * Package private Constructor so that it can only be instantiated
054: * by the GatewayServiceLocator Class.
055: */
056: public WebserviceGatewayServiceLocator() {
057: }
058:
059: /**
060: * Locates the SSO Session Manager Service Webservice implementation.
061: *
062: * @return the SSO session manager WS implementation.
063: * @throws Exception
064: */
065: public org.josso.gateway.session.service.SSOSessionManager getSSOSessionManager()
066: throws Exception {
067:
068: org.josso.gateway.session.service.ws.impl.SSOSessionManagerServiceLocator ssoManagerServiceLocator = new org.josso.gateway.session.service.ws.impl.SSOSessionManagerServiceLocator();
069: org.josso.gateway.session.service.ws.impl.SSOSessionManager ssoSessionManagerWebservice;
070:
071: String smEndpoint = getEndpointBase()
072: + "/services/SSOSessionManager";
073:
074: logger.debug("Using SSOSessionManager endpoint '" + smEndpoint
075: + "'");
076:
077: ssoManagerServiceLocator
078: .setSSOSessionManagerEndpointAddress(smEndpoint);
079:
080: ssoSessionManagerWebservice = ssoManagerServiceLocator
081: .getSSOSessionManager();
082:
083: WebserviceSSOSessionManager wsm = new WebserviceSSOSessionManager(
084: ssoSessionManagerWebservice);
085:
086: ComponentKeeper ck = Lookup.getInstance().getComponentKeeper();
087: if (ck instanceof MBeanComponentKeeper) {
088: MBeanComponentKeeper mbeanCk = (MBeanComponentKeeper) ck;
089: mbeanCk.registerResource(mbeanCk.buildObjectName(wsm,
090: "WebserviceSSOSessionManager"), wsm);
091: }
092:
093: return wsm;
094: }
095:
096: /**
097: * Locates the SSO Identity Manager Service Webservice implementation.
098: *
099: * @return the SSO session manager WS implementation.
100: * @throws Exception
101: */
102: public org.josso.gateway.identity.service.SSOIdentityManager getSSOIdentityManager()
103: throws Exception {
104: org.josso.gateway.identity.service.ws.impl.SSOIdentityManagerServiceLocator ssoIdentityManagerServiceLocator = new org.josso.gateway.identity.service.ws.impl.SSOIdentityManagerServiceLocator();
105: org.josso.gateway.identity.service.ws.impl.SSOIdentityManager ssoIdentityManagerWebservice;
106:
107: String imEndpoint = getEndpointBase()
108: + "/services/SSOIdentityManager";
109:
110: logger.debug("Using SSOIdentityManager endpoint '" + imEndpoint
111: + "'");
112:
113: ssoIdentityManagerServiceLocator
114: .setSSOIdentityManagerEndpointAddress(imEndpoint);
115:
116: ssoIdentityManagerWebservice = ssoIdentityManagerServiceLocator
117: .getSSOIdentityManager();
118:
119: org.josso.gateway.identity.service.ws.WebserviceSSOIdentityManager wim = new org.josso.gateway.identity.service.ws.WebserviceSSOIdentityManager(
120: ssoIdentityManagerWebservice);
121:
122: ComponentKeeper ck = Lookup.getInstance().getComponentKeeper();
123: if (ck instanceof MBeanComponentKeeper) {
124: MBeanComponentKeeper mbeanCk = (MBeanComponentKeeper) ck;
125: mbeanCk.registerResource(mbeanCk.buildObjectName(wim,
126: "WebserviceSSOIdentityManager"), wim);
127: }
128:
129: return wim;
130: }
131:
132: /**
133: * Locates the SSO Identity Provider Service Webservice implementation.
134: *
135: * @return the SSO identity provider manager WS implementation.
136: * @throws Exception
137: */
138: public org.josso.gateway.identity.service.SSOIdentityProvider getSSOIdentityProvider()
139: throws Exception {
140: org.josso.gateway.identity.service.ws.impl.SSOIdentityProviderServiceLocator ssoIdentityProviderServiceLocator = new org.josso.gateway.identity.service.ws.impl.SSOIdentityProviderServiceLocator();
141: org.josso.gateway.identity.service.ws.impl.SSOIdentityProvider ssoIdentityProviderWebservice;
142:
143: String ipEndpoint = getEndpointBase()
144: + "/services/SSOIdentityProvider";
145:
146: logger.debug("Using SSOIdentityProvider endpoint '"
147: + ipEndpoint + "'");
148:
149: ssoIdentityProviderServiceLocator
150: .setSSOIdentityProviderEndpointAddress(ipEndpoint);
151:
152: ssoIdentityProviderWebservice = ssoIdentityProviderServiceLocator
153: .getSSOIdentityProvider();
154:
155: org.josso.gateway.identity.service.ws.WebserviceSSOIdentityProvider wip = new org.josso.gateway.identity.service.ws.WebserviceSSOIdentityProvider(
156: ssoIdentityProviderWebservice);
157:
158: ComponentKeeper ck = Lookup.getInstance().getComponentKeeper();
159: if (ck instanceof MBeanComponentKeeper) {
160: MBeanComponentKeeper mbeanCk = (MBeanComponentKeeper) ck;
161: mbeanCk.registerResource(mbeanCk.buildObjectName(wip,
162: "WebserviceSSOIdentityProvider"), wip);
163: }
164:
165: return wip;
166: }
167:
168: /**
169: * Builds the endpoint base string.
170: *
171: * @return the endpoint base
172: */
173: private String getEndpointBase() {
174: return (_transportSecurity
175: .equalsIgnoreCase(TRANSPORT_SECURITY_CONFIDENTIAL) ? "https"
176: : "http")
177: + "://"
178: + _endpoint
179: + "/"
180: + (_servicesWebContext != null ? _servicesWebContext
181: : "josso");
182:
183: }
184:
185: //----------------------------------------------------------------- Configuration Properties
186:
187: /**
188: * SOAP end point, e.g. localhost:8080
189: */
190: public void setEndpoint(String endpoint) {
191: _endpoint = endpoint;
192: }
193:
194: /**
195: * SOAP end point, e.g. localhost:8080
196: */
197: public String getEndpoint() {
198: return _endpoint;
199: }
200:
201: /**
202: * SOAP end point services web context, e.g. myjosso
203: */
204: public void setServicesWebContext(String servicesWebContext) {
205: _servicesWebContext = servicesWebContext;
206: }
207:
208: /**
209: * SOAP end point services web context, e.g. myjosso
210: */
211: public String getServicesWebContext() {
212: return _servicesWebContext;
213: }
214:
215: /**
216: * Set the username used to authenticate SOAP messages.
217: *
218: * @param username the username used to authenticate the SOAP message.
219: */
220: public void setUsername(String username) {
221: WebserviceClientAuthentication.setUsername(username);
222: _username = username;
223: }
224:
225: /**
226: * Getter for username used to authenticate SOAP messages.
227: */
228: public String getUsername() {
229: return _username;
230: }
231:
232: /**
233: * Set the password used to authenticate SOAP messages.
234: *
235: * @param password the password used to authenticate the SOAP message.
236: */
237: public void setPassword(String password) {
238: WebserviceClientAuthentication.setPassword(password);
239: }
240:
241: public String getPassword() {
242: return "*";
243: }
244:
245: /**
246: * Transport security used in SOAP messages, valid values are : none, confidential
247: * @param transportSecurity valid values are none, confidential
248: */
249: public void setTransportSecurity(String transportSecurity) {
250: _transportSecurity = transportSecurity;
251: }
252:
253: /**
254: * Transport security used in SOAP messages, valid values are : none|confidential
255: */
256: public String getTransportSecurity() {
257: return _transportSecurity;
258: }
259:
260: }
|