001: package com.sun.portal.proxylet.servlet;
002:
003: import com.iplanet.am.util.AMClientDetector;
004: import com.iplanet.am.util.SystemProperties;
005: import com.iplanet.services.cdm.Client;
006: import com.iplanet.services.cdm.ClientException;
007: import com.iplanet.sso.*;
008: import com.sun.portal.proxylet.util.ProxyletConstants;
009: import com.sun.identity.sm.ServiceManager;
010: import com.sun.identity.sm.ServiceSchema;
011: import com.sun.identity.sm.ServiceSchemaManager;
012: import com.sun.identity.sm.SMSException;
013:
014: import java.util.logging.Logger;
015: import java.util.*;
016: import java.net.*;
017: import javax.servlet.http.*;
018:
019: public class ClientInfo {
020: HttpServletRequest req;
021:
022: private com.sun.portal.proxylet.servlet.UserAttributes userAttrs = null;
023: private String HTMLcharsetname = null;
024: private String enc = null;
025: private String bindIP = null;
026: private String bindPort = null;
027: private String pacLocation = null;
028: private ResourceBundle appletBundle = null;
029: private SSOToken ssoToken = null;
030: private ServiceManager serviceManager;
031: private static Logger logger;
032:
033: public Map globalattrs_1;
034:
035: public static void setLogger(Logger l) {
036: logger = l;
037: }
038:
039: public String getPlatformLoginURL() {
040: return platformLoginURL;
041: }
042:
043: public int getSessionIdleTimeout() {
044: return sessionIdleTimeout;
045: }
046:
047: private String platformLoginURL = null;
048: private int sessionIdleTimeout;
049:
050: public ClientInfo(HttpServletRequest req) throws Exception {
051: this .req = req;
052: readUserPreferences();
053: }
054:
055: public SSOToken getSSOToken() {
056: return ssoToken;
057: }
058:
059: public void readUserPreferences() throws Exception {
060: logger.info("readUserPreferences function");
061: ssoToken = createSSOToken();
062: if (ssoToken == null) {
063: throw new SSOException("Can't get ssoToken");
064: }
065:
066: String ATTRIBUTE_PREFIX = "iplanet-am-platform-";
067: String SERVICE_NAME = "iPlanetAMPlatformService";
068:
069: serviceManager = new ServiceManager(ssoToken);
070:
071: Map globalattrs = getGlobalAttributes(SERVICE_NAME, ssoToken);
072:
073: // retrive platform config URL iplanet-am-platform-login-url
074: platformLoginURL = AttributeExtractor.getString(globalattrs,
075: ATTRIBUTE_PREFIX + "login-url", null);
076:
077: ATTRIBUTE_PREFIX = "iplanet-am-session-";
078: SERVICE_NAME = "iPlanetAMSessionService";
079: globalattrs_1 = getDynamicAttributes(SERVICE_NAME, ssoToken);
080:
081: // retrive session timeout iplanet-am-session-max-idle-time
082: sessionIdleTimeout = AttributeExtractor.getInt(globalattrs_1,
083: ATTRIBUTE_PREFIX + "max-idle-time", 0);
084:
085: String c_applet_res_bundle = "srapProxyletApplet";
086:
087: userAttrs = new com.sun.portal.proxylet.servlet.UserAttributes(
088: ssoToken, "iplanet-am-user-");
089: enc = ssoToken.getProperty("Locale");
090: appletBundle = ResourceBundle.getBundle(c_applet_res_bundle,
091: com.iplanet.am.util.Locale.getLocale(enc));
092:
093: HTMLcharsetname = findHTMLCharset();
094:
095: logger.info("User Attributes read");
096: com.sun.portal.proxylet.util.UserAttributes attrs = new com.sun.portal.proxylet.util.UserAttributes(
097: ssoToken, ProxyletConstants.PROXYLET_SERVICE_NAME,
098: ProxyletConstants.PROXYLET_POLICY);
099: if (attrs.isServiceAssigned() == false) {
100: logger.info("is service assigned false ");
101: throw new Exception("noPrivilege");
102: }
103: bindIP = attrs
104: .getString(ProxyletConstants.PROXYLET_CLIENT_BIND_IP);
105: bindPort = attrs
106: .getString(ProxyletConstants.PROXYLET_CLIENT_BIND_PORT);
107: pacLocation = attrs
108: .getString(ProxyletConstants.PROXYLET_PACFILE_LOCATION);
109: }
110:
111: public ResourceBundle getCustomizedLocale(String localefile) {
112: ResourceBundle appBundle = ResourceBundle.getBundle(localefile,
113: com.iplanet.am.util.Locale.getLocale(enc));
114: return appBundle;
115: }
116:
117: /*
118: * Obtains the global service attributes given a service name.
119: *
120: * If service name is null or zero length, then null is returned.
121: * In the event of an AMException, null is returned.
122: *
123: * @param szServiceName java.lang.String - name of the service
124: *
125: * @return java.util.Map - Global service attributes or null if an
126: * exception has occured
127: */
128: private Map getGlobalAttributes(String szServiceName, SSOToken token) {
129:
130: Map attrs = null;
131:
132: if ((szServiceName == null) || (szServiceName.length() == 0))
133: return null;
134:
135: try {
136: ServiceSchemaManager schemaMgr = new ServiceSchemaManager(
137: szServiceName, token);
138: ServiceSchema schema = schemaMgr.getGlobalSchema();
139: attrs = schema.getAttributeDefaults();
140: schema = null;
141: } catch (SMSException smse) {
142:
143: } catch (SSOException ssoe) {
144:
145: }
146: return attrs;
147: }
148:
149: private Map getDynamicAttributes(String szServiceName,
150: SSOToken token) {
151:
152: Map attrs = null;
153:
154: if ((szServiceName == null) || (szServiceName.length() == 0))
155: return null;
156:
157: try {
158: ServiceSchemaManager schemaMgr = new ServiceSchemaManager(
159: szServiceName, token);
160: ServiceSchema schema = schemaMgr.getDynamicSchema();
161: attrs = schema.getAttributeDefaults();
162: schema = null;
163: } catch (SMSException smse) {
164:
165: } catch (SSOException ssoe) {
166:
167: }
168: return attrs;
169: }
170:
171: /**
172: * Update session to indicate presence of proxylet
173: * This will be used by the gateway to determine whether to rewrite or not
174: */
175:
176: public void updateSession(String key, String value) {
177: //ssoToken.setProperty(key, value);
178: }
179:
180: public String getBindIP() {
181: return bindIP;
182: }
183:
184: public String getBindPort() {
185: return bindPort;
186: }
187:
188: public String getPacLocation() {
189: return pacLocation;
190: }
191:
192: public String getHTMLcharsetname() {
193: return HTMLcharsetname;
194: }
195:
196: public ResourceBundle getAppletBundle() {
197: return appletBundle;
198: }
199:
200: public String getLocale() {
201: return enc;
202: }
203:
204: public String findHTMLCharset() {
205: AMClientDetector amCD = new AMClientDetector();
206: String clientType = amCD.getClientType(req);
207: String HTMLcharset = null;
208:
209: try {
210: Client clientObj = Client.getInstance(clientType);
211: HTMLcharset = clientObj
212: .getCharset(com.iplanet.am.util.Locale
213: .getLocale(getLocale()));
214: } catch (ClientException ce) {
215: HTMLcharset = "ISO-8859-1";
216:
217: }
218: return HTMLcharset;
219: }
220:
221: private SSOToken createSSOToken() {
222: SSOToken token = null;
223: String cookieName = SystemProperties.get(
224: "com.iplanet.am.cookie.name", "iPlanetDirectoryPro");
225: Cookie[] cks = req.getCookies();
226:
227: if (cks != null) {
228: for (int i = 0; i < cks.length; i++) {
229: String cName = cks[i].getName();
230: if (cName != null && cName.equals(cookieName)) {
231: String sessID = cks[i].getValue();
232: try {
233: token = SSOTokenManager.getInstance()
234: .createSSOToken(sessID);
235: } catch (SSOException ssoe) {
236: try {
237: token = SSOTokenManager.getInstance()
238: .createSSOToken(
239: URLDecoder.decode(sessID));
240: } catch (SSOException ssoe2) {
241: }
242: }
243: break;
244: }
245: }
246: }
247: return token;
248: }
249: }
|