1 9 package org.jboss.net.axis.security; 10 11 import java.lang.reflect.Constructor ; 12 import java.security.KeyStore ; 13 14 import org.apache.log4j.Logger; 15 import org.apache.ws.security.components.crypto.CryptoFactory; 16 17 28 public class JBossCryptoFactory extends CryptoFactory 29 { 30 private static Logger log = Logger.getLogger(JBossCryptoFactory.class); 31 32 39 public static JBossCrypto getInstance(String cryptoClassName, KeyStore keystore) 40 { 41 if (log.isDebugEnabled()) 42 log.debug("Attempting to get a Crypto instance of type " + cryptoClassName); 43 return loadClass(cryptoClassName, keystore); 44 } 45 46 53 private static JBossCrypto loadClass(String cryptoClassName, KeyStore keystore) 54 { 55 Class cryptogenClass = null; 56 JBossCrypto crypto = null; 57 try 58 { 59 cryptogenClass = java.lang.Class.forName(cryptoClassName); 61 } 62 catch (ClassNotFoundException e) 63 { 64 throw new RuntimeException (cryptoClassName + " Not Found"); 65 } 66 67 log.info("Using Crypto Engine [" + cryptoClassName + "]"); 68 69 try 70 { 71 Class [] classes = new Class []{KeyStore .class}; 72 Constructor c = cryptogenClass.getConstructor(classes); 73 crypto = (JBossCrypto) c.newInstance(new Object []{keystore}); 74 return crypto; 75 } 76 catch (java.lang.Exception e) 77 { 78 log.debug(e); 79 log.debug(cryptoClassName + " cannot create instance with KeyStore constructor"); 80 } 81 82 try 83 { 84 crypto = (JBossCrypto) cryptogenClass.newInstance(); 86 return crypto; 87 } 88 catch (java.lang.Exception e) 89 { 90 throw new RuntimeException (cryptoClassName + " cannot create instance"); 91 } 92 93 } 94 } 95 | Popular Tags |