KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > common > net > SSLConfiguration


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Marc Wick.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.common.net;
26
27 import java.io.File JavaDoc;
28 import java.io.Serializable JavaDoc;
29
30 /**
31  * This class defines a SSLConfiguration
32  *
33  * @author <a HREF="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
34  * @version 1.0
35  */

36 public class SSLConfiguration implements Serializable JavaDoc
37 {
38   private static final long serialVersionUID = -7030030045041996566L;
39
40   /** kestore file */
41   private File JavaDoc keyStore;
42   /** keystore password */
43   private String JavaDoc keyStorePassword;
44   /** key password */
45   private String JavaDoc keyStoreKeyPassword;
46
47   // TODO : provide support for naming aliases
48

49   /** need client authentication */
50   private boolean isClientAuthenticationRequired = false;
51
52   /** truststore file */
53   private File JavaDoc trustStore;
54   /** truststore password */
55   private String JavaDoc trustStorePassword;
56
57   /**
58    * Returns the isClientAuthenticationRequired value.
59    *
60    * @return Returns the isClientAuthenticationRequired.
61    */

62   public boolean isClientAuthenticationRequired()
63   {
64     return isClientAuthenticationRequired;
65   }
66
67   /**
68    * Sets the isClientAuthenticationRequired value.
69    *
70    * @param isClientAuthenticationRequired The isClientAuthenticationRequired to
71    * set.
72    */

73   public void setClientAuthenticationRequired(
74       boolean isClientAuthenticationRequired)
75   {
76     this.isClientAuthenticationRequired = isClientAuthenticationRequired;
77   }
78
79   /**
80    * Returns the keyStore value.
81    *
82    * @return Returns the keyStore.
83    */

84   public File JavaDoc getKeyStore()
85   {
86     return keyStore;
87   }
88
89   /**
90    * Sets the keyStore value.
91    *
92    * @param keyStore The keyStore to set.
93    */

94   public void setKeyStore(File JavaDoc keyStore)
95   {
96     this.keyStore = keyStore;
97   }
98
99   /**
100    * Returns the keyStoreKeyPassword value.
101    *
102    * @return Returns the keyStoreKeyPassword.
103    */

104   public String JavaDoc getKeyStoreKeyPassword()
105   {
106     if (keyStoreKeyPassword != null)
107       return keyStoreKeyPassword;
108     return getKeyStorePassword();
109   }
110
111   /**
112    * Sets the keyStoreKeyPassword value.
113    *
114    * @param keyStoreKeyPassword The keyStoreKeyPassword to set.
115    */

116   public void setKeyStoreKeyPassword(String JavaDoc keyStoreKeyPassword)
117   {
118     this.keyStoreKeyPassword = keyStoreKeyPassword;
119   }
120
121   /**
122    * Returns the keyStorePassword value.
123    *
124    * @return Returns the keyStorePassword.
125    */

126   public String JavaDoc getKeyStorePassword()
127   {
128     return keyStorePassword;
129   }
130
131   /**
132    * Sets the keyStorePassword value.
133    *
134    * @param keyStorePassword The keyStorePassword to set.
135    */

136   public void setKeyStorePassword(String JavaDoc keyStorePassword)
137   {
138     this.keyStorePassword = keyStorePassword;
139   }
140
141   /**
142    * Returns the trustStore value.
143    *
144    * @return Returns the trustStore.
145    */

146   public File JavaDoc getTrustStore()
147   {
148     if (trustStore != null)
149       return trustStore;
150
151     return getKeyStore();
152   }
153
154   /**
155    * Sets the trustStore value.
156    *
157    * @param trustStore The trustStore to set.
158    */

159   public void setTrustStore(File JavaDoc trustStore)
160   {
161     this.trustStore = trustStore;
162   }
163
164   /**
165    * Returns the trustStorePassword value.
166    *
167    * @return Returns the trustStorePassword.
168    */

169   public String JavaDoc getTrustStorePassword()
170   {
171     if (trustStorePassword != null)
172       return trustStorePassword;
173
174     return getKeyStorePassword();
175   }
176
177   /**
178    * Sets the trustStorePassword value.
179    *
180    * @param trustStorePassword The trustStorePassword to set.
181    */

182   public void setTrustStorePassword(String JavaDoc trustStorePassword)
183   {
184     this.trustStorePassword = trustStorePassword;
185   }
186
187   /**
188    * create a SSLConfiguration with the java default behaviour (using System
189    * properties)
190    *
191    * @return config
192    */

193   public static SSLConfiguration getDefaultConfig()
194   {
195     SSLConfiguration config = new SSLConfiguration();
196     config.keyStore = new File JavaDoc(System.getProperty("javax.net.ssl.keyStore"));
197     config.keyStorePassword = System
198         .getProperty("javax.net.ssl.keyStorePassword");
199     config.keyStoreKeyPassword = System
200         .getProperty("javax.net.ssl.keyStorePassword");
201     config.trustStore = new File JavaDoc(System.getProperty("javax.net.ssl.trustStore"));
202     config.trustStorePassword = System
203         .getProperty("javax.net.ssl.trustStorePassword");
204     return config;
205   }
206
207 }
208
Popular Tags