1 22 package org.jboss.ejb3.test.security.unit; 23 24 import javax.security.auth.login.AppConfigurationEntry ; 25 import javax.security.auth.login.Configuration ; 26 import javax.security.auth.login.LoginContext ; 27 28 import org.jboss.ejb3.test.security.TimerTester; 29 import org.jboss.logging.Logger; 30 import org.jboss.security.SecurityAssociation; 31 import org.jboss.security.SimplePrincipal; 32 import org.jboss.security.auth.callback.UsernamePasswordHandler; 33 import org.jboss.security.auth.login.XMLLoginConfigImpl; 34 import org.jboss.test.JBossTestCase; 35 import junit.framework.Test; 36 37 41 public class TimerRunAsTestCase extends JBossTestCase 42 { 43 private static final Logger log = Logger 44 .getLogger(TimerRunAsTestCase.class); 45 46 static boolean deployed = false; 47 static int test = 0; 48 49 public TimerRunAsTestCase(String name) 50 { 51 super(name); 52 } 53 54 public void testSecurityAssociation() 55 { 56 SecurityAssociation.clear(); 57 SecurityAssociation.pushSubjectContext(null, new SimplePrincipal("bill"), "password".toCharArray()); 58 assertEquals("bill", SecurityAssociation.getPrincipal().getName()); 59 SecurityAssociation.popSubjectContext(); 60 assertNull(SecurityAssociation.getPrincipal()); 61 } 62 63 public void testNoSecurityAssociationPrincipal() throws Exception 64 { 65 SecurityAssociation.clear(); 66 67 AppConfigurationEntry [] entries; 68 XMLLoginConfigImpl config = new XMLLoginConfigImpl(); 69 config.setConfigResource("jaas-test-config.xml"); 70 config.loadConfig(); 71 Configuration.setConfiguration(config); 72 73 entries = Configuration.getConfiguration().getAppConfigurationEntry("timer-runas-test"); 74 assertEquals(1, entries.length); 75 76 UsernamePasswordHandler handler = new UsernamePasswordHandler(null, null); 77 LoginContext lc = new LoginContext ("timer-runas-test", handler); 78 79 lc.login(); 80 81 TimerTester test = (TimerTester) getInitialContext().lookup("TimerTester"); 82 assertNotNull(test); 83 84 test.startTimer(5000); 85 Thread.sleep(6000); 86 assertTrue(test.isTimerCalled()); 87 88 lc.logout(); 89 } 90 91 public static Test suite() throws Exception 92 { 93 return getDeploySetup(TimerRunAsTestCase.class, "timer-runas-security.jar"); 94 } 95 } | Popular Tags |