1 4 package org.objectweb.jonas.jtests.beans.jca15; 5 6 import java.rmi.RemoteException ; 7 import javax.ejb.CreateException ; 8 import javax.ejb.EJBException ; 9 import javax.ejb.RemoveException ; 10 import javax.ejb.EJBObject ; 11 import javax.ejb.SessionBean ; 12 import javax.ejb.SessionContext ; 13 import javax.naming.Context ; 14 import javax.naming.InitialContext ; 15 import javax.naming.NamingException ; 16 import javax.sql.DataSource ; 17 import ersatz.resourceadapter.*; 18 import javax.resource.cci.Connection ; 19 import javax.resource.spi.ManagedConnection ; 20 import javax.resource.spi.ConnectionEvent ; 21 import javax.resource.spi.ConnectionManager ; 22 23 24 27 public class SecuredCASLR implements SessionBean { 28 29 SessionContext ejbContext; 30 private ManagedConnectionFactoryImpl mcf = null; private ConnectionFactoryImpl cccf = null; private ConnectionImpl conn = null; 33 private ConnectionRequestInfoImpl crii = null; 34 InitialContext ic=null; 35 private String res_auth = ""; 36 String cName = "SecuredCASLR"; 37 38 42 43 public void setSessionContext(SessionContext ctx) { 44 Utility.log(cName+".setSessionContext"); 45 ejbContext = ctx; 46 } 47 48 49 public void ejbRemove() { 50 Utility.log(""); 51 } 52 53 54 public void ejbCreate() throws CreateException { 55 Utility.log(""); 56 } 57 58 public void ejbPassivate() { 59 Utility.log(""); 60 } 61 62 public void ejbActivate() { 63 Utility.log(""); 64 } 65 66 69 public void closeUp(int w) { 70 try { 71 if (w>0) { 72 conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED); 75 Utility.log(cName+".closeUp : closed physical connection"); 76 } else { 77 conn.close(); 80 Utility.log(cName+".closeUp : closed connection"); 81 } 82 } catch (Exception e) { 83 Utility.log(cName+".closeUp error: close handle/physical connection failed"); 84 } 85 } 86 public void setResAuth(String ra) { 87 res_auth=ra; } 89 public void setMatchNull(boolean b) { 90 mcf = cccf.getMcf(); mcf.setMatchNull(b); 92 } 93 97 100 public void method1(String rar_jndi_name, String testName) 101 throws Exception 102 { 103 Utility.log("============================ "+testName); 104 try { 105 ic = new InitialContext (); 106 } catch (Exception e1) { 107 Utility.log(cName+".method1 error: InitialContext failed"); 108 throw e1; 109 } 110 try { 111 cccf = (ConnectionFactoryImpl)ic.lookup(rar_jndi_name); 112 Utility.log(cName+".method1 : found "+rar_jndi_name); 113 } catch (Exception e2) { 114 Utility.log(cName+".method1 error: lookup failed for "+rar_jndi_name); 115 throw e2; 116 } 117 118 try { 124 conn = (ConnectionImpl)cccf.getConnection(); 125 Utility.log(cName+".method1 : getConnection() 'Container' conn="+conn); 126 127 if (conn==null) { 128 Utility.log(cName+".method1 error: getConnection returned null connection."); 129 throw new Exception (""); 130 } 131 } catch (Exception e4) { 132 Utility.log(cName+".method1 error: getConnection failed " 133 +e4.toString()); 134 throw e4; 135 } 136 } 137 138 public String getResAuth() { 139 try { 140 ManagedConnectionImpl mc = conn.getMC(); 141 String ra = mc.res_auth; Utility.log(cName+".getResAuth " 143 +"<res-auth>"+ra+"</res-auth>"); 144 if (ra==null || ra.length()==0) 145 throw new Exception (""); 146 return ra; 147 } catch (Exception e) { 148 Utility.log(cName 149 +".getResAuth error: failed to find <res-auth> " 150 +"in ManagedConnectionImpl"); 151 return ""; 152 } 153 } 154 public String getSecurityPassword() { 155 crii = conn.crii; try { 157 ManagedConnectionImpl mc = conn.getMC(); 158 String pw = crii.getPassword(); 159 Utility.log(cName+".getSecurityPassword (" 160 +mc.res_auth+")password="+pw); 161 if (pw==null || pw.length()==0) 162 throw new Exception (""); 163 return pw; 164 } catch (Exception e) { 165 mcf = cccf.getMcf(); 166 String pw = mcf.defaultPassword; Utility.log(cName 168 +".getSecurityPassword error: failed to find ConnectionRequestInfoImpl " 169 +"instance containing password. Using default="+pw); 170 return pw; 171 } 172 } 173 public String getSecurityUserName() { 174 crii = conn.crii; try { 176 ManagedConnectionImpl mc = conn.getMC(); 177 String u = crii.getUserName(); 178 Utility.log(cName+".getSecurityUserName (" 179 +mcf.getRes_Auth()+")userName="+u); 180 if (u==null || u.length()==0) 181 throw new Exception (""); 182 return u; 183 } catch (Exception e) { 184 mcf = cccf.getMcf(); 185 String u = mcf.defaultUserName; Utility.log(cName 187 +".getSecurityUserName error: failed to find ConnectionRequestInfoImpl " 188 +"instance containing userName. Using default="+u); 189 return u; 190 } 191 } 192 193 } 194 195 | Popular Tags |