001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.desktop.context;
006:
007: import java.util.Properties;
008: import java.util.Map;
009: import java.util.HashMap;
010:
011: import java.io.File;
012: import java.io.IOException;
013: import java.io.FileInputStream;
014: import java.io.FileOutputStream;
015:
016: /**
017: * This class implements the DesktopContext interface using Java
018: * properties files.
019: */
020:
021: public class PropertiesServiceAppContext implements ServiceAppContext {
022: protected Properties properties = null;
023: protected String filename = null;
024:
025: protected static final String NOSESSIONURL_KEY = "noSessionURL";
026: protected static final String SESSIONRETURNURLPARAMNAME_KEY = "sessionReturnURLParamName";
027: protected static final String DEBUGCONTEXTCLASSNAME_KEY = "debugContextClassName";
028: protected static final String SESSIONAPPCONTEXTCLASSNAME_KEY = "sessionAppContextClassName";
029: protected static final String AUTHLESSSESSIONAPPCONTEXTCLASSNAME_KEY = "sessionAppContextClassName";
030: protected static final String DESKTOPCONTEXTCLASSNAME_KEY = "desktopContextClassName";
031: protected static final String SERVICECONTEXTCLASSNAME_KEY = "serviceContextClassName";
032: protected static final String SESSIONCONTEXTCLASSNAME_KEY = "sessionContextClassName";
033: protected static final String CLIENTCONTEXTCLASSNAME_KEY = "clientContextClassName";
034: protected static final String TEMPLATECONTEXTCLASSNAME_KEY = "templateContextClassName";
035: protected static final String INACTIVE_MAX_KEY = "inactiveMax";
036: protected static final String REAP_INTERVAL_KEY = "reapInterval";
037: protected static final String CLIENT_SESSION_INACTIVE_MAX_KEY = "clientSessionInactiveMax";
038: protected static final String CLIENT_SESSION_REAP_INTERVAL_KEY = "clientSessionReapInterval";
039: protected static final String CLIENT_SESSIONS_MAX_KEY = "clientSessionsMax";
040: protected static final String ENABLE_AUTHLESS_DESKTOP_KEY = "enableAuthlessDesktop";
041: protected static final String ENABLE_FEDERATION_KEY = "enableFederation";
042: protected static final String PRELOGIN_URL_KEY = "preLoginURL";
043: protected static final String ACCESS_URL_KEY = "accessURL";
044:
045: protected static final String DEFAULT_FILENAME = "/etc/opt/SUNWportal/service-context.properties";
046:
047: public PropertiesServiceAppContext() {
048: this (DEFAULT_FILENAME);
049: }
050:
051: public PropertiesServiceAppContext(String filename) {
052: properties = new Properties();
053: this .filename = filename;
054:
055: FileInputStream fis = null;
056: try {
057: fis = new FileInputStream(new File(filename));
058: properties.load(fis);
059: } catch (IOException ioe) {
060: throw new ContextError(
061: "PropertiesServiceAppContext.PropertiesServiceAppContext(): ",
062: ioe);
063: }
064: }
065:
066: public void init(String portalId) {
067: // nothing
068: }
069:
070: public String getDebugContextClassName() {
071: return properties.getProperty(DEBUGCONTEXTCLASSNAME_KEY);
072: }
073:
074: public String getSessionAppContextClassName() {
075: return properties.getProperty(SESSIONAPPCONTEXTCLASSNAME_KEY);
076: }
077:
078: public String getAuthlessSessionAppContextClassName() {
079: return properties
080: .getProperty(AUTHLESSSESSIONAPPCONTEXTCLASSNAME_KEY);
081: }
082:
083: public String getWSRPSessionAppContextClassName() {
084: return properties
085: .getProperty(AUTHLESSSESSIONAPPCONTEXTCLASSNAME_KEY);
086: }
087:
088: public String getDesktopContextClassName() {
089: return properties.getProperty(DESKTOPCONTEXTCLASSNAME_KEY);
090: }
091:
092: public String getSessionContextClassName() {
093: return properties.getProperty(SESSIONCONTEXTCLASSNAME_KEY);
094: }
095:
096: public String getServiceContextClassName() {
097: return properties.getProperty(SERVICECONTEXTCLASSNAME_KEY);
098: }
099:
100: public String getClientContextClassName() {
101: return properties.getProperty(CLIENTCONTEXTCLASSNAME_KEY);
102: }
103:
104: public String getTemplateContextClassName() {
105: return properties.getProperty(TEMPLATECONTEXTCLASSNAME_KEY);
106: }
107:
108: public String getNoSessionURL() {
109: return properties.getProperty(NOSESSIONURL_KEY);
110: }
111:
112: public String getLogoutURL() {
113: return properties.getProperty(NOSESSIONURL_KEY);
114: }
115:
116: public String getAccessURL() {
117: return properties.getProperty(ACCESS_URL_KEY);
118: }
119:
120: public String getSessionReturnURLParamName() {
121: return properties.getProperty(SESSIONRETURNURLPARAMNAME_KEY);
122: }
123:
124: public Map getAuthorizedAuthlessUIDs() {
125: HashMap somemap = new HashMap();
126: return somemap;
127: }
128:
129: public String getDefaultAuthlessUID() {
130: return "userid";
131: }
132:
133: public long getReapInterval() {
134: long interval = Long.parseLong(properties
135: .getProperty(REAP_INTERVAL_KEY));
136: return interval;
137: }
138:
139: public long getInactiveMax() {
140: long maxInactive = Long.parseLong(properties
141: .getProperty(INACTIVE_MAX_KEY));
142: return maxInactive;
143: }
144:
145: public long getClientSessionReapInterval() {
146: long interval = Long.parseLong(properties
147: .getProperty(CLIENT_SESSION_REAP_INTERVAL_KEY));
148: return interval;
149: }
150:
151: public long getClientSessionInactiveMax() {
152: long maxInactive = Long.parseLong(properties
153: .getProperty(CLIENT_SESSION_INACTIVE_MAX_KEY));
154: return maxInactive;
155: }
156:
157: public long getClientSessionsMax() {
158: long maxSessions = Long.parseLong(properties
159: .getProperty(CLIENT_SESSIONS_MAX_KEY));
160: return maxSessions;
161: }
162:
163: public boolean isAuthlessEnabled() {
164: Boolean authlessEnabled = Boolean.valueOf(properties
165: .getProperty(ENABLE_AUTHLESS_DESKTOP_KEY));
166: return authlessEnabled.booleanValue();
167: }
168:
169: public boolean isFederationEnabled() {
170: Boolean federationEnabled = Boolean.valueOf(properties
171: .getProperty(ENABLE_FEDERATION_KEY));
172: return federationEnabled.booleanValue();
173: }
174:
175: /* This ServiceAppContext has no Liberty implementation.
176: * Thus, isFederationEnabled should have already returned false and then
177: * this method should never get called.
178: * If atall it is called then return whatever value is there in the key.
179: * (Value might have been hardcoded in the properties file)
180: */
181: public String getPreLoginURL(String returnURL,
182: String libertySSOFailedParamName) {
183: return properties.getProperty(PRELOGIN_URL_KEY);
184: }
185:
186: public String getStringAttribute(String name) {
187: return properties.getProperty(name);
188: }
189:
190: public void setStringAttribute(String name, String val) {
191: properties.setProperty(name, val);
192:
193: FileOutputStream fos = null;
194: try {
195: fos = new FileOutputStream(new File(filename));
196: properties.store(fos, "Last updated at: ");
197: } catch (IOException ioe) {
198: throw new ContextError(
199: "PropertiesContext.storeAttribute()", ioe);
200: }
201: }
202: }
|