001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.monitoring.security;
006:
007: import com.sun.portal.monitoring.utilities.PropertyHelper;
008:
009: import java.net.InetAddress;
010: import java.net.UnknownHostException;
011:
012: public class SecurityContext {
013: public SecurityContext(PropertyHelper propertyHelper) {
014: this .propertyHelper = propertyHelper;
015: if (propertyHelper == null) {
016: this .propertyHelper = new PropertyHelper(null);
017: }
018: }
019:
020: private PropertyHelper propertyHelper;
021:
022: public PropertyHelper getPropertyHelper() {
023: return propertyHelper;
024: }
025:
026: private String getProperty(String propertySuffix,
027: String defaultValue) {
028: return propertyHelper.getProperty(getClass().getName(),
029: propertySuffix, defaultValue);
030: }
031:
032: private String getHostName() throws UnknownHostException {
033: InetAddress inetAddress = InetAddress.getByName(null);
034: return inetAddress.getCanonicalHostName();
035: }
036:
037: public CertificateContext getCertificateContext()
038: throws UnknownHostException {
039: CertificateContext context = new CertificateContext();
040:
041: context.setAlias(getProperty(PROPERTY_SUFFIX_CERTIFICATE_ALIAS,
042: CERTIFICATE_ALIAS));
043: context.setKeyAlg(getProperty(
044: PROPERTY_SUFFIX_CERTIFICATE_KEY_ALGORITHM,
045: CERTIFICATE_KEY_ALGORITHM));
046: context.setCn(getProperty(PROPERTY_SUFFIX_CERTIFICATE_CN,
047: getHostName()));
048: context.setOu(getProperty(PROPERTY_SUFFIX_CERTIFICATE_OU,
049: CERTIFICATE_OU));
050: context.setO(getProperty(PROPERTY_SUFFIX_CERTIFICATE_O,
051: CERTIFICATE_O));
052: context.setC(getProperty(PROPERTY_SUFFIX_CERTIFICATE_C,
053: CERTIFICATE_C));
054: context.setValidity(getProperty(
055: PROPERTY_SUFFIX_CERTIFICATE_VALIDITY,
056: CERTIFICATE_VALIDITY));
057:
058: return context;
059: }
060:
061: public KeyStoreContext getKeyStoreContext() {
062: KeyStoreContext context = new KeyStoreContext();
063:
064: context.setKeyStoreDirectory(getProperty(
065: PROPERTY_SUFFIX_DIRECTORY, DIRECTORY));
066: context.setKeyStoreFileName(getProperty(
067: PROPERTY_SUFFIX_KEY_STORE_FILE_NAME,
068: KEY_STORE_FILE_NAME));
069: context.setKeyStorePasswordFileName(getProperty(
070: PROPERTY_SUFFIX_KEY_STORE_PASSWORD_FILE_NAME,
071: KEY_STORE_PASSWORD_FILE_NAME));
072: context.setKeyStorePassword(getProperty(
073: PROPERTY_SUFFIX_KEY_STORE_PASSWORD, KEY_STORE_PASSWORD)
074: .toCharArray());
075: context.setExportImportFileName(getProperty(
076: PROPERTY_SUFFIX_EXPORT_IMPORT_FILE_NAME,
077: EXPORT_IMPORT_FILE_NAME));
078:
079: return context;
080: }
081:
082: public KeyStoreContext getTrustStoreContext() {
083: KeyStoreContext context = new KeyStoreContext();
084:
085: context.setKeyStoreDirectory(getProperty(
086: PROPERTY_SUFFIX_DIRECTORY, DIRECTORY));
087: context.setKeyStoreFileName(getProperty(
088: PROPERTY_SUFFIX_TRUST_STORE_FILE_NAME,
089: TRUST_STORE_FILE_NAME));
090: context.setKeyStorePasswordFileName(getProperty(
091: PROPERTY_SUFFIX_TRUST_STORE_PASSWORD_FILE_NAME,
092: TRUST_STORE_PASSWORD_FILE_NAME));
093: context.setKeyStorePassword(getProperty(
094: PROPERTY_SUFFIX_TRUST_STORE_PASSWORD,
095: TRUST_STORE_PASSWORD).toCharArray());
096: context.setExportImportFileName(getProperty(
097: PROPERTY_SUFFIX_EXPORT_IMPORT_FILE_NAME,
098: EXPORT_IMPORT_FILE_NAME));
099:
100: return context;
101: }
102:
103: public static String PROPERTY_SUFFIX_CERTIFICATE_ALIAS = "certificate.alias";
104: public static String CERTIFICATE_ALIAS = "PortalServerCertificate";
105:
106: public static String PROPERTY_SUFFIX_CERTIFICATE_KEY_ALGORITHM = "certificate.key.algorithm";
107: public static String CERTIFICATE_KEY_ALGORITHM = "RSA";
108:
109: public static String PROPERTY_SUFFIX_CERTIFICATE_CN = "certificate.cn";
110:
111: public static String PROPERTY_SUFFIX_CERTIFICATE_OU = "certificate.ou";
112: public static String CERTIFICATE_OU = "PortalServer";
113:
114: public static String PROPERTY_SUFFIX_CERTIFICATE_O = "certificate.o";
115: public static String CERTIFICATE_O = "PortalServer";
116:
117: public static String PROPERTY_SUFFIX_CERTIFICATE_C = "certificate.c";
118: public static String CERTIFICATE_C = "US";
119:
120: public static String PROPERTY_SUFFIX_CERTIFICATE_VALIDITY = "certificate.validity";
121: public static String CERTIFICATE_VALIDITY = "180";
122:
123: public static String PROPERTY_SUFFIX_DIRECTORY = "directory";
124: public static String DIRECTORY = ".";
125:
126: public static String PROPERTY_SUFFIX_KEY_STORE_FILE_NAME = "key.store.file.name";
127: public static String KEY_STORE_FILE_NAME = "KeyStore";
128:
129: public static String PROPERTY_SUFFIX_KEY_STORE_PASSWORD_FILE_NAME = "key.store.getPassword.file.name";
130: public static String KEY_STORE_PASSWORD_FILE_NAME = ".KeyStore.Password";
131:
132: public static String PROPERTY_SUFFIX_KEY_STORE_PASSWORD = "key.store.getPassword";
133: public static String KEY_STORE_PASSWORD = "DemoPassword";
134:
135: public static String PROPERTY_SUFFIX_TRUST_STORE_FILE_NAME = "trust.store.file.name";
136: public static String TRUST_STORE_FILE_NAME = "TrustStore";
137:
138: public static String PROPERTY_SUFFIX_TRUST_STORE_PASSWORD_FILE_NAME = "trust.store.getPassword.file.name";
139: public static String TRUST_STORE_PASSWORD_FILE_NAME = ".TrustStore.Password";
140:
141: public static String PROPERTY_SUFFIX_TRUST_STORE_PASSWORD = "trust.store.getPassword";
142: public static String TRUST_STORE_PASSWORD = "DemoPassword";
143:
144: public static String PROPERTY_SUFFIX_EXPORT_IMPORT_FILE_NAME = "export.import.file.name";
145: public static String EXPORT_IMPORT_FILE_NAME = "PortalServer.Certificate";
146: }
|