1 9 package org.jboss.net.axis.security; 10 11 import java.security.KeyStore ; 12 import java.security.cert.Certificate ; 13 import java.security.cert.X509Certificate ; 14 import java.util.Enumeration ; 15 import java.util.Properties ; 16 17 import javax.security.auth.x500.X500Principal ; 18 19 import org.apache.log4j.Logger; 20 import org.apache.ws.security.components.crypto.Merlin; 21 22 34 public class JBoss14Crypto extends Merlin implements JBossCrypto 35 { 36 private Logger log = Logger.getLogger(getClass()); 37 39 public JBoss14Crypto(KeyStore keystore) throws Exception 40 { 41 super(null); 42 43 this.properties = new Properties (); 45 46 if (keystore != null) 47 { 48 if (log.isDebugEnabled()) 49 log.debug("Creating new JBoss14Crypto using a " + keystore.getType() + " keystore."); 50 setKeyStore(keystore); 51 } 54 else 55 { 56 if (log.isDebugEnabled()) 57 log.debug("Creating new JBoss14Crypto WITHOUT a keystore."); 58 } 59 } 60 61 public String getAliasForX500Principal(X500Principal dn) throws Exception 62 { 63 String alias = null; 64 foundcert : for (Enumeration enu = keystore.aliases(); enu.hasMoreElements();) 65 { 66 String element = (String ) enu.nextElement(); 67 68 71 Certificate [] certs = keystore.getCertificateChain(element); 72 if (certs == null) 73 { 74 Certificate cert = keystore.getCertificate(element); 75 if (cert != null) 76 certs = new Certificate []{cert}; 77 } 78 if (certs != null) 79 { 80 for (int i = 0; i < certs.length; i++) 81 { 82 if (!(certs[i] instanceof X509Certificate )) 83 continue; 84 85 X509Certificate x509cert = (X509Certificate ) certs[i]; 86 if (dn.equals(x509cert.getSubjectX500Principal())) 87 { 88 alias = element; 89 break foundcert; 90 } 91 } 92 } 93 } 94 return alias; 95 } 96 } 97 | Popular Tags |