| 1 |
package org.globus.gsi.provider; |
| 2 |
|
| 3 |
import org.globus.gsi.stores.PEMKeyStore; |
| 4 |
|
| 5 |
import java.security.KeyStore; |
| 6 |
import java.security.KeyStore.LoadStoreParameter; |
| 7 |
import java.security.KeyStore.ProtectionParameter; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
public class KeyStoreParametersFactory { |
| 12 |
|
| 13 |
public static KeyStore.LoadStoreParameter createCertKeyParameters( |
| 14 |
String certLocations, String keyLocation) { |
| 15 |
return new CertKeyParameters(certLocations, keyLocation); |
| 16 |
} |
| 17 |
|
| 18 |
public static KeyStore.LoadStoreParameter createProxyCertParameters( |
| 19 |
String proxyCertLocation) { |
| 20 |
return new ProxyCertParameters(proxyCertLocation); |
| 21 |
} |
| 22 |
|
| 23 |
public static LoadStoreParameter createTrustStoreParameters( |
| 24 |
String trustedCertificateDirectories) { |
| 25 |
return new TrustStoreParameters(trustedCertificateDirectories, null); |
| 26 |
} |
| 27 |
|
| 28 |
public static LoadStoreParameter createTrustStoreParameters( |
| 29 |
String trustedCertificateDirectories, String defaultDirectory) { |
| 30 |
return new TrustStoreParameters(trustedCertificateDirectories, |
| 31 |
defaultDirectory); |
| 32 |
} |
| 33 |
|
| 34 |
private static class TrustStoreParameters implements FileStoreParameters { |
| 35 |
private String trustedCertificateDirectories; |
| 36 |
private String defaultCertificateDirectory; |
| 37 |
|
| 38 |
public TrustStoreParameters(String trustedCertificateDirectories, |
| 39 |
String defaultCertificateDirectory) { |
| 40 |
super(); |
| 41 |
this.trustedCertificateDirectories = trustedCertificateDirectories; |
| 42 |
this.defaultCertificateDirectory = defaultCertificateDirectory; |
| 43 |
} |
| 44 |
|
| 45 |
public Object getProperty(String key) { |
| 46 |
if (key.equals(PEMKeyStore.DIRECTORY_LIST_KEY)) { |
| 47 |
return trustedCertificateDirectories; |
| 48 |
} else if (key.equals(PEMKeyStore.DEFAULT_DIRECTORY_KEY)) { |
| 49 |
return defaultCertificateDirectory; |
| 50 |
} |
| 51 |
return null; |
| 52 |
} |
| 53 |
|
| 54 |
public ProtectionParameter getProtectionParameter() { |
| 55 |
// TODO Auto-generated method stub |
| 56 |
return null; |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
private static class ProxyCertParameters implements FileStoreParameters { |
| 62 |
|
| 63 |
private String proxyLocation; |
| 64 |
|
| 65 |
public ProxyCertParameters(String proxyLocation) { |
| 66 |
super(); |
| 67 |
this.proxyLocation = proxyLocation; |
| 68 |
} |
| 69 |
|
| 70 |
public Object getProperty(String key) { |
| 71 |
if (key.equals(PEMKeyStore.PROXY_FILENAME)) { |
| 72 |
return this.proxyLocation; |
| 73 |
} else { |
| 74 |
return null; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
public ProtectionParameter getProtectionParameter() { |
| 79 |
// TODO Auto-generated method stub |
| 80 |
return null; |
| 81 |
} |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
private static class CertKeyParameters implements FileStoreParameters { |
| 86 |
private String certLocations; |
| 87 |
private String keyLocation; |
| 88 |
private ProtectionParameter param; |
| 89 |
|
| 90 |
public CertKeyParameters(String certLocations, String keyLocation) { |
| 91 |
super(); |
| 92 |
this.certLocations = certLocations; |
| 93 |
this.keyLocation = keyLocation; |
| 94 |
} |
| 95 |
|
| 96 |
public ProtectionParameter getProtectionParameter() { |
| 97 |
return param; |
| 98 |
} |
| 99 |
|
| 100 |
public Object getProperty(String key) { |
| 101 |
if (key.equals(PEMKeyStore.KEY_FILENAME)) { |
| 102 |
return this.keyLocation; |
| 103 |
} else if (key.equals(PEMKeyStore.CERTIFICATE_FILENAME)) { |
| 104 |
return this.certLocations; |
| 105 |
} else { |
| 106 |
return null; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
public static interface FileStoreParameters extends LoadStoreParameter { |
| 113 |
public Object getProperty(String key); |
| 114 |
} |
| 115 |
} |