01: /*
02: * Created by IntelliJ IDEA.
03: * User: sanjib.ghosh@sun.com
04: * Date: Jan 10, 2002
05: * Time: $TME$
06: */
07: package com.sun.portal.proxylet.servlet;
08:
09: import com.iplanet.am.sdk.AMException;
10: import com.iplanet.am.sdk.AMStoreConnection;
11: import com.iplanet.am.sdk.AMUser;
12: import com.iplanet.sso.SSOException;
13: import com.iplanet.sso.SSOToken;
14:
15: import java.util.*;
16:
17: public class UserAttributes {
18:
19: private String attributePrefix;
20: //private Map userAttributes;
21: protected AMUser user = null;
22: protected Map userAttributes;
23: public boolean applyDefault;
24:
25: public UserAttributes(SSOToken token, String attributePrefix1) {
26: try {
27: AMStoreConnection connection = new AMStoreConnection(token);
28: user = connection.getUser(token.getPrincipal().getName());
29: userAttributes = user.getAttributes();
30: attributePrefix = attributePrefix1;
31: applyDefault = false;
32: } catch (SSOException ssoe) {
33: applyDefault = true;
34: } catch (AMException dpe) {
35: applyDefault = true;
36: }
37: }
38:
39: public String getString(String name, String defaultValue) {
40: return (applyDefault) ? defaultValue : AttributeExtractor
41: .getString(userAttributes, attributePrefix + name,
42: defaultValue);
43: }
44:
45: public int getInt(String name, int defaultValue) {
46: return (applyDefault) ? defaultValue : AttributeExtractor
47: .getInt(userAttributes, attributePrefix + name,
48: defaultValue);
49: }
50:
51: public boolean getBoolean(String name, boolean defaultValue) {
52: return (applyDefault) ? defaultValue : AttributeExtractor
53: .getBoolean(userAttributes, attributePrefix + name,
54: defaultValue);
55: }
56:
57: public List getStringList(String name) {
58: return (applyDefault) ? new ArrayList() : AttributeExtractor
59: .getStringList(userAttributes, attributePrefix + name);
60: }
61:
62: public String getPreferredLocale(String defaultValue) {
63: return (applyDefault) ? defaultValue : AttributeExtractor
64: .getString(userAttributes, "preferredlocale",
65: defaultValue);
66: }
67:
68: public void setStringList(String name, List value) {
69: HashSet hs = new HashSet(value);
70: Map changedMap = new HashMap();
71: changedMap.put(attributePrefix + name, hs);
72: try {
73: user.setAttributes(changedMap);
74: user.store();
75: } catch (SSOException ssoe) {
76: } catch (AMException ame) {
77: }
78: }
79:
80: public void setString(String name, String value) {
81: HashSet hs = new HashSet(1);
82: hs.add((Object) value);
83: Map changedMap = new HashMap();
84: changedMap.put(attributePrefix + name, hs);
85: try {
86: user.setAttributes(changedMap);
87: user.store();
88: } catch (SSOException ssoe) {
89: } catch (AMException ame) {
90: }
91: }
92:
93: }
|