001: /**
002: * $Id: PSConfigContextImpl.java,v 1.35 2007/01/26 03:47:09 portalbld Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.common.context;
014:
015: import java.io.File;
016: import java.io.FileNotFoundException;
017: import java.io.IOException;
018: import java.util.Properties;
019:
020: import sun.misc.BASE64Decoder;
021:
022: import com.sun.portal.util.ResourceLoader;
023: import com.sun.portal.util.Platform;
024:
025: public class PSConfigContextImpl implements PSConfigContext {
026:
027: protected static final String FS = Platform.fs;
028: protected String domainDir = null;
029: protected Properties isConfig = null;
030: protected Properties psConfig = null;
031: protected Properties domainConfig = null;
032: protected Properties portalVersion = null;
033: protected BASE64Decoder decoder = new BASE64Decoder();
034:
035: public PSConfigContextImpl(String domainID)
036: throws FileNotFoundException, IOException {
037:
038: ResourceLoader rl = ResourceLoader.getInstance(System
039: .getProperties());
040: psConfig = rl.getProperties(PS_CONFIG_FILE);
041:
042: if (psConfig != null) {
043: domainDir = getPSConfigDir() + FS + DOMAINS + FS + domainID;
044: String file = domainDir + FS + DOMAIN_CONFIG_FILE;
045: domainConfig = rl.getProperties(file);
046: String amconf = getUserAuthConfigFile();
047: isConfig = rl.getProperties(amconf);
048:
049: String portalVersionFile = getPSBaseDir() + FS + "lib" + FS
050: + PS_VERSION_FILE;
051: portalVersion = rl.getProperties(portalVersionFile);
052: }
053: }
054:
055: public String getPathSeparator() {
056: return Platform.pathSep;
057: }
058:
059: /**
060: * IMPORTANT: If this function messes up, PS/AM seperated configurations
061: * can get messed up. So change with care.
062: * @return
063: */
064: public String getAMVersion() {
065: //Note: The JES3 Linux AS install return different string
066: String version = isConfig.getProperty(AM_VERSION).trim();
067: String AMVer6Regex = "\\s*6.*"; //first non-whitespace character should be 6
068: String AMVer7Regex = "\\s*7.*"; //first non-whitespace character should be 7
069: if (version.matches(AMVer7Regex))
070: return "7";
071: else if (version.matches(AMVer6Regex))
072: return "6";
073: else
074: return "invalid";
075: }
076:
077: public String getJavaHome() {
078: return psConfig.getProperty(JAVA_HOME);
079: }
080:
081: public String getPSBaseDir() {
082: return psConfig.getProperty(PS_BASE_DIR);
083: }
084:
085: public String getPSDataDir() {
086: return psConfig.getProperty(PS_DATA_DIR);
087: }
088:
089: public String getPSConfigDir() {
090: return psConfig.getProperty(PS_CONFIG_DIR);
091:
092: }
093:
094: public String getISBaseDir() {
095: return psConfig.getProperty(IS_BASE_DIR);
096: }
097:
098: public String getISConfigDir() {
099: return psConfig.getProperty(IS_CONFIG_DIR);
100: }
101:
102: public String getISDataDir() {
103: return psConfig.getProperty(IS_DATA_DIR);
104: }
105:
106: public String getCacaoBaseDir() {
107: return psConfig.getProperty(CACAO_BASE_DIR);
108: }
109:
110: public String getCacaoConfigDir() {
111: return psConfig.getProperty(CACAO_CONFIG_DIR);
112: }
113:
114: public String getSharedLibsDir() {
115: return psConfig.getProperty(SHARED_LIB_DIR);
116: }
117:
118: public String getPrivateSharedLibsDir() {
119: return psConfig.getProperty(PRIVATE_SHARE_LIB_DIR);
120: }
121:
122: public String getJSSNSSLibDir() {
123: return psConfig.getProperty(JSS_NSS_LIB_DIR);
124: }
125:
126: public String getJSSJARDir() {
127: return psConfig.getProperty(JSS_JAR_DIR);
128: }
129:
130: public String getJDMKLibDir() {
131: return psConfig.getProperty(JDMK_LIB_DIR);
132: }
133:
134: public String getDerbyLibDir() {
135: return psConfig.getProperty(DERBY_LIB_DIR);
136: }
137:
138: public String getAntHomeDir() {
139: return psConfig.getProperty(ANT_HOME_DIR);
140: }
141:
142: public String getAntLibDir() {
143: return psConfig.getProperty(ANT_LIB_DIR);
144: }
145:
146: public String getRegistryLibDir() {
147: return psConfig.getProperty(REGISTRY_LIB_DIR);
148: }
149:
150: public String getJESMFLibDir() {
151: return psConfig.getProperty(JESMF_LIB_DIR);
152: }
153:
154: public String getJESMFBinDir() {
155: return psConfig.getProperty(JESMF_BIN_DIR);
156: }
157:
158: public String getJAXLibDir() {
159: return psConfig.getProperty(JAX_LIB_DIR);
160: }
161:
162: public String getOrgNamingAttribute() {
163: return psConfig.getProperty(ORG_NAMING_ATTR);
164: }
165:
166: public String getRoleNamingAttribute() {
167: return psConfig.getProperty(ROLE_NAMING_ATTR);
168: }
169:
170: public String getUserNamingAttribute() {
171: return psConfig.getProperty(USER_NAMING_ATTR);
172: }
173:
174: public String getPeopleContainerNamingAttribute() {
175: return psConfig.getProperty(PEOPLE_CONTAINER_NAMING_ATTR);
176: }
177:
178: public String getUserAuthConfigFile() {
179: return domainConfig.getProperty(USER_AUTH_CONFIG_FILE);
180: }
181:
182: public String getUserDataStoreManager() {
183: return domainConfig.getProperty(USER_STORE_MANAGER);
184: }
185:
186: public String getUserDataStoreManagerCredentials() {
187: String cred = domainConfig
188: .getProperty(USER_STORE_MANAGER_CREDENTIALS);
189:
190: try {
191: return new String(decoder.decodeBuffer(cred), "8859_1");
192: } catch (Exception e) {
193: return cred;
194: }
195: }
196:
197: public String getDomainDataClass() {
198: return domainConfig.getProperty(DOMAIN_DATA_CLASS);
199: }
200:
201: public String getDomainDataHost() {
202: return domainConfig.getProperty(DOMAIN_DATA_HOST);
203: }
204:
205: public String getDomainDataPort() {
206: return domainConfig.getProperty(DOMAIN_DATA_PORT);
207: }
208:
209: public boolean isDomainDataSecure() {
210: String isSecure = domainConfig.getProperty(DOMAIN_DATA_SECURE);
211:
212: if ((isSecure == null) || (isSecure.trim().length() == 0)) {
213: isSecure = isConfig.getProperty(AM_LDAP_SERVER_SECURE);
214: }
215:
216: return Boolean.valueOf(isSecure).booleanValue();
217: }
218:
219: public String getDomainDataRootSuffix() {
220: return domainConfig.getProperty(DOMAIN_DATA_ROOTSUFFIX);
221: }
222:
223: public String getDomainDataPrincipal() {
224: return domainConfig.getProperty(DOMAIN_DATA_PRINCIPAL);
225: }
226:
227: public String getDomainDataCredentials() {
228: String cred = domainConfig.getProperty(DOMAIN_DATA_CREDENTIALS);
229:
230: try {
231: return new String(decoder.decodeBuffer(cred), "8859_1");
232: } catch (Exception e) {
233: return cred;
234: }
235: }
236:
237: public String getSessionServiceProtocol() {
238: return isConfig.getProperty(AM_SERVER_PROTOCOL);
239: }
240:
241: public String getSessionServiceHost() {
242: return isConfig.getProperty(AM_SERVER_HOST);
243: }
244:
245: public String getSessionServicePort() {
246: return isConfig.getProperty(AM_SERVER_PORT);
247: }
248:
249: public String getDefaultOrganization() {
250: String amDefaultOrg = isConfig.getProperty(AM_DEFAULTORG);
251: String amRootSuffix = getRootSuffix();
252:
253: if (amDefaultOrg.equalsIgnoreCase(amRootSuffix)) {
254: return amDefaultOrg;
255: }
256: return amDefaultOrg + "," + amRootSuffix;
257: }
258:
259: public String getRootSuffix() {
260: return isConfig.getProperty(AM_ROOTSUFFIX);
261: }
262:
263: public String getDefaultPeopleDN() {
264: return getPeopleContainerNamingAttribute() + "=People,"
265: + getDefaultOrganization();
266: }
267:
268: public String getDomainComponent() {
269: return isConfig.getProperty(AM_DOMAINCOMPONENT);
270: }
271:
272: public String getEncryptionKey() {
273: return isConfig.getProperty(AM_ENCRYPTION_PWD);
274: }
275:
276: public String getDirectoryServerHost() {
277: return isConfig.getProperty(AM_LDAP_SERVER_HOST);
278: }
279:
280: public String getDirectoryServerPort() {
281: return isConfig.getProperty(AM_LDAP_SERVER_PORT);
282: }
283:
284: public String getAdminUserDN() {
285: return isConfig.getProperty(AM_ADMIN_USER_DN);
286: }
287:
288: public String getAMSpecialUsersDN() {
289: String userDNs = isConfig.getProperty(AM_SPECIAL_USER_DN);
290: int index = userDNs.indexOf("|");
291: return (index < 0) ? userDNs : userDNs.substring(0, index);
292: }
293:
294: public String getAMLDAPUserDN() {
295: return psConfig.getProperty(AM_LDAP_USER_DN).replaceAll("\\=",
296: "=");
297: }
298:
299: public String getISConsoleURI() {
300: return isConfig.getProperty(AM_CONSOLE_URI);
301: }
302:
303: public String getISServerURI() {
304: return isConfig.getProperty(AM_SERVER_URI);
305: }
306:
307: public String getAttributeHandlerName(String component) {
308: return domainConfig.getProperty(ATTRIBUTE_HANDLER_PREFIX
309: + component);
310: }
311:
312: public String getPortalProductName() {
313: return portalVersion.getProperty(PS_PROD_NAME);
314: }
315:
316: public String getPortalVersion() {
317: return portalVersion.getProperty(PS_PROD_VERSION);
318: }
319: }
|