01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.taskadmin.context;
06:
07: import java.util.HashMap;
08: import java.util.logging.Level;
09: import java.util.logging.Logger;
10:
11: import javax.servlet.http.HttpServletRequest;
12:
13: import com.sun.portal.taskadmin.TaskAdminException;
14: import com.sun.portal.taskadmin.TaskAdminConstants;
15: import com.sun.portal.taskadmin.context.TaskAdminISConnection;
16:
17: import com.sun.portal.desktop.context.ContextError;
18: import com.sun.portal.log.common.PortalLogger;
19:
20: import com.iplanet.sso.SSOTokenListener;
21: import com.iplanet.sso.SSOTokenEvent;
22:
23: public class ISUserTaskAdminContextFactory implements
24: UserTaskAdminContextFactory, SSOTokenListener {
25:
26: private static Logger logger = PortalLogger
27: .getLogger(ISUserTaskAdminContextFactory.class);
28: private HashMap userTaskAdminContexts = new HashMap();
29:
30: public ISUserTaskAdminContextFactory() {
31: //do nothing
32: }
33:
34: public void init() {
35: // do nothing for now.
36: }
37:
38: public UserTaskAdminContext getUserTaskAdminContext(
39: HttpServletRequest req) throws TaskAdminException {
40: return getUserTaskAdminContext(req, true);
41: }
42:
43: public synchronized UserTaskAdminContext getUserTaskAdminContext(
44: HttpServletRequest req, boolean create)
45: throws TaskAdminException {
46:
47: ISUserTaskAdminContext context = null;
48: String sid = getSessionID(req);
49: context = (ISUserTaskAdminContext) userTaskAdminContexts
50: .get(sid);
51:
52: if (context == null && create) {
53: //
54: // could not find in cache
55: // create a new one
56: //
57:
58: try {
59: context = new ISUserTaskAdminContext();
60: context.init(req);
61: //
62: // put the new object into the cache
63: //
64: context.addSSOTokenListener(this );
65: logger.log(Level.FINER, "PSCR_CSPTAC0001");
66: userTaskAdminContexts.put(sid, context);
67: } catch (SecurityException se) {
68: throw new ContextError(
69: "UserTaskAdminContextFactory.getUserTaskAdminContext(): ",
70: se);
71: }
72: }
73:
74: return context;
75: }
76:
77: public synchronized void ssoTokenChanged(SSOTokenEvent se) {
78: String sid = se.getToken().getTokenID().toString();
79: System.out.println("received the SSOTokenevent for sid=" + sid);
80: userTaskAdminContexts.remove(sid);
81:
82: }
83:
84: public String getSessionID(HttpServletRequest req)
85: throws TaskAdminException {
86: return TaskAdminISConnection.getSSOToken(req).getTokenID()
87: .toString();
88: }
89:
90: }
|