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.identity.service.ws;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.josso.gateway.identity.SSORole;
026: import org.josso.gateway.identity.SSOUser;
027: import org.josso.gateway.identity.exceptions.NoSuchUserException;
028: import org.josso.gateway.identity.exceptions.SSOIdentityException;
029: import org.josso.gateway.identity.service.BaseRoleImpl;
030: import org.josso.gateway.identity.service.BaseUserImpl;
031: import org.josso.gateway.identity.service.SSOIdentityManager;
032: import org.josso.gateway.identity.service.store.IdentityStore;
033: import org.josso.gateway.identity.service.store.IdentityStoreKeyAdapter;
034:
035: import java.util.ArrayList;
036: import java.util.List;
037:
038: /**
039: * Webservice client implementation for the SSO Identity Manager based on
040: * the Axis-generated Stub & Skeleton.
041: *
042: * @author <a href="mailto:gbrigand@josso.org">Gianluca Brigandi</a>
043: * @version CVS $Id: WebserviceSSOIdentityManager.java 508 2008-02-18 13:32:29Z sgonzalez $
044: */
045:
046: public class WebserviceSSOIdentityManager implements
047: org.josso.gateway.identity.service.SSOIdentityManager {
048: private static final Log logger = LogFactory
049: .getLog(SSOIdentityManager.class);
050:
051: private org.josso.gateway.identity.service.ws.impl.SSOIdentityManager _wsSSOIdentityManager;
052:
053: private int _errorCount;
054:
055: private int _processedCount;
056:
057: /**
058: * Build a Webservice SSO Identity Manager.
059: *
060: * @param wsSSOIdentityManager the SOAP stub to be invoked.
061: */
062: public WebserviceSSOIdentityManager(
063: org.josso.gateway.identity.service.ws.impl.SSOIdentityManager wsSSOIdentityManager) {
064: _wsSSOIdentityManager = wsSSOIdentityManager;
065: }
066:
067: /**
068: * Initializes this manager instance.
069: */
070: public void initialize() {
071:
072: }
073:
074: /**
075: * Finds a user based on its name. The name is a unique identifier of the user, probably the user login.
076: *
077: * @param name
078: *
079: * @throws org.josso.gateway.identity.exceptions.NoSuchUserException
080: * if the user does not exist.
081: */
082: public SSOUser findUser(String name) throws NoSuchUserException,
083: SSOIdentityException {
084:
085: try {
086: if (logger.isDebugEnabled())
087: logger.debug("[findUser()] : " + name);
088: return adaptSSOUser(_wsSSOIdentityManager.findUser(name));
089: } catch (org.josso.gateway.identity.service.ws.impl.NoSuchUserException e) {
090: throw new NoSuchUserException(e.getMessage());
091:
092: } catch (java.rmi.RemoteException e) {
093: _errorCount++;
094: throw new SSOIdentityException(e.getMessage(), e);
095: } finally {
096: _processedCount++;
097: }
098: }
099:
100: /**
101: * Finds the user associated to a sso session
102: *
103: * @param sessionId the sso session identifier
104: *
105: * @throws org.josso.gateway.identity.exceptions.NoSuchUserException
106: * if no user is associated to this session id.
107: */
108: public SSOUser findUserInSession(String sessionId)
109: throws NoSuchUserException, SSOIdentityException {
110:
111: try {
112: if (logger.isDebugEnabled())
113: logger.debug("[findUserInSession()] : " + sessionId);
114: return adaptSSOUser(_wsSSOIdentityManager
115: .findUserInSession(sessionId));
116:
117: } catch (org.josso.gateway.identity.service.ws.impl.SSOIdentityException e) {
118: throw new SSOIdentityException(e.getMessage(), e);
119:
120: } catch (java.rmi.RemoteException e) {
121: _errorCount++;
122: throw new SSOIdentityException(e.getMessage(), e);
123: } finally {
124: _processedCount++;
125: }
126: }
127:
128: /**
129: * Finds a collection of user's roles.
130: * Elements in the collection are SSORole instances.
131: *
132: * @param username
133: *
134: * @throws org.josso.gateway.identity.exceptions.SSOIdentityException
135: *
136: */
137: public SSORole[] findRolesByUsername(String username)
138: throws SSOIdentityException {
139: try {
140: if (logger.isDebugEnabled())
141: logger.debug("[findRolesByUsername()] : " + username);
142: return adaptSSORoles(_wsSSOIdentityManager
143: .findRolesByUsername(username));
144: } catch (java.rmi.RemoteException e) {
145: _errorCount++;
146: throw new SSOIdentityException(e.getMessage(), e);
147: } finally {
148: _processedCount++;
149: }
150: }
151:
152: public void userExists(String username) throws NoSuchUserException,
153: SSOIdentityException {
154: try {
155: if (logger.isDebugEnabled())
156: logger.debug("[userExists()] : " + username);
157: _wsSSOIdentityManager.userExists(username);
158: } catch (java.rmi.RemoteException e) {
159: _errorCount++;
160: throw new SSOIdentityException(e.getMessage(), e);
161: } finally {
162: _processedCount++;
163: }
164: }
165:
166: /**
167: * Maps a SOAP SSOUser type instance to a JOSSO SSOUser type instance.
168: *
169: * @param srcSSOUser the SOAP type instance to be mapped.
170: * @return the mapped user
171: */
172: protected org.josso.gateway.identity.SSOUser adaptSSOUser(
173: org.josso.gateway.identity.service.ws.impl.SSOUser srcSSOUser) {
174:
175: BaseUserImpl targetSSOUser = new BaseUserImpl();
176:
177: targetSSOUser.setName(srcSSOUser.getName());
178:
179: // map Properties
180: org.josso.gateway.identity.service.ws.impl.SSONameValuePair[] properties = srcSSOUser
181: .getProperties();
182:
183: List nvList = new ArrayList();
184: for (int i = 0; i < properties.length; i++) {
185: nvList.add(adaptSSOValuePair(properties[i]));
186: }
187:
188: targetSSOUser
189: .setProperties((org.josso.gateway.SSONameValuePair[]) nvList
190: .toArray(new org.josso.gateway.SSONameValuePair[nvList
191: .size()]));
192:
193: return targetSSOUser;
194: }
195:
196: /**
197: * Maps a SOAP SSOValuePair type instance to a JOSSO SSOValuePair type instance.
198: *
199: * @param srcSSONameValuePair the SOAP type instance to be mapped.
200: * @return the mapped value pair
201: */
202: protected org.josso.gateway.SSONameValuePair adaptSSOValuePair(
203: org.josso.gateway.identity.service.ws.impl.SSONameValuePair srcSSONameValuePair) {
204:
205: BaseUserImpl targetSSOUser = new BaseUserImpl();
206: org.josso.gateway.SSONameValuePair targetSSONameValuePair = new org.josso.gateway.SSONameValuePair(
207: srcSSONameValuePair.getName(), srcSSONameValuePair
208: .getValue());
209:
210: return targetSSONameValuePair;
211: }
212:
213: /**
214: * Maps a SOAP SSORole type instance to a JOSSO SSORole type instance.
215: *
216: * @param srcSSORole the SOAP type instance to be mapped.
217: * @return the mapped role
218: */
219: protected org.josso.gateway.identity.SSORole adaptSSORole(
220: org.josso.gateway.identity.service.ws.impl.SSORole srcSSORole) {
221:
222: BaseRoleImpl targetSSORole = new BaseRoleImpl();
223:
224: targetSSORole.setName(srcSSORole.getName());
225: return targetSSORole;
226: }
227:
228: /**
229: * Maps one or more SOAP SSORole type instancess to one or more JOSSO SSORole type instances.
230: *
231: * @param srcSSORoles the SOAP type instances to be mapped.
232: * @return the mapped roles
233: */
234: protected org.josso.gateway.identity.SSORole[] adaptSSORoles(
235: org.josso.gateway.identity.service.ws.impl.SSORole[] srcSSORoles) {
236:
237: ArrayList targetSSORoles = new ArrayList();
238: for (int i = 0; i < srcSSORoles.length; i++) {
239: targetSSORoles.add(adaptSSORole(srcSSORoles[i]));
240: }
241:
242: return (SSORole[]) targetSSORoles
243: .toArray(new BaseRoleImpl[targetSSORoles.size()]);
244: }
245:
246: /**
247: * Provided for compatibility only ...
248: */
249: public void setIdentityStoreKeyAdapter(IdentityStoreKeyAdapter a) {
250: throw new UnsupportedOperationException(
251: "Not supported by this type of manager");
252: }
253:
254: /**
255: * Provided for compatibility only ...
256: */
257: public void setIdentityStore(IdentityStore is) {
258: throw new UnsupportedOperationException(
259: "Not supported by this type of manager");
260: }
261:
262: public int getErrorCount() {
263: return _errorCount;
264: }
265:
266: public int getProcessedCount() {
267: return _processedCount;
268: }
269:
270: }
|