001: /*
002: * $Id: UserProfile.java,v 1.19 2006/03/20 07:29:43 ss150821 Exp $
003: * $Source: /m/portal/ps/srap/src/com/sun/portal/rproxy/configservlet/client/UserProfile.java,v $
004: * $Log: UserProfile.java,v $
005: * Revision 1.19 2006/03/20 07:29:43 ss150821
006: * 6279950
007: *
008: * Revision 1.18 2005/11/30 11:27:18 ss150821
009: * 6356996 - Srap Code base needs to save files in the unix file format and not windows
010: *
011: * Revision 1.17 2005/09/21 11:06:59 dg154973
012: * CR 6280402 - log system results in excessive lock contention
013: *
014: * Revision 1.16 2005/03/30 09:03:54 dg154973
015: * CR 6247264 PortalLogger should not be used with 'this' option
016: *
017: * Revision 1.15 2005/02/25 09:44:11 ss150821
018: * RFE 6223490 - SRA Should use JDK based logging, changed to start throwing the full stacktrace for the exception in the logs
019: *
020: * Revision 1.14 2005/02/23 09:14:06 ss150821
021: * RFE 6223490 - SRA Should use JDK based logging
022: *
023: * Revision 1.13 2005/02/23 09:13:05 ss150821
024: * RFE 6223490 - SRA Should use JDK based logging
025: *
026: * Revision 1.12 2004/11/18 09:53:14 ss150821
027: * Bug #6195816 - Significant performance degradation when Gateway Logging (Identity) Enabled on the SRA
028: *
029: * Revision 1.11 2004/07/27 12:52:04 vt126379
030: * RFE#5075809, CRT#99
031: *
032: * Revision 1.10 2003/09/01 12:11:06 mm132998
033: * Bug ID : 4911706 , 4801456
034: *
035: * Revision 1.9 2003/07/10 13:56:15 mm132998
036: * Decoding Session Id.
037: *
038: * Revision 1.8 2003/05/28 13:21:24 mm132998
039: * Custom Auth level
040: *
041: * Revision 1.7 2003/04/17 12:35:00 bv131302
042: * always decode before calling createSSOToken
043: *
044: * Revision 1.6 2003/01/23 10:10:12 bv131302
045: * id60 changes merged
046: *
047: * Revision 1.4.4.1 2002/12/30 11:13:47 bv131302
048: * id60 related changes
049: *
050: * Revision 1.4 2002/10/17 12:38:31 bv131302
051: * bringing some early changes of appserver_branch into the tip
052: *
053: * Revision 1.3 2002/07/29 05:07:15 rt130506
054: * CRT 1742
055: *
056: * Revision 1.2 2002/06/21 13:04:13 bv131302
057: * LDAP Attribute name changes
058: *
059: * Revision 1.1 2002/06/14 09:53:49 rt130506
060: * SRAP rebranding
061: *
062: * Revision 1.6 2002/06/11 16:02:10 bv131302
063: * new branded
064: *
065: * Revision 1.5 2002/05/28 13:22:41 mm132998
066: * Bug Id - 4692248 , CRT - 1217
067: *
068: * Revision 1.4 2002/05/13 06:22:26 mm132998
069: * Perf related modifications
070: *
071: * Revision 1.3 2002/02/21 06:03:33 mm132998
072: * Checkin for Bug id : 4640268 - RProxy migration to iDSAME
073: *
074: *
075: */
076: package com.sun.portal.rproxy.configservlet.client;
077:
078: import java.net.URLDecoder;
079: import java.util.ArrayList;
080: import java.util.List;
081: import java.util.Map;
082: import java.util.Set;
083: import java.util.logging.Level;
084: import java.util.logging.Logger;
085:
086: import com.iplanet.sso.SSOException;
087: import com.iplanet.sso.SSOToken;
088: import com.iplanet.sso.SSOTokenManager;
089: import com.sun.portal.log.common.PortalLogger;
090: import com.sun.portal.util.SSOUtil;
091:
092: public class UserProfile {
093:
094: private static final String GET_REQUEST = "GET_USERS";
095:
096: private Map result;
097:
098: private String sId;
099:
100: private static Logger logger = PortalLogger
101: .getLogger(UserProfile.class);
102:
103: public String toString() {
104: return result.toString();
105: }
106:
107: // sessionId is expected to be decoded (if necessary)
108: public UserProfile(String sessionId) throws SendRequestException,
109: GetResponseException {
110: try {
111: sId = null;
112: SSOTokenManager ssoTokenManager = SSOTokenManager
113: .getInstance();
114: SSOToken s = null;
115: try {
116: s = SSOUtil
117: .getSSOTokenThrowExceptionToClient(sessionId);
118: } catch (SSOException ssoEx) {
119: result = null;
120: } catch (Exception e) {
121: result = null;
122: }
123:
124: String cookieEncode = com.iplanet.am.util.SystemProperties
125: .get("com.iplanet.am.cookie.encode");
126: if (cookieEncode.equals("false"))
127: sId = sessionId;
128: else
129: sId = URLDecoder.decode(sessionId);
130:
131: if (s == null || !ssoTokenManager.isValidToken(s)) {
132: result = null;
133: } else {
134: // System.out.println("Auth level : "+s.getAuthLevel());
135: result = UserProfileGatewayCache.getResponse(sId);
136: }
137: // System.out.println("Suceeded in getting profile : " + result);
138: } catch (Exception ex) {
139: result = null;
140: // System.out.println("EXCEPTION !!!!!!!!!!!!!!!!");
141: // ex.printStackTrace();
142: // logger.log(Level.SEVERE, "Exception getting user profile", ex);
143: logger.log(Level.SEVERE, "PSSRRPROXY_CSPRCSERVLETC006", ex);
144: }
145: }
146:
147: public String getSessionID() {
148: return sId;
149: }
150:
151: public String getString(String name, String defaultValue) {
152: if (result != null) {
153: return AttributeExtractor.getString(result, name,
154: defaultValue);
155: }
156: return defaultValue;
157:
158: }
159:
160: public int getInt(String name, int defaultValue) {
161: if (result != null) {
162: return AttributeExtractor
163: .getInt(result, name, defaultValue);
164: }
165: return defaultValue;
166: }
167:
168: public boolean getBoolean(String name, boolean defaultValue) {
169: if (result != null) {
170: return AttributeExtractor.getBoolean(result, name,
171: defaultValue);
172: }
173: return defaultValue;
174: }
175:
176: public List getStringList(String name) {
177: if (result != null) {
178: return AttributeExtractor.getStringList(result, name);
179: }
180: return new ArrayList();
181: }
182:
183: /*
184: * iDSAME migration - Mridul Any method to change the user's profile should
185: * be in this class right ? But if I create an instance , then it contacts
186: * the servlet and gets the latest attributes , which may not always be
187: * necessary in case I just want to set a few attributes. Hence , this
188: * static method.
189: */
190: private static final String SET_USER_ATTRIBUTES = "SET_USER_ATTRIBUTES";
191:
192: public static void setAttributes(String sessionId,
193: String attribute, Set value) throws SendRequestException,
194: GetResponseException {
195: // Unable to set attribute !
196: // , AMException{
197: // The following line may need some change to write it properly ??
198: // - Mridul
199: UserProfileGatewayCache.setAttribute(sessionId, attribute,
200: value);
201: /*
202: * Request request = new Request(sessionId, null, SET_USER_ATTRIBUTES ,
203: * attribute , new Object [] { value }); Response resp =
204: * SrapClient.execute(request); //if (resp == null || !resp.isNormal()){
205: * //throw new AMException("Unable to set the desired attributes"); //}
206: */
207: }
208: // EOC : iDSAME migration - Mridul
209: }
|