1 22 package org.jboss.net.ssl; 23 24 import java.io.IOException ; 25 import java.security.KeyStore ; 26 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 import javax.net.ssl.TrustManager; 30 import javax.net.ssl.KeyManager; 31 import javax.net.ssl.TrustManagerFactory; 32 import javax.net.ssl.KeyManagerFactory; 33 34 import org.jboss.security.SecurityDomain; 35 import org.apache.tomcat.util.net.jsse.JSSESocketFactory; 36 37 43 public class JBossSocketFactory 44 extends JSSESocketFactory 45 { 46 private SecurityDomain securityDomain; 47 48 public JBossSocketFactory() 49 { 50 } 51 52 public void setAttribute(String name, Object value) 53 { 54 if (name.equalsIgnoreCase("securityDomain")) 55 { 56 try 57 { 58 setSecurityDomainName((String ) value); 59 } 60 catch (Exception e) 61 { 62 IllegalArgumentException ex = 63 new IllegalArgumentException ("Failed to set security domain"); 64 ex.initCause(e); 65 throw ex; 66 } 67 } 68 super.setAttribute(name, value); 69 } 70 71 78 public void setSecurityDomainName(String jndiName) 79 throws NamingException , IOException 80 { 81 InitialContext iniCtx = new InitialContext (); 82 securityDomain = (SecurityDomain) iniCtx.lookup(jndiName); 83 } 84 85 93 protected KeyStore getKeystore(String type, String pass) 94 throws IOException 95 { 96 verifySecurityDomain(); 97 return securityDomain.getKeyStore(); 98 } 99 100 106 protected KeyStore getTrustStore(String type) throws IOException 107 { 108 verifySecurityDomain(); 109 return securityDomain.getTrustStore(); 110 } 111 112 120 protected TrustManager[] getTrustManagers(String keystoreType, String algorithm) 121 throws Exception 122 { 123 verifySecurityDomain(); 124 TrustManagerFactory tmf = securityDomain.getTrustManagerFactory(); 125 TrustManager[] trustMgrs = null; 126 127 if( tmf != null ) 128 { 129 trustMgrs = tmf.getTrustManagers(); 130 } 131 return trustMgrs; 132 } 133 134 143 protected KeyManager[] getKeyManagers(String keystoreType, String algorithm, 144 String keyAlias) 145 throws Exception 146 { 147 verifySecurityDomain(); 148 KeyManagerFactory kmf = securityDomain.getKeyManagerFactory(); 149 KeyManager[] keyMgrs = null; 150 if( kmf != null ) 151 { 152 keyMgrs = kmf.getKeyManagers(); 153 } 154 return keyMgrs; 155 } 156 157 private void verifySecurityDomain() 158 { 159 String str = "securityDomain is null." + 160 "Set it as an attribute in the connector setting"; 161 162 if(this.securityDomain == null) 163 throw new IllegalStateException (str); 164 } 165 } 166 | Popular Tags |