1 16 17 18 package org.apache.xmlrpc.secure; 19 20 import java.security.KeyStore ; 21 import java.security.Provider ; 22 import java.security.Security ; 23 24 26 public class SecurityTool 27 implements SecurityConstants 28 { 29 33 protected static String securityProviderClass; 34 35 40 private static String securityProtocol; 41 42 45 private static String keyStorePassword; 46 47 52 private static String keyStoreType; 53 54 58 private static String keyStore; 59 60 63 private static String trustStorePassword; 64 65 70 private static String trustStoreType; 71 72 76 private static String trustStore; 77 78 84 private static String keyManagerType; 85 86 91 private static String protocolHandlerPackages; 92 93 public static void setup() 94 throws Exception 95 { 96 101 Security.addProvider((Provider )Class.forName( 102 SecurityTool.getSecurityProviderClass()).newInstance()); 103 104 108 System.setProperty(PROTOCOL_HANDLER_PACKAGES, 109 SecurityTool.getProtocolHandlerPackages()); 110 111 113 System.setProperty(KEY_STORE_TYPE, 114 SecurityTool.getKeyStoreType()); 115 116 System.setProperty(KEY_STORE, 117 SecurityTool.getKeyStore()); 118 119 System.setProperty(KEY_STORE_PASSWORD, 120 SecurityTool.getKeyStorePassword()); 121 122 124 System.setProperty(TRUST_STORE_TYPE, 125 SecurityTool.getTrustStoreType()); 126 127 System.setProperty(TRUST_STORE, 128 SecurityTool.getTrustStore()); 129 130 System.setProperty(TRUST_STORE_PASSWORD, 131 SecurityTool.getTrustStorePassword()); 132 } 133 134 139 public static void setProtocolHandlerPackages(String x) 140 { 141 protocolHandlerPackages = x; 142 } 143 144 149 public static String getProtocolHandlerPackages() 150 { 151 if (System.getProperty(PROTOCOL_HANDLER_PACKAGES) != null) 152 { 153 return System.getProperty(PROTOCOL_HANDLER_PACKAGES); 154 } 155 if (protocolHandlerPackages == null) 156 { 157 return DEFAULT_PROTOCOL_HANDLER_PACKAGES; 158 } 159 else 160 { 161 return protocolHandlerPackages; 162 } 163 } 164 165 170 public static void setSecurityProviderClass(String x) 171 { 172 securityProviderClass = x; 173 } 174 175 180 public static String getSecurityProviderClass() 181 { 182 if (System.getProperty(SECURITY_PROVIDER_CLASS) != null) 183 { 184 return System.getProperty(SECURITY_PROVIDER_CLASS); 185 } 186 if (securityProviderClass == null) 187 { 188 return DEFAULT_SECURITY_PROVIDER_CLASS; 189 } 190 else 191 { 192 return securityProviderClass; 193 } 194 } 195 196 201 public static void setKeyStorePassword(String x) 202 { 203 keyStorePassword = x; 204 } 205 206 211 public static void setSecurityProtocol(String x) 212 { 213 securityProtocol = x; 214 } 215 216 221 public static String getSecurityProtocol() 222 { 223 if (System.getProperty(SECURITY_PROTOCOL) != null) 224 { 225 return System.getProperty(SECURITY_PROTOCOL); 226 } 227 if (securityProtocol== null) 228 { 229 return DEFAULT_SECURITY_PROTOCOL; 230 } 231 else 232 { 233 return securityProtocol; 234 } 235 } 236 237 242 public static void setKeyStore(String x) 243 { 244 keyStore = x; 245 } 246 247 252 public static String getKeyStore() 253 { 254 if (System.getProperty(KEY_STORE) != null) 255 { 256 return System.getProperty(KEY_STORE); 257 } 258 if (keyStore == null) 259 { 260 return DEFAULT_KEY_STORE; 261 } 262 else 263 { 264 return keyStore; 265 } 266 } 267 268 273 public static void setKeyStoreType(String x) 274 { 275 keyStoreType = x; 276 } 277 278 283 public static String getKeyStoreType() 284 { 285 if (System.getProperty(KEY_STORE_TYPE) != null) 286 { 287 return System.getProperty(KEY_STORE_TYPE); 288 } 289 if (keyStoreType == null) 290 { 291 296 return KeyStore.getDefaultType(); 297 } 298 else 299 { 300 return keyStoreType; 301 } 302 } 303 304 309 public static String getKeyStorePassword() 310 { 311 if (System.getProperty(KEY_STORE_PASSWORD) != null) 312 { 313 return System.getProperty(KEY_STORE_PASSWORD); 314 } 315 if (keyStorePassword == null) 316 { 317 return DEFAULT_KEY_STORE_PASSWORD; 318 } 319 else 320 { 321 return keyStorePassword; 322 } 323 } 324 325 330 public static void setTrustStore(String x) 331 { 332 trustStore = x; 333 } 334 335 340 public static String getTrustStore() 341 { 342 if (System.getProperty(TRUST_STORE) != null) 343 { 344 return System.getProperty(TRUST_STORE); 345 } 346 if (trustStore == null) 347 { 348 return DEFAULT_TRUST_STORE; 349 } 350 else 351 { 352 return trustStore; 353 } 354 } 355 356 361 public static void setTrustStoreType(String x) 362 { 363 trustStoreType = x; 364 } 365 366 371 public static String getTrustStoreType() 372 { 373 if (System.getProperty(TRUST_STORE_TYPE) != null) 374 { 375 return System.getProperty(TRUST_STORE_TYPE); 376 } 377 if (trustStoreType == null) 378 { 379 384 return KeyStore.getDefaultType(); 385 } 386 else 387 { 388 return trustStoreType; 389 } 390 } 391 392 397 public static void setTrustStorePassword(String x) 398 { 399 trustStorePassword = x; 400 } 401 402 407 public static String getTrustStorePassword() 408 { 409 if (System.getProperty(TRUST_STORE_PASSWORD) != null) 410 { 411 return System.getProperty(TRUST_STORE_PASSWORD); 412 } 413 if (trustStorePassword == null) 414 { 415 return DEFAULT_TRUST_STORE_PASSWORD; 416 } 417 else 418 { 419 return trustStorePassword; 420 } 421 } 422 423 428 public static void setKeyManagerType(String x) 429 { 430 keyManagerType = x; 431 } 432 433 438 public static String getKeyManagerType() 439 { 440 if (System.getProperty(KEY_MANAGER_TYPE) != null) 441 { 442 return System.getProperty(KEY_MANAGER_TYPE); 443 } 444 if (keyManagerType == null) 445 { 446 return DEFAULT_KEY_MANAGER_TYPE; 447 } 448 else 449 { 450 return keyManagerType; 451 } 452 } 453 } 454 | Popular Tags |