1 23 24 package org.continuent.sequoia.common.net; 25 26 import java.io.File ; 27 import java.io.Serializable ; 28 29 import org.continuent.sequoia.common.xml.ControllerXmlTags; 30 31 37 public class SSLConfiguration implements Serializable 38 { 39 private static final long serialVersionUID = -7030030045041996566L; 40 41 42 private File keyStore; 43 44 private String keyStorePassword; 45 46 private String keyStoreKeyPassword; 47 48 50 51 private boolean isClientAuthenticationRequired = false; 52 53 54 private File trustStore; 55 56 private String trustStorePassword; 57 58 63 public boolean isClientAuthenticationRequired() 64 { 65 return isClientAuthenticationRequired; 66 } 67 68 74 public void setClientAuthenticationRequired( 75 boolean isClientAuthenticationRequired) 76 { 77 this.isClientAuthenticationRequired = isClientAuthenticationRequired; 78 } 79 80 85 public File getKeyStore() 86 { 87 return keyStore; 88 } 89 90 95 public void setKeyStore(File keyStore) 96 { 97 this.keyStore = keyStore; 98 } 99 100 105 public String getKeyStoreKeyPassword() 106 { 107 if (keyStoreKeyPassword != null) 108 return keyStoreKeyPassword; 109 return getKeyStorePassword(); 110 } 111 112 117 public void setKeyStoreKeyPassword(String keyStoreKeyPassword) 118 { 119 this.keyStoreKeyPassword = keyStoreKeyPassword; 120 } 121 122 127 public String getKeyStorePassword() 128 { 129 return keyStorePassword; 130 } 131 132 137 public void setKeyStorePassword(String keyStorePassword) 138 { 139 this.keyStorePassword = keyStorePassword; 140 } 141 142 147 public File getTrustStore() 148 { 149 if (trustStore != null) 150 return trustStore; 151 152 return getKeyStore(); 153 } 154 155 160 public void setTrustStore(File trustStore) 161 { 162 this.trustStore = trustStore; 163 } 164 165 170 public String getTrustStorePassword() 171 { 172 if (trustStorePassword != null) 173 return trustStorePassword; 174 175 return getKeyStorePassword(); 176 } 177 178 183 public void setTrustStorePassword(String trustStorePassword) 184 { 185 this.trustStorePassword = trustStorePassword; 186 } 187 188 194 public static SSLConfiguration getDefaultConfig() 195 { 196 SSLConfiguration config = new SSLConfiguration(); 197 String keyStoreProperty = System.getProperty("javax.net.ssl.keyStore"); 198 if (keyStoreProperty == null) 199 throw new RuntimeException ( 200 "javax.net.ssl.keyStore has not been properly defined"); 201 config.keyStore = new File (keyStoreProperty); 202 203 config.keyStorePassword = System 204 .getProperty("javax.net.ssl.keyStorePassword"); 205 if (config.keyStorePassword == null) 206 throw new RuntimeException ( 207 "javax.net.ssl.keyStorePassword has not been properly defined"); 208 209 config.keyStoreKeyPassword = System 210 .getProperty("javax.net.ssl.keyStoreKeyPassword"); 211 if (config.keyStoreKeyPassword == null) 212 config.keyStoreKeyPassword = config.keyStorePassword; 213 214 String trustStoreProperty = System.getProperty("javax.net.ssl.trustStore"); 215 if (trustStoreProperty == null) 216 trustStoreProperty = keyStoreProperty; 217 config.trustStore = new File (trustStoreProperty); 218 219 config.trustStorePassword = System 220 .getProperty("javax.net.ssl.trustStorePassword"); 221 if (config.trustStorePassword == null) 222 config.trustStorePassword = config.keyStorePassword; 223 return config; 224 } 225 226 231 public String getXml() 232 { 233 StringBuffer info = new StringBuffer (); 234 info.append("<" + ControllerXmlTags.ELT_SSL + " " 235 + ControllerXmlTags.ATT_SSL_KEYSTORE + "=\"" + getKeyStore() + "\" " 236 + ControllerXmlTags.ATT_SSL_KEYSTORE_PASSWORD + "=\"" 237 + getKeyStorePassword() + "\" " 238 + ControllerXmlTags.ATT_SSL_KEYSTORE_KEYPASSWORD + "=\"" 239 + getKeyStoreKeyPassword() + "\" " 240 + ControllerXmlTags.ATT_SSL_NEED_CLIENT_AUTH + "=\"" 241 + isClientAuthenticationRequired() + "\" " 242 + ControllerXmlTags.ATT_SSL_TRUSTSTORE + "=\"" + getTrustStore() 243 + "\" " + ControllerXmlTags.ATT_SSL_TRUSTSTORE_PASSWORD + "=\"" 244 + getTrustStorePassword() + "\"/>"); 245 return info.toString(); 246 } 247 248 } 249 | Popular Tags |