1 17 18 package org.apache.geronimo.connector.outbound; 19 20 import javax.security.auth.Subject ; 21 import javax.resource.ResourceException ; 22 23 import org.apache.geronimo.security.ContextManager; 24 25 31 public class SubjectInterceptorTest extends ConnectionInterceptorTestUtils { 32 33 private SubjectInterceptor subjectInterceptor; 34 35 protected void setUp() throws Exception { 36 super.setUp(); 37 subjectInterceptor = new SubjectInterceptor(this); 38 } 39 40 protected void tearDown() throws Exception { 41 super.tearDown(); 42 subjectInterceptor = null; 43 } 44 45 public void testGetConnection() throws Exception { 46 subject = new Subject (); 47 ContextManager.setCallers(subject, subject); 48 ConnectionInfo connectionInfo = makeConnectionInfo(); 49 ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo(); 50 subjectInterceptor.getConnection(connectionInfo); 51 assertTrue("Expected call to next with same connectionInfo", connectionInfo == obtainedConnectionInfo); 52 assertTrue("Expected the same managedConnectionInfo", managedConnectionInfo == connectionInfo.getManagedConnectionInfo()); 53 assertTrue("Expected supplied subject to be inserted", subject == managedConnectionInfo.getSubject()); 54 } 55 56 public void testReturnConnection() throws Exception { 57 ConnectionInfo connectionInfo = makeConnectionInfo(); 58 subjectInterceptor.returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE); 59 assertTrue("Expected call to next with same connectionInfo", connectionInfo == returnedConnectionInfo); 60 } 61 62 public void testEnterWithSameSubject() throws Exception { 63 makeSubject("foo"); 64 ConnectionInfo connectionInfo = makeConnectionInfo(); 65 managedConnection = new TestPlainManagedConnection(); 66 subjectInterceptor.getConnection(connectionInfo); 67 obtainedConnectionInfo = null; 69 subjectInterceptor.getConnection(connectionInfo); 70 assertTrue("Expected connection asked for", obtainedConnectionInfo == connectionInfo); 71 assertTrue("Expected no connection returned", returnedConnectionInfo == null); 72 } 73 74 public void testEnterWithChangedSubject() throws Exception { 75 makeSubject("foo"); 76 ContextManager.setCallers(subject, subject); 77 ConnectionInfo connectionInfo = makeConnectionInfo(); 78 managedConnection = new TestPlainManagedConnection(); 79 subjectInterceptor.getConnection(connectionInfo); 80 obtainedConnectionInfo = null; 82 makeSubject("bar"); 83 ContextManager.setCallers(subject, subject); 84 subjectInterceptor.getConnection(connectionInfo); 85 assertTrue("Expected connection asked for", obtainedConnectionInfo != null); 87 assertTrue("Expected connection returned", returnedConnectionInfo != null); 89 } 90 91 public void testApplicationManagedSecurity() throws Exception { 92 makeSubject("foo"); 93 ConnectionInfo connectionInfo = makeConnectionInfo(); 94 connectionInfo.setApplicationManagedSecurity(true); 95 ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo(); 96 managedConnection = new TestPlainManagedConnection(); 97 subjectInterceptor.getConnection(connectionInfo); 98 assertTrue("Expected call to next with same connectionInfo", connectionInfo == obtainedConnectionInfo); 100 assertTrue("Expected the same managedConnectionInfo", managedConnectionInfo == connectionInfo.getManagedConnectionInfo()); 101 assertTrue("Expected no subject to be inserted", null == managedConnectionInfo.getSubject()); 102 } 103 104 public void testUnshareablePreventsReAssociation() throws Exception { 105 makeSubject("foo"); 106 ContextManager.setCallers(subject, subject); 107 ConnectionInfo connectionInfo = makeConnectionInfo(); 108 connectionInfo.setUnshareable(true); 109 managedConnection = new TestPlainManagedConnection(); 110 subjectInterceptor.getConnection(connectionInfo); 111 obtainedConnectionInfo = null; 113 makeSubject("bar"); 114 ContextManager.setCallers(subject, subject); 115 try { 116 subjectInterceptor.getConnection(connectionInfo); 117 fail("Reassociating should fail on an unshareable connection"); 118 } catch (ResourceException e) { 119 } 120 } 121 122 } 123 | Popular Tags |