1 25 package org.ofbiz.base.util; 26 27 import java.security.Principal ; 28 import java.security.PrivateKey ; 29 import java.security.cert.X509Certificate ; 30 import java.net.Socket ; 31 32 import javax.net.ssl.X509KeyManager; 33 34 41 public class AliasKeyManager implements X509KeyManager { 42 43 protected X509KeyManager keyManager = null; 44 protected String alias = null; 45 46 protected AliasKeyManager() {} 47 48 public AliasKeyManager(X509KeyManager keyManager, String alias) { 49 this.keyManager = keyManager; 50 this.alias = alias; 51 } 52 53 public String chooseClientAlias(String [] keyType, Principal [] issuers, Socket socket) { 55 for (int i = 0; i < keyType.length; i++) { 56 String [] aliases = keyManager.getClientAliases(keyType[i], issuers); 57 if (aliases != null && aliases.length > 0) { 58 for (int x = 0; x < aliases.length; x++) { 59 if (alias.equals(aliases[i])) { 60 return alias; 61 } 62 } 63 } 64 } 65 return null; 66 } 67 68 public String chooseServerAlias(String keyType, Principal [] issuers, Socket socket) { 70 return keyManager.chooseServerAlias(keyType, issuers, socket); 71 } 72 73 public X509Certificate [] getCertificateChain(String alias) { 74 return keyManager.getCertificateChain(alias); 75 } 76 77 public String [] getClientAliases(String keyType, Principal [] issuers) { 78 return keyManager.getClientAliases(keyType, issuers); 79 } 80 81 public PrivateKey getPrivateKey(String alias) { 82 return keyManager.getPrivateKey(alias); 83 } 84 85 public String [] getServerAliases(String keyType, Principal [] issuers) { 86 return keyManager.getServerAliases(keyType, issuers); 87 } 88 } 89 | Popular Tags |