001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.taskadmin.context;
006:
007: import java.util.HashMap;
008:
009: import javax.servlet.http.HttpServletRequest;
010:
011: import com.sun.portal.taskadmin.TaskAdminException;
012: import com.sun.portal.taskadmin.TaskAdminConstants;
013:
014: import com.sun.portal.desktop.context.ContextError;
015:
016: import com.iplanet.sso.SSOToken;
017: import com.iplanet.sso.SSOTokenListener;
018: import com.iplanet.sso.SSOTokenEvent;
019:
020: public class ISTaskAdminContextFactory implements
021: TaskAdminContextFactory, SSOTokenListener {
022:
023: private HashMap taskAdminContexts = new HashMap();
024:
025: public ISTaskAdminContextFactory() {
026: //do nothing
027: }
028:
029: public void init() {
030: // do nothing for now.
031: }
032:
033: public TaskAdminContext getTaskAdminContext(HttpServletRequest req)
034: throws TaskAdminException {
035: return getTaskAdminContext(req, true);
036: }
037:
038: public synchronized TaskAdminContext getTaskAdminContext(
039: HttpServletRequest req, boolean create)
040: throws TaskAdminException {
041:
042: ISTaskAdminContext context = null;
043: String sid = getSessionID(req);
044: context = (ISTaskAdminContext) taskAdminContexts.get(sid);
045:
046: if (context == null && create) {
047: //
048: // could not find in cache
049: // create a new one
050: //
051:
052: try {
053: context = new ISTaskAdminContext();
054: context.init(req);
055: //
056: // put the new object into the cache
057: //
058: context.addSSOTokenListener(this );
059: //context.debugError("added the token listener");
060:
061: taskAdminContexts.put(sid, context);
062: } catch (SecurityException se) {
063: throw new ContextError(
064: "TaskAdminContextFactory.getTaskAdminContext(): ",
065: se);
066: }
067: }
068:
069: return context;
070: }
071:
072: public TaskAdminContext getTaskAdminContext(SSOToken ssoToken,
073: String portalId) throws TaskAdminException {
074: return getTaskAdminContext(ssoToken, true, portalId);
075: }
076:
077: public synchronized TaskAdminContext getTaskAdminContext(
078: SSOToken ssoToken, boolean create, String portalId)
079: throws TaskAdminException {
080:
081: ISTaskAdminContext context = null;
082: String sid = ssoToken.getTokenID().toString();
083: context = (ISTaskAdminContext) taskAdminContexts.get(sid);
084:
085: if (context == null && create) {
086: //
087: // could not find in cache
088: // create a new one
089: //
090:
091: try {
092: context = new ISTaskAdminContext();
093: context.init(ssoToken, portalId);
094: //
095: // put the new object into the cache
096: //
097: context.addSSOTokenListener(this );
098: //context.debugError("added the token listener");
099:
100: taskAdminContexts.put(sid, context);
101: } catch (SecurityException se) {
102: throw new ContextError(
103: "TaskAdminContextFactory.getTaskAdminContext(): ",
104: se);
105: }
106: }
107:
108: return context;
109: }
110:
111: public synchronized void ssoTokenChanged(SSOTokenEvent se) {
112: String sid = se.getToken().getTokenID().toString();
113: System.out.println("received the SSOTokenevent for sid=" + sid);
114: taskAdminContexts.remove(sid);
115:
116: }
117:
118: public String getSessionID(HttpServletRequest req)
119: throws TaskAdminException {
120: return TaskAdminISConnection.getSSOToken(req).getTokenID()
121: .toString();
122: }
123:
124: }
|