001: /*
002: * Copyright 2003 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.sra.admin.context;
007:
008: import java.io.FileOutputStream;
009: import java.io.IOException;
010: import java.util.Properties;
011:
012: public abstract class SRAPropertyContextImpl implements
013: SRAPropertyContext {
014:
015: protected Properties p = null;
016:
017: public SRAPropertyContextImpl(Properties p) {
018: this .p = p;
019: }
020:
021: public static final String FORWARD_SLASH = "/";
022: public static final char FORWARD_SLASH_CHAR = '/';
023: public static final String BACK_SLASH = "\\";
024: public static final char BACK_SLASH_CHAR = '\\';
025:
026: protected String replaceBackSlash(String pathName) {
027: String result = null;
028: result = pathName.replace(BACK_SLASH_CHAR, FORWARD_SLASH_CHAR);
029: return result;
030: }
031:
032: //private static final String SELF_SIGNED_CERTIFICATE_NICK_NAME = "server-cert";
033:
034: public final Boolean doCreateSelfSignedCertificate() {
035: if (p.getProperty(DO_CREATE_SELF_SIGNED_CERTIFICATE) != null) {
036: return (p.getProperty(DO_CREATE_SELF_SIGNED_CERTIFICATE)
037: .equalsIgnoreCase("y")
038: || p.getProperty(DO_CREATE_SELF_SIGNED_CERTIFICATE)
039: .equalsIgnoreCase("yes") || p.getProperty(
040: DO_CREATE_SELF_SIGNED_CERTIFICATE)
041: .equalsIgnoreCase("true")) ? Boolean.TRUE
042: : Boolean.FALSE;
043: } else {
044: return Boolean.FALSE;
045: }
046: }
047:
048: public final String getLogUserPassword() {
049: return System.getProperty(LOG_USER_PASSWORD, EMPTY_STRING);
050: }
051:
052: public final String getCertificateDatabasePassword() {
053: return System.getProperty(CERTIFICATE_DATABASE_PASSWORD,
054: EMPTY_STRING);
055: }
056:
057: public final String getSelfSignedCertificateInformation() {
058: return p.getProperty(SELF_SIGNED_CERTIFICATE_INFORMATION);
059: }
060:
061: public final String getPortalProtocol() {
062: return p.getProperty(PORTAL_PROTOCOL);
063: }
064:
065: public final String getPortalHost() {
066: return p.getProperty(PORTAL_HOST);
067: }
068:
069: public final String getPortalPort() {
070: return p.getProperty(PORTAL_PORT);
071: }
072:
073: public final String getPortalDeployURI() {
074: return p.getProperty(PORTAL_DEPLOY_URI);
075: }
076:
077: public final Boolean doCreateNewIdentitySDKInstance() {
078: return (p.getProperty(DO_CREATE_NEW_IDENTITY_SDK_INSTANCE)
079: .equalsIgnoreCase("y")
080: || p.getProperty(DO_CREATE_NEW_IDENTITY_SDK_INSTANCE)
081: .equalsIgnoreCase("yes") || p.getProperty(
082: DO_CREATE_NEW_IDENTITY_SDK_INSTANCE).equalsIgnoreCase(
083: "true")) ? Boolean.TRUE : Boolean.FALSE;
084: }
085:
086: public final Boolean write(String configurationFile,
087: String propertiesHeader) {
088: Boolean result = Boolean.TRUE;
089:
090: FileOutputStream fos = null;
091: try {
092: fos = new FileOutputStream(configurationFile);
093: p.setProperty(LOG_USER_PASSWORD, EMPTY_STRING);
094: p.setProperty(CERTIFICATE_DATABASE_PASSWORD, EMPTY_STRING);
095: //making empty entries to the above keys before we store it to file system.
096: p.store(fos, propertiesHeader);
097: //storing the original values back to the keys in the properties object.
098: p.setProperty(LOG_USER_PASSWORD, System.getProperty(
099: LOG_USER_PASSWORD, EMPTY_STRING));
100: p.setProperty(CERTIFICATE_DATABASE_PASSWORD, System
101: .getProperty(CERTIFICATE_DATABASE_PASSWORD,
102: EMPTY_STRING));
103: } catch (IOException ioe) {
104: ioe.printStackTrace();
105: result = Boolean.FALSE;
106: } finally {
107: if (fos != null) {
108: try {
109: fos.close();
110: } catch (IOException ioe) {
111: // IGNORE: We might be ok. This is just non-server utility.
112: }
113: }
114: }
115:
116: return result;
117: }
118: }
|