assertTrue(sm.isSimulateJBossJaasSecurityManager());
ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
Queue queue = (Queue)ic.lookup("/queue/SecureTestQueue");
Principal nabopolassar = new SimplePrincipal("nabopolassar");
Set principals = new HashSet();
principals.add(nabopolassar);
Subject subject =
new Subject(false, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
Principal nebuchadrezzar = new SimplePrincipal("nebuchadrezzar");
SecurityAssociation.pushSubjectContext(subject, nebuchadrezzar, "xexe");
Connection conn = null;
try
{
conn = cf.createConnection("john", "needle");
conn.start();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = session.createProducer(queue);
MessageConsumer cons = session.createConsumer(queue);
TextMessage m = session.createTextMessage("floccinaucinihilipilification");
prod.send(m);
TextMessage rm = (TextMessage)cons.receive(5000);
assertEquals("floccinaucinihilipilification", rm.getText());
SecurityAssociation.SubjectContext context = SecurityAssociation.popSubjectContext();
Subject s = context.getSubject();
assertNotNull(s);
Set ps = s.getPrincipals();
assertNotNull(ps);
assertEquals(1, ps.size());
Principal p = (Principal)ps.iterator().next();
assertTrue(p instanceof SimplePrincipal);
assertEquals("nabopolassar", ((SimplePrincipal)p).getName());
p = context.getPrincipal();
assertNotNull(p);