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;
006:
007: import com.sun.portal.monitoring.security.sasl.SaslCallbackHandler;
008: import com.sun.portal.monitoring.security.sasl.SaslContext;
009: import com.sun.portal.monitoring.security.ssl.Ssl;
010: import com.sun.portal.monitoring.security.ssl.SslContext;
011: import com.sun.portal.monitoring.security.ssl.SslException;
012: import com.sun.portal.monitoring.utilities.PropertyHelper;
013:
014: import javax.net.ssl.SSLSocketFactory;
015: import javax.security.auth.callback.CallbackHandler;
016:
017: public class ConnectorContext {
018: public ConnectorContext(PropertyHelper propertyHelper) {
019: this .propertyHelper = propertyHelper;
020: if (propertyHelper == null) {
021: this .propertyHelper = new PropertyHelper(null);
022: }
023: }
024:
025: private PropertyHelper propertyHelper;
026:
027: public String getProtocol() {
028: return protocol;
029: }
030:
031: public void setProtocol(String protocol) {
032: this .protocol = protocol;
033: }
034:
035: public Boolean getSaslDisable() {
036: return saslDisable;
037: }
038:
039: public void setSaslDisable(Boolean saslDisable) {
040: this .saslDisable = saslDisable;
041: }
042:
043: public String getProfiles() {
044: return profiles;
045: }
046:
047: public void setProfiles(String profiles) {
048: this .profiles = profiles;
049: }
050:
051: public CallbackHandler getSaslCallbackHandler() {
052: return saslCallbackHandler;
053: }
054:
055: public void setSaslCallbackHandler(
056: CallbackHandler saslCallbackHandler) {
057: this .saslCallbackHandler = saslCallbackHandler;
058: }
059:
060: public Boolean getSslDisable() {
061: return sslDisable;
062: }
063:
064: public void setSslDisable(Boolean sslDisable) {
065: this .sslDisable = sslDisable;
066: }
067:
068: public SSLSocketFactory getSSLSocketFactory() {
069: return sslSocketFactory;
070: }
071:
072: public void setSSLSocketFactory(SSLSocketFactory sslSocketFactory) {
073: this .sslSocketFactory = sslSocketFactory;
074: }
075:
076: public String getCiphers() {
077: return ciphers;
078: }
079:
080: public void setCiphers(String ciphers) {
081: this .ciphers = ciphers;
082: }
083:
084: public String getAdditionalPropertiesDirectory() {
085: return additionalPropertiesDirectory;
086: }
087:
088: public void setAdditionalPropertiesDirectory(
089: String additionalPropertiesDirectory) {
090: this .additionalPropertiesDirectory = additionalPropertiesDirectory;
091: }
092:
093: public String getAdditionalPropertiesFileName() {
094: return additionalPropertiesFileName;
095: }
096:
097: public void setAdditionalPropertiesFileName(
098: String additionalPropertiesFileName) {
099: this .additionalPropertiesFileName = additionalPropertiesFileName;
100: }
101:
102: private String getProperty(String propertySuffix,
103: String defaultValue) {
104: return propertyHelper.getProperty(getClass().getName(),
105: propertySuffix, defaultValue);
106: }
107:
108: private Boolean getBooleanProperty(String propertySuffix) {
109: return propertyHelper.getBooleanProperty(getClass().getName(),
110: propertySuffix);
111: }
112:
113: public void gearUp(SaslContext saslContext, SslContext sslContext)
114: throws MonitoringException {
115: setProtocol(getProperty(PROPERTY_SUFFIX_PROTOCOL, PROTOCOL));
116:
117: setSaslDisable(getBooleanProperty(PROPERTY_SUFFIX_SASL_DISABLE));
118: if (!getSaslDisable().booleanValue()) {
119: setProfiles(System.getProperty("jmx.remote.profiles", null));
120: if (getProfiles() == null) {
121: setProfiles("TLS SASL/"
122: + saslContext.getMechanismName());
123:
124: setSaslCallbackHandler(new SaslCallbackHandler(
125: saslContext));
126: }
127: }
128:
129: setSslDisable(getBooleanProperty(PROPERTY_SUFFIX_SSL_DISABLE));
130: if (!getSslDisable().booleanValue()) {
131: Ssl ssl = new Ssl();
132: ssl.setSslContext(sslContext);
133: try {
134: ssl.gearUp();
135: } catch (SslException ssle) {
136: throw new MonitoringException(ssle);
137: }
138: setSSLSocketFactory(ssl.getSSLSocketFactory());
139:
140: String[] aCiphers = sslContext.getCiphers();
141: String result = "";
142: if (aCiphers != null) {
143: for (int i = 0; i < aCiphers.length; i++) {
144: result += " " + aCiphers[i];
145: }
146: }
147: setCiphers(result);
148: }
149:
150: setAdditionalPropertiesDirectory(getProperty(
151: PROPERTY_SUFFIX_ADDITIONAL_PROPERTIES_DIRECTORY,
152: ADDITIONAL_PROPERTIES_DIRECTORY));
153: setAdditionalPropertiesFileName(getProperty(
154: PROPERTY_SUFFIX_ADDITIONAL_PROPERTIES_FILE_NAME,
155: ADDITIONAL_PROPERTIES_FILE_NAME));
156: }
157:
158: public static String PROPERTY_SUFFIX_PROTOCOL = "protocol";
159: public static String PROTOCOL = "jmxmp";
160: private String protocol;
161:
162: public static String PROPERTY_SUFFIX_SASL_DISABLE = "sasl.disable";
163: private Boolean saslDisable;
164:
165: private String profiles;
166: private CallbackHandler saslCallbackHandler;
167:
168: public static String PROPERTY_SUFFIX_SSL_DISABLE = "ssl.disable";
169: private Boolean sslDisable;
170:
171: private SSLSocketFactory sslSocketFactory;
172: private String ciphers;
173:
174: public static String PROPERTY_SUFFIX_ADDITIONAL_PROPERTIES_DIRECTORY = "additional.properties.directory";
175: public static String ADDITIONAL_PROPERTIES_DIRECTORY = ".";
176: private String additionalPropertiesDirectory;
177:
178: public static String PROPERTY_SUFFIX_ADDITIONAL_PROPERTIES_FILE_NAME = "additional.properties.file.name";
179: public static String ADDITIONAL_PROPERTIES_FILE_NAME = ".unknown";
180: private String additionalPropertiesFileName;
181: }
|