001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.desktop.context;
007:
008: import java.util.Set;
009: import java.util.Map;
010: import java.util.HashMap;
011: import java.util.Iterator;
012: import java.util.logging.Logger;
013: import java.util.logging.Level;
014: import java.net.URLEncoder;
015:
016: import com.sun.liberty.LibertyManager;
017: import com.iplanet.am.util.SystemProperties;
018:
019: import com.sun.portal.desktop.ROC;
020: import com.sun.portal.util.SSOUtil;
021: import com.sun.portal.log.common.PortalLogger;
022:
023: public class DSAMEServiceAppContext implements ServiceAppContext,
024: DSAMEConstants {
025: private static Logger logger = PortalLogger
026: .getLogger(DSAMEServiceAppContext.class);
027: protected static String serverProtocol = SystemProperties
028: .get(AM_SERVER_PROTOCOL);
029: protected static String serverPort = SystemProperties
030: .get(AM_SERVER_PORT);
031: protected static String serverHost = SystemProperties
032: .get(AM_SERVER_HOST);
033: protected static String serverURL = serverProtocol + "://"
034: + serverHost + ":" + serverPort;
035:
036: private static final String ROC_AUTHORIZED_AUTHLESS_UIDS = "authorizedAuthlessUIDs";
037:
038: private static DSAMEConnection dsameConn = null;
039:
040: private static DSAMEMultiPortalConstants dmpc = null;
041:
042: public DSAMEServiceAppContext() {
043: // nothing
044: }
045:
046: public synchronized void init(String portalId) {
047: DSAMEMultiPortalConstants.createInstance(portalId);
048: dmpc = DSAMEMultiPortalConstants.getInstance();
049: initAdminDSAMEConnection();
050: }
051:
052: protected DSAMEConnection getAdminDSAMEConnection() {
053: if (dsameConn == null) {
054: throw new ContextError(
055: "DSAMEServiceAppContext.getAdminDSAMEConnection(): not initialized");
056: }
057:
058: return dsameConn;
059: }
060:
061: private DSAMEConnection initAdminDSAMEConnection() {
062: if (dsameConn == null) {
063: // Create admin SSOToken in order to establish DSAME connection
064: dsameConn = new DSAMEConnection(SSOUtil.getAdminSSOToken());
065:
066: }
067:
068: return dsameConn;
069: }
070:
071: public String getDebugContextClassName() {
072:
073: return getAdminDSAMEConnection()
074: .getGlobalAttributeFromROC(dmpc.MP_SUN_DESKTOP_SERVICE,
075: ATTR_DEBUGCONTEXTCLASSNAME);
076: }
077:
078: public String getSessionAppContextClassName() {
079: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
080: dmpc.MP_SUN_DESKTOP_SERVICE,
081: ATTR_SESSIONAPPCONTEXTCLASSNAME);
082: }
083:
084: public String getAuthlessSessionAppContextClassName() {
085: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
086: dmpc.MP_SUN_DESKTOP_SERVICE,
087: ATTR_AUTHLESSSESSIONAPPCONTEXTCLASSNAME);
088: }
089:
090: public String getWSRPSessionAppContextClassName() {
091: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
092: dmpc.MP_SUN_DESKTOP_SERVICE,
093: ATTR_WSRPSESSIONAPPCONTEXTCLASSNAME);
094: }
095:
096: public String getDesktopContextClassName() {
097:
098: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
099: dmpc.MP_SUN_DESKTOP_SERVICE,
100: ATTR_DESKTOPCONTEXTCLASSNAME);
101: }
102:
103: public String getSessionContextClassName() {
104:
105: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
106: dmpc.MP_SUN_DESKTOP_SERVICE,
107: ATTR_SESSIONCONTEXTCLASSNAME);
108: }
109:
110: public String getServiceContextClassName() {
111:
112: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
113: dmpc.MP_SUN_DESKTOP_SERVICE,
114: ATTR_SERVICECONTEXTCLASSNAME);
115: }
116:
117: public String getClientContextClassName() {
118:
119: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
120: dmpc.MP_SUN_DESKTOP_SERVICE,
121: ATTR_CLIENTCONTEXTCLASSNAME);
122: }
123:
124: public String getTemplateContextClassName() {
125:
126: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
127: dmpc.MP_SUN_DESKTOP_SERVICE,
128: ATTR_TEMPLATECONTEXTCLASSNAME);
129: }
130:
131: public String getNoSessionURL() {
132: String noSessionURL = dsameConn.getGlobalAttributeFromROC(
133: DSAME_PLATFORM_SERVICE, ATTR_NOSESSIONURL);
134: if (noSessionURL != null) {
135: if (noSessionURL.indexOf("://") != -1) {
136: // If the URL in attribute is a complete URL
137: return noSessionURL;
138: } else {
139: // If URL in attribute is partial URL append to serverURL
140: StringBuffer fullURL = new StringBuffer(serverURL);
141: return fullURL.append(noSessionURL).toString();
142: }
143: }
144: // Logout URL in attribute is null not much can be done
145: return null;
146: }
147:
148: public String getLogoutURL() {
149: Boolean federationEnabled = Boolean.valueOf(dsameConn
150: .getGlobalAttributeFromROC(dmpc.MP_SUN_DESKTOP_SERVICE,
151: ATTR_ENABLE_FEDERATION));
152: StringBuffer logoutURLBuff = new StringBuffer(serverURL);
153:
154: if (federationEnabled.booleanValue()) {
155: String providerID = dsameConn.getGlobalAttributeFromROC(
156: dmpc.MP_SUN_DESKTOP_SERVICE,
157: ATTR_HOSTED_PROVIDER_ID);
158: String metaAlias = null;
159: if (providerID != null && providerID.length() != 0) {
160: try {
161: metaAlias = LibertyManager.getMetaAlias(providerID);
162: } catch (Exception e) {
163: logger.log(Level.INFO, "PSDT_CSPDC0034", e);
164: metaAlias = null;
165: //'misconfig' block will take care of this situation
166: }
167: }
168: if (providerID == null || providerID.length() == 0
169: || metaAlias == null || metaAlias.length() == 0) {
170: /* This is misconfiguration. So return the local logout url,
171: * because if liberty has been misconfigured, then it is
172: * unlikely that the user is liberty signed-on.
173: */
174: return dsameConn.getGlobalAttributeFromROC(
175: DSAME_PLATFORM_SERVICE, ATTR_LOGOUTURL);
176: }
177: logoutURLBuff.append(
178: SystemProperties.get(DEPLOYMENT_DESCRIPTOR_KEY))
179: .append("/").append(LIBERTY_LOGOUT_PAGE_NAME)
180: .append("?").append(
181: LibertyManager.getMetaAliasKey()).append(
182: "=").append(metaAlias);
183: return logoutURLBuff.toString();
184: } else {
185: String attrLogoutURL = dsameConn.getGlobalAttributeFromROC(
186: DSAME_PLATFORM_SERVICE, ATTR_LOGOUTURL);
187: if (attrLogoutURL != null) {
188: if (attrLogoutURL.indexOf("://") != -1) {
189: // If the URL in attribute is a complete URL
190: return attrLogoutURL;
191: } else {
192: // If URL in attribute is partial URL append to serverURL
193: return logoutURLBuff.append(attrLogoutURL)
194: .toString();
195: }
196: }
197: // Logout URL in attribute is null not much can be done
198: return null;
199: }
200: }
201:
202: public String getSessionReturnURLParamName() {
203: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
204: dmpc.MP_SUN_DESKTOP_SERVICE,
205: ATTR_SESSIONRETURNURLPARAMNAME);
206: }
207:
208: public Map getAuthorizedAuthlessUIDs() {
209: //
210: // here, we are using the ROC at two levels. the first
211: // level stored the Set uid-pw pairs, and the second
212: // level stores a map which is the first parsed into
213: // a map
214: //
215: Map authorized = (Map) ROC
216: .getObject(ROC_AUTHORIZED_AUTHLESS_UIDS);
217: if (authorized == null) {
218: Set uidPasswordPairs = getAdminDSAMEConnection()
219: .getGlobalAttributeMultiValueFromROC(
220: dmpc.MP_SUN_DESKTOP_SERVICE,
221: ATTR_AUTHORIZEDAUTHLESSUIDS);
222:
223: authorized = new HashMap();
224:
225: //Following for loop code has been changed to fix CR 6335164
226: for (Iterator i = uidPasswordPairs.iterator(); i.hasNext();) {
227: String pair = (String) i.next();
228: int sep = pair.indexOf('|');
229: if (sep != -1) {
230: authorized.put((pair.substring(0, sep))
231: .toLowerCase(), pair.substring(sep + 1));
232: } else {
233: authorized.put(pair.toLowerCase(), null);
234: }
235: }
236:
237: ROC.setObject(ROC_AUTHORIZED_AUTHLESS_UIDS, authorized);
238: }
239:
240: return authorized;
241: }
242:
243: public String getDefaultAuthlessUID() {
244: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
245: dmpc.MP_SUN_DESKTOP_SERVICE, ATTR_DEFAULTAUTHLESSUID);
246: }
247:
248: public String getAccessURL() {
249: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
250: dmpc.MP_SUN_DESKTOP_SERVICE, ATTR_ACCESS_URL);
251: }
252:
253: public long getReapInterval() {
254: long interval = Long.parseLong(getAdminDSAMEConnection()
255: .getGlobalAttributeFromROC(dmpc.MP_SUN_DESKTOP_SERVICE,
256: ATTR_REAP_INTERVAL));
257: return interval;
258: }
259:
260: public long getInactiveMax() {
261: long maxInactive = Long.parseLong(getAdminDSAMEConnection()
262: .getGlobalAttributeFromROC(dmpc.MP_SUN_DESKTOP_SERVICE,
263: ATTR_INACTIVE_MAX));
264: return maxInactive;
265: }
266:
267: public long getClientSessionReapInterval() {
268: long interval = Long.parseLong(getAdminDSAMEConnection()
269: .getGlobalAttributeFromROC(dmpc.MP_SUN_DESKTOP_SERVICE,
270: ATTR_CLIENT_SESSION_REAP_INTERVAL));
271: return interval;
272: }
273:
274: public long getClientSessionInactiveMax() {
275: long maxInactive = Long.parseLong(getAdminDSAMEConnection()
276: .getGlobalAttributeFromROC(dmpc.MP_SUN_DESKTOP_SERVICE,
277: ATTR_CLIENT_SESSION_INACTIVE_MAX));
278: return maxInactive;
279: }
280:
281: public long getClientSessionsMax() {
282: long sessionsMax = Long.parseLong(getAdminDSAMEConnection()
283: .getGlobalAttributeFromROC(dmpc.MP_SUN_DESKTOP_SERVICE,
284: ATTR_CLIENT_SESSIONS_MAX));
285: return sessionsMax;
286: }
287:
288: public boolean isAuthlessEnabled() {
289: Boolean authlessEnabled = Boolean
290: .valueOf(getAdminDSAMEConnection()
291: .getGlobalAttributeFromROC(
292: dmpc.MP_SUN_DESKTOP_SERVICE,
293: ATTR_ENABLE_AUTHLESS_DESKTOP));
294: return authlessEnabled.booleanValue();
295: }
296:
297: protected boolean isAuthlessEnabledForFederatedUsers() {
298: Boolean authlessDisabledForFederatedUsers = Boolean
299: .valueOf(getAdminDSAMEConnection()
300: .getGlobalAttributeFromROC(
301: dmpc.MP_SUN_DESKTOP_SERVICE,
302: ATTR_DISABLE_AUTHLESS_FOR_FEDERATED_USERS));
303: return !authlessDisabledForFederatedUsers.booleanValue();
304: }
305:
306: public boolean isFederationEnabled() {
307: Boolean federationEnabled = Boolean
308: .valueOf(getAdminDSAMEConnection()
309: .getGlobalAttributeFromROC(
310: dmpc.MP_SUN_DESKTOP_SERVICE,
311: ATTR_ENABLE_FEDERATION));
312: return federationEnabled.booleanValue();
313: }
314:
315: /**
316: * Forms and returns a preLogin URL. If liberty is misconfigured, then it
317: * returns null.
318: *
319: * Typically, preLogin will be formed in one of the 3 possible ways:
320: * 1. "http://host:port/amserver/preLogin?metaAliasKey=metaAlias&isPassive=true&gotoOnFedCookieNo=http://host:port/portal/dt?libertySSOFailed=true&goto=http://host:port/portal/dt"
321: * 2. "http://host:port/amserver/preLogin?metaAliasKey=metaAlias&isPassive=false&gotoOnFedCookieNo=http://host:port/portal/dt?libertySSOFailed=true&goto=http://host:port/portal/dt"
322: * 3. "http://host:port/amserver/preLogin?metaAliasKey=metaAlias&goto=http://host:port/portal/dt"
323: */
324: public String getPreLoginURL(String returnURL,
325: String libertySSOFailedParamName) {
326: StringBuffer preLoginURL = new StringBuffer(serverURL);
327: String providerID = getStringAttribute(ATTR_HOSTED_PROVIDER_ID);
328: String metaAlias = null;
329: if (providerID != null && providerID.length() != 0) {
330: try {
331: metaAlias = LibertyManager.getMetaAlias(providerID);
332: } catch (Exception e) {
333: logger.log(Level.INFO, "PSDT_CSPDC0034", e);
334: return null;
335: }
336: }
337: if (providerID == null || providerID.length() == 0
338: || metaAlias == null || metaAlias.length() == 0) {
339: //This is liberty misconfiguration, so return null
340: return null;
341: }
342:
343: String deployDescriptor = SystemProperties
344: .get(DEPLOYMENT_DESCRIPTOR_KEY);
345:
346: preLoginURL.append(deployDescriptor).append("/").append(
347: PRE_LOGIN_PAGE_NAME).append("?").append(
348: LibertyManager.getMetaAliasKey()).append("=").append(
349: metaAlias);
350:
351: if (isAuthlessEnabled()) {
352: if (isAuthlessEnabledForFederatedUsers()) {
353: preLoginURL.append("&").append(PASSIVE_IDP_QUERY_PARAM)
354: .append("=true");
355: } else {
356: preLoginURL.append("&").append(PASSIVE_IDP_QUERY_PARAM)
357: .append("=false");
358: }
359: preLoginURL.append("&").append(FED_COOKIE_NO_QUERY_PARAM)
360: .append("=");
361: StringBuffer onFedCookieNoURL = new StringBuffer(returnURL);
362: if (returnURL.indexOf('?') != -1) {
363: onFedCookieNoURL.append("&");
364: } else {
365: onFedCookieNoURL.append("?");
366: }
367: onFedCookieNoURL.append(libertySSOFailedParamName).append(
368: "=true");
369: preLoginURL.append(URLEncoder.encode(onFedCookieNoURL
370: .toString()));
371: }
372: preLoginURL.append("&goto=").append(
373: URLEncoder.encode(returnURL));
374:
375: return preLoginURL.toString();
376: }
377:
378: public String getStringAttribute(String name) {
379:
380: return getAdminDSAMEConnection().getGlobalAttributeFromROC(
381: dmpc.MP_SUN_DESKTOP_SERVICE, name);
382: }
383:
384: public void setStringAttribute(String name, String val) {
385: getAdminDSAMEConnection().setGlobalAttribute(
386: dmpc.MP_SUN_DESKTOP_SERVICE, name, val);
387: }
388: }
|