1 22 package org.jboss.test.security.test; 23 24 import java.util.HashSet ; 25 import java.util.Properties ; 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 28 import javax.rmi.PortableRemoteObject ; 29 30 import junit.framework.Test; 31 import org.jboss.security.SimplePrincipal; 32 import org.jboss.test.JBossTestCase; 33 import org.jboss.test.security.interfaces.SubjectSession; 34 import org.jboss.test.security.interfaces.SubjectSessionHome; 35 36 37 42 public class CallerInfoUnitTestCase 43 extends JBossTestCase 44 { 45 public CallerInfoUnitTestCase(String name) 46 { 47 super(name); 48 } 49 50 52 public void testCallerSubject() throws Exception 53 { 54 log.debug("+++ testCallerSubject()"); 55 Properties env = new Properties (); 56 env.setProperty(Context.INITIAL_CONTEXT_FACTORY, 57 "org.jboss.security.jndi.JndiLoginInitialContextFactory"); 58 env.setProperty(Context.SECURITY_PRINCIPAL, "jduke"); 59 env.setProperty(Context.SECURITY_CREDENTIALS, "theduke"); 60 InitialContext ctx = new InitialContext (env); 61 Object obj = ctx.lookup("caller-info.SubjectSessionFacade"); 62 obj = PortableRemoteObject.narrow(obj, SubjectSessionHome.class); 63 SubjectSessionHome home = (SubjectSessionHome) obj; 64 log.debug("Found CustomPrincipalHome"); 65 SubjectSession bean = home.create(); 66 log.debug("Created CustomPrincipal"); 67 68 HashSet principals = new HashSet (); 69 principals.add(new SimplePrincipal("CallerInfoFacadeRole")); 70 principals.add(new SimplePrincipal("CallerInfoStatelessRole")); 71 principals.add(new SimplePrincipal("CallerInfoStatefulRole")); 72 principals.add(new SimplePrincipal("CallerInfoEntityRole")); 73 bean.validateCallerContext("callerJduke", principals); 74 bean.remove(); 75 } 76 77 public static Test suite() throws Exception 78 { 79 return JBossTestCase.getDeploySetup(CallerInfoUnitTestCase.class, "caller-info.jar"); 80 } 81 82 } 83 | Popular Tags |