01: /*
02: * Copyright 2005 Sun Microsystems, Inc. All
03: * rights reserved. Use of this product is subject
04: * to license terms. Federal Acquisitions:
05: * Commercial Software -- Government Users
06: * Subject to Standard License Terms and
07: * Conditions.
08: *
09: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
10: * are trademarks or registered trademarks of Sun Microsystems,
11: * Inc. in the United States and other countries.
12: */
13: package com.sun.portal.wsrp.wssso.common;
14:
15: import java.util.HashMap;
16: import java.util.logging.Level;
17: import java.util.logging.Logger;
18:
19: import com.iplanet.sso.SSOException;
20: import com.iplanet.sso.SSOToken;
21: import com.iplanet.sso.SSOTokenEvent;
22: import com.iplanet.sso.SSOTokenListener;
23: import com.sun.portal.log.common.PortalLogger;
24:
25: public class UserConfigurationManager implements SSOTokenListener {
26:
27: private static UserConfigurationManager userConfigs = new UserConfigurationManager();
28:
29: private HashMap cache = new HashMap();
30:
31: private static Logger debugLogger = PortalLogger
32: .getLogger(UserConfigurationManager.class);
33:
34: private UserConfigurationManager() {
35:
36: }
37:
38: public static UserConfigurationManager getInstance() {
39: return userConfigs;
40: }
41:
42: public UserConfiguration getUserConfiguration(SSOToken userToken)
43: throws SSOException {
44:
45: String userName = userToken.getPrincipal().getName();
46:
47: Object value = cache.get(userName);
48:
49: if (value != null) {
50: UserConfiguration config = (UserConfiguration) value;
51: config.reinit(userToken);
52: // There is no way to unregister an SSOToken listener
53: // Registering it multiple times generate multiple SSOToken events
54: // Hence commeting this for now
55: //userToken.addSSOTokenListener(this);
56: return config;
57: }
58:
59: UserConfiguration config = new UserConfiguration(userToken);
60: userToken.addSSOTokenListener(this );
61: synchronized (cache) {
62: cache.put(userName, config);
63: }
64: return config;
65:
66: }
67:
68: public void ssoTokenChanged(SSOTokenEvent ssoTokenEvent) {
69: try {
70: String userName = ssoTokenEvent.getToken().getPrincipal()
71: .getName();
72: synchronized (cache) {
73: cache.remove(userName);
74: }
75:
76: } catch (SSOException soe) {
77: debugLogger.log(Level.SEVERE, "", soe);
78: }
79: }
80: }
|