[jboss-cvs] JBossAS SVN: r82463 - in projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Dec 22 04:41:20 EST 2008


Author: wolfc
Date: 2008-12-22 04:41:20 -0500 (Mon, 22 Dec 2008)
New Revision: 82463

Modified:
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/SecuredBean.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/SecuredLocal.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/unit/AuthenticationInterceptorTestCase.java
Log:
EJBTHREE-1646: test for sameness on result of multiple getCallerPrincipal calls

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/SecuredBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/SecuredBean.java	2008-12-22 07:17:14 UTC (rev 82462)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/SecuredBean.java	2008-12-22 09:41:20 UTC (rev 82463)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.core.test.ejbthree1646;
 
+import java.security.Principal;
+
 import javax.annotation.Resource;
 import javax.annotation.security.RolesAllowed;
 import javax.ejb.SessionContext;
@@ -39,6 +41,11 @@
    @Resource
    private SessionContext ctx;
    
+   public Principal getCallerPrincipal()
+   {
+      return ctx.getCallerPrincipal();
+   }
+   
    @RolesAllowed("Admin")
    public void onlyAdmin()
    {

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/SecuredLocal.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/SecuredLocal.java	2008-12-22 07:17:14 UTC (rev 82462)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/SecuredLocal.java	2008-12-22 09:41:20 UTC (rev 82463)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.core.test.ejbthree1646;
 
+import java.security.Principal;
+
 import javax.ejb.Local;
 
 /**
@@ -30,6 +32,8 @@
 @Local
 public interface SecuredLocal
 {
+   Principal getCallerPrincipal();
+   
    void onlyAdmin();
    
    String whoAmI();

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/unit/AuthenticationInterceptorTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/unit/AuthenticationInterceptorTestCase.java	2008-12-22 07:17:14 UTC (rev 82462)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1646/unit/AuthenticationInterceptorTestCase.java	2008-12-22 09:41:20 UTC (rev 82463)
@@ -66,6 +66,19 @@
       container.setJaccContextId("test");
    }
    
+   private SecurityContext login(String name, Object credential) throws Exception
+   {
+      SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
+      SecurityContextUtil util = sc.getUtil();
+      Principal principal = new SimplePrincipal(name);
+      Subject subject = new Subject();
+      subject.getPrincipals().add(principal);
+      subject.getPrivateCredentials().add(credential);
+      util.createSubjectInfo(principal, credential, subject);
+      SecurityContextAssociation.setSecurityContext(sc);
+      return sc;
+   }
+   
    @Test
    public void test1() throws Exception
    {
@@ -92,15 +105,7 @@
    {
       SecuredLocal bean = lookup("SecuredBean/local", SecuredLocal.class);
       
-      SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
-      SecurityContextUtil util = sc.getUtil();
-      Principal principal = new SimplePrincipal("Admin");
-      Object credential = null;
-      Subject subject = new Subject();
-      subject.getPrincipals().add(principal);
-      subject.getPrivateCredentials().add(credential);
-      util.createSubjectInfo(principal, credential, subject);
-      SecurityContextAssociation.setSecurityContext(sc);
+      login("Admin", null);
       
       String me = bean.whoAmI();
       assertEquals("Admin", me);
@@ -109,19 +114,37 @@
    }
    
    @Test
+   public void testEquals() throws Exception
+   {
+      SecuredLocal bean = lookup("SecuredBean/local", SecuredLocal.class);
+      
+      login("Admin", null);
+      
+      Principal p1 = bean.getCallerPrincipal();
+      Principal p2 = bean.getCallerPrincipal();
+      
+      assertEquals(p1, p2);
+   }
+   
+   @Test
+   public void testSame() throws Exception
+   {
+      SecuredLocal bean = lookup("SecuredBean/local", SecuredLocal.class);
+      
+      login("Admin", null);
+      
+      Principal p1 = bean.getCallerPrincipal();
+      Principal p2 = bean.getCallerPrincipal();
+      
+      assertSame(p1, p2);
+   }
+   
+   @Test
    public void testSecurityContextAssociation() throws Exception
    {
       SecuredLocal bean = lookup("SecuredBean/local", SecuredLocal.class);
       
-      SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
-      SecurityContextUtil util = sc.getUtil();
-      Principal principal = new SimplePrincipal("Invalid");
-      Object credential = null;
-      Subject subject = new Subject();
-      subject.getPrincipals().add(principal);
-      subject.getPrivateCredentials().add(credential);
-      util.createSubjectInfo(principal, credential, subject);
-      SecurityContextAssociation.setSecurityContext(sc);
+      SecurityContext sc = login("Invalid", null);
       
       try
       {




More information about the jboss-cvs-commits mailing list