001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006: * Contact: sequoia@continuent.org
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: * Initial developer(s): Marc Wick.
021: * Contributor(s): ______________________.
022: */package org.continuent.sequoia.common.net;
023:
024: import java.io.File;
025: import java.io.Serializable;
026:
027: /**
028: * This class defines a SSLConfiguration
029: *
030: * @author <a href="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
031: * @version 1.0
032: */
033: public class SSLConfiguration implements Serializable {
034: private static final long serialVersionUID = -7030030045041996566L;
035:
036: /** kestore file */
037: private File keyStore;
038: /** keystore password */
039: private String keyStorePassword;
040: /** key password */
041: private String keyStoreKeyPassword;
042:
043: // TODO : provide support for naming aliases
044:
045: /** need client authentication */
046: private boolean isClientAuthenticationRequired = false;
047:
048: /** truststore file */
049: private File trustStore;
050: /** truststore password */
051: private String trustStorePassword;
052:
053: /**
054: * Returns the isClientAuthenticationRequired value.
055: *
056: * @return Returns the isClientAuthenticationRequired.
057: */
058: public boolean isClientAuthenticationRequired() {
059: return isClientAuthenticationRequired;
060: }
061:
062: /**
063: * Sets the isClientAuthenticationRequired value.
064: *
065: * @param isClientAuthenticationRequired The isClientAuthenticationRequired to
066: * set.
067: */
068: public void setClientAuthenticationRequired(
069: boolean isClientAuthenticationRequired) {
070: this .isClientAuthenticationRequired = isClientAuthenticationRequired;
071: }
072:
073: /**
074: * Returns the keyStore value.
075: *
076: * @return Returns the keyStore.
077: */
078: public File getKeyStore() {
079: return keyStore;
080: }
081:
082: /**
083: * Sets the keyStore value.
084: *
085: * @param keyStore The keyStore to set.
086: */
087: public void setKeyStore(File keyStore) {
088: this .keyStore = keyStore;
089: }
090:
091: /**
092: * Returns the keyStoreKeyPassword value.
093: *
094: * @return Returns the keyStoreKeyPassword.
095: */
096: public String getKeyStoreKeyPassword() {
097: if (keyStoreKeyPassword != null)
098: return keyStoreKeyPassword;
099: return getKeyStorePassword();
100: }
101:
102: /**
103: * Sets the keyStoreKeyPassword value.
104: *
105: * @param keyStoreKeyPassword The keyStoreKeyPassword to set.
106: */
107: public void setKeyStoreKeyPassword(String keyStoreKeyPassword) {
108: this .keyStoreKeyPassword = keyStoreKeyPassword;
109: }
110:
111: /**
112: * Returns the keyStorePassword value.
113: *
114: * @return Returns the keyStorePassword.
115: */
116: public String getKeyStorePassword() {
117: return keyStorePassword;
118: }
119:
120: /**
121: * Sets the keyStorePassword value.
122: *
123: * @param keyStorePassword The keyStorePassword to set.
124: */
125: public void setKeyStorePassword(String keyStorePassword) {
126: this .keyStorePassword = keyStorePassword;
127: }
128:
129: /**
130: * Returns the trustStore value.
131: *
132: * @return Returns the trustStore.
133: */
134: public File getTrustStore() {
135: if (trustStore != null)
136: return trustStore;
137:
138: return getKeyStore();
139: }
140:
141: /**
142: * Sets the trustStore value.
143: *
144: * @param trustStore The trustStore to set.
145: */
146: public void setTrustStore(File trustStore) {
147: this .trustStore = trustStore;
148: }
149:
150: /**
151: * Returns the trustStorePassword value.
152: *
153: * @return Returns the trustStorePassword.
154: */
155: public String getTrustStorePassword() {
156: if (trustStorePassword != null)
157: return trustStorePassword;
158:
159: return getKeyStorePassword();
160: }
161:
162: /**
163: * Sets the trustStorePassword value.
164: *
165: * @param trustStorePassword The trustStorePassword to set.
166: */
167: public void setTrustStorePassword(String trustStorePassword) {
168: this .trustStorePassword = trustStorePassword;
169: }
170:
171: /**
172: * create a SSLConfiguration with the java default behaviour (using System
173: * properties)
174: *
175: * @return config
176: */
177: public static SSLConfiguration getDefaultConfig() {
178: SSLConfiguration config = new SSLConfiguration();
179: String keyStoreProperty = System
180: .getProperty("javax.net.ssl.keyStore");
181: if (keyStoreProperty == null)
182: throw new RuntimeException(
183: "javax.net.ssl.keyStore has not been properly defined");
184: config.keyStore = new File(keyStoreProperty);
185:
186: config.keyStorePassword = System
187: .getProperty("javax.net.ssl.keyStorePassword");
188: if (config.keyStorePassword == null)
189: throw new RuntimeException(
190: "javax.net.ssl.keyStorePassword has not been properly defined");
191:
192: config.keyStoreKeyPassword = System
193: .getProperty("javax.net.ssl.keyStoreKeyPassword");
194: if (config.keyStoreKeyPassword == null)
195: config.keyStoreKeyPassword = config.keyStorePassword;
196:
197: String trustStoreProperty = System
198: .getProperty("javax.net.ssl.trustStore");
199: if (trustStoreProperty == null)
200: trustStoreProperty = keyStoreProperty;
201: config.trustStore = new File(trustStoreProperty);
202:
203: config.trustStorePassword = System
204: .getProperty("javax.net.ssl.trustStorePassword");
205: if (config.trustStorePassword == null)
206: config.trustStorePassword = config.keyStorePassword;
207: return config;
208: }
209:
210: }
|