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.session.service.ws;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.josso.gateway.session.SSOSession;
026: import org.josso.gateway.session.exceptions.NoSuchSessionException;
027: import org.josso.gateway.session.exceptions.SSOSessionException;
028: import org.josso.gateway.session.service.SSOSessionManager;
029: import org.josso.gateway.session.service.SessionIdGenerator;
030: import org.josso.gateway.session.service.MutableBaseSession;
031: import org.josso.gateway.session.service.store.SessionStore;
032: import org.josso.gateway.assertion.exceptions.AssertionNotValidException;
033:
034: import java.rmi.RemoteException;
035: import java.util.Collection;
036:
037: /**
038: * Webservice client implementation for the SSO Session Manager based on
039: * the Axis-generated Stub & Skeleton.
040: *
041: * @author <a href="mailto:gbrigand@josso.org">Gianluca Brigandi</a>
042: * @version CVS $Id: WebserviceSSOSessionManager.java 508 2008-02-18 13:32:29Z sgonzalez $
043: */
044:
045: public class WebserviceSSOSessionManager implements
046: org.josso.gateway.session.service.SSOSessionManager {
047: private static final Log logger = LogFactory
048: .getLog(SSOSessionManager.class);
049:
050: private org.josso.gateway.session.service.ws.impl.SSOSessionManager _wsSSOSessionManager;
051:
052: private long _processedCount;
053: private long _errorCount;
054:
055: /**
056: * Build a Webservice SSO Session Manager.
057: *
058: * @param wsSSOSessionManager the SOAP stub to be invoked.
059: */
060: public WebserviceSSOSessionManager(
061: org.josso.gateway.session.service.ws.impl.SSOSessionManager wsSSOSessionManager) {
062: _wsSSOSessionManager = wsSSOSessionManager;
063: }
064:
065: /**
066: * Initiates a new session. The session id is returned.
067: *
068: * @return the new session identifier.
069: */
070: public String initiateSession(String username)
071: throws SSOSessionException {
072: try {
073: return _wsSSOSessionManager.initiateSession(username);
074: } catch (java.rmi.RemoteException e) {
075: _errorCount++;
076: throw new SSOSessionException(e.getMessage(), e);
077: } finally {
078: _processedCount++;
079: }
080: }
081:
082: /**
083: * This method accesss the session associated to the received id.
084: * This resets the session last access time and updates the access count.
085: *
086: * @param sessionId the session id previously returned by initiateSession.
087: * @throws org.josso.gateway.session.exceptions.NoSuchSessionException if the session id is not related to any sso session.
088: */
089: public void accessSession(String sessionId)
090: throws NoSuchSessionException, SSOSessionException {
091:
092: try {
093: _wsSSOSessionManager.accessSession(sessionId);
094: } catch (org.josso.gateway.session.service.ws.impl.NoSuchSessionException e) {
095: throw new org.josso.gateway.session.exceptions.NoSuchSessionException(
096: e.getMessage());
097:
098: } catch (java.rmi.RemoteException e) {
099: _errorCount++;
100: throw new SSOSessionException(e.getMessage(), e);
101: } finally {
102: _processedCount++;
103: }
104:
105: }
106:
107: /**
108: * Gets an SSO session based on its id.
109: *
110: * @param sessionId the session id previously returned by initiateSession.
111: * @throws org.josso.gateway.session.exceptions.NoSuchSessionException if the session id is not related to any sso session.
112: */
113: public SSOSession getSession(String sessionId)
114: throws NoSuchSessionException, SSOSessionException {
115:
116: try {
117: return adaptSSOSession(_wsSSOSessionManager
118: .getSession(sessionId));
119: } catch (org.josso.gateway.session.service.ws.impl.NoSuchSessionException e) {
120: throw new org.josso.gateway.session.exceptions.NoSuchSessionException(
121: e.getMessage());
122:
123: } catch (java.rmi.RemoteException e) {
124: _errorCount++;
125: throw new SSOSessionException(e.getMessage(), e);
126: } finally {
127: _processedCount++;
128: }
129:
130: }
131:
132: /**
133: * Gets all SSO sessions.
134: */
135: public Collection getSessions() throws SSOSessionException {
136: throw new UnsupportedOperationException(
137: "Not supported by this implementation");
138: }
139:
140: /**
141: * Gets an SSO session based on the associated user.
142: *
143: * @param username the username used when initiating the session.
144: * @throws org.josso.gateway.session.exceptions.NoSuchSessionException if the session id is not related to any sso session.
145: */
146: public Collection getUserSessions(String username)
147: throws NoSuchSessionException, SSOSessionException {
148: throw new UnsupportedOperationException(
149: "Not supported by this implementation");
150: }
151:
152: /**
153: * Invalidates all sessions, (not supported)
154: *
155: */
156: public void invalidateAll() throws SSOSessionException {
157: throw new UnsupportedOperationException(
158: "Not supported by this implementation");
159: }
160:
161: /**
162: * Invalidates a session.
163: *
164: * @param sessionId the session id previously returned by initiateSession.
165: * @throws org.josso.gateway.session.exceptions.NoSuchSessionException if the session id is not related to any sso session.
166: */
167: public void invalidate(String sessionId)
168: throws NoSuchSessionException, SSOSessionException {
169:
170: try {
171: _wsSSOSessionManager.invalidate(sessionId);
172: } catch (java.rmi.RemoteException e) {
173: _errorCount++;
174: throw new SSOSessionException(e.getMessage(), e);
175: } finally {
176: _processedCount++;
177: }
178:
179: }
180:
181: /**
182: * Check all sessions and remove those that are not valid from the store.
183: * This method is invoked periodically to update sessions state.
184: */
185: public void checkValidSessions() {
186:
187: try {
188: _wsSSOSessionManager.checkValidSessions();
189: } catch (java.rmi.RemoteException e) {
190: _errorCount++;
191: } finally {
192: _processedCount++;
193: }
194:
195: }
196:
197: /**
198: * For compatibility only
199: */
200: public void initialize() {
201: }
202:
203: /**
204: * For compatibility only
205: */
206: public void setSessionStore(SessionStore ss) {
207: throw new UnsupportedOperationException(
208: "Not supporte by this implementation");
209: }
210:
211: /**
212: * For compatibility only
213: */
214: public void setSessionIdGenerator(SessionIdGenerator g) {
215: throw new UnsupportedOperationException(
216: "Not supported by this implementation");
217: }
218:
219: public int getSessionCount() throws SSOSessionException {
220: try {
221: return _wsSSOSessionManager.getSessionCount();
222: } catch (RemoteException e) {
223: throw new SSOSessionException(e.getMessage(), e);
224: }
225: }
226:
227: public long getErrorCount() {
228: return _errorCount;
229: }
230:
231: public long getProcessedCount() {
232: return _processedCount;
233: }
234:
235: /**
236: * Maps a SOAP SSOSession type instance to a JOSSO SSOSession type instance.
237: *
238: * @param srcSSOSession the SOAP type instance to be mapped.
239: * @return the mapped session
240: */
241: protected org.josso.gateway.session.SSOSession adaptSSOSession(
242: org.josso.gateway.session.service.ws.impl.SSOSession srcSSOSession) {
243:
244: MutableBaseSession targetSSOSession = new MutableBaseSession();
245:
246: targetSSOSession.setId(srcSSOSession.getId());
247: targetSSOSession.setCreationTime(srcSSOSession
248: .getCreationTime());
249: targetSSOSession.setLastAccessedTime(srcSSOSession
250: .getLastAccessTime());
251: targetSSOSession.setMaxInactiveInterval(srcSSOSession
252: .getMaxInactiveInterval());
253: targetSSOSession.setUsername(srcSSOSession.getUsername());
254: targetSSOSession.setAccessCount(srcSSOSession.getAccessCount());
255:
256: return targetSSOSession;
257:
258: }
259:
260: }
|