[jboss-cvs] JBossAS SVN: r90100 - branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/profileservice/testsecure.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 11 12:12:39 EDT 2009


Author: scott.stark at jboss.org
Date: 2009-06-11 12:12:38 -0400 (Thu, 11 Jun 2009)
New Revision: 90100

Modified:
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/profileservice/testsecure/ProfileServiceUnitTestCase.java
Log:
JBAS-6982, add a test of passing security info using JndiLoginInitialContextFactory


Modified: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/profileservice/testsecure/ProfileServiceUnitTestCase.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/profileservice/testsecure/ProfileServiceUnitTestCase.java	2009-06-11 16:01:15 UTC (rev 90099)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/profileservice/testsecure/ProfileServiceUnitTestCase.java	2009-06-11 16:12:38 UTC (rev 90100)
@@ -24,9 +24,12 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
+import javax.naming.Context;
 import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
 
@@ -52,6 +55,15 @@
  */
 public class ProfileServiceUnitTestCase extends AbstractProfileServiceTest
 {
+   private static final String JNDI_LOGIN_INITIAL_CONTEXT_FACTORY = "org.jboss.security.jndi.JndiLoginInitialContextFactory";
+
+   private static final String SECURE_PROFILE_SERVICE_JNDI_NAME = "SecureProfileService/remote";
+   private static final String SECURE_MANAGEMENT_VIEW_JNDI_NAME = "SecureManagementView/remote";
+   private static final String SECURE_DEPLOYMENT_MANAGER_JNDI_NAME = "SecureDeploymentManager/remote";
+   
+   private static final String PROFILE_SERVICE_PRINCIPAL = "javaduke";
+   private static final String PROFILE_SERVICE_CREDENTIALS = "anotherduke";
+
    private LoginContext loginContext;
 
    /**
@@ -164,7 +176,28 @@
       logout();
    }
 
-
+   /**
+    * Validate that there is only 1 DefaultDS ManagedComponent
+    * @throws Exception
+    */
+   public void testDefaultDSComponentCountUsingJLICF()
+      throws Exception
+   {
+      ManagementView mgtView = getManagementViewJLICF();
+      ComponentType type = new ComponentType("DataSource", "LocalTx");
+      Set<ManagedComponent> comps = mgtView.getComponentsForType(type);
+      int count = 0;
+      for (ManagedComponent comp : comps)
+      {
+        String cname = comp.getName();
+        if( cname.endsWith("DefaultDS") )
+        {
+           count ++;
+        }
+      }
+      assertEquals("There is 1 DefaultDS ManagedComponent", 1, 1);
+   }
+   
    // Private and protected
 
    @Override
@@ -173,6 +206,22 @@
       return "profileservice";
    }
 
+   protected InitialContext getInitialContextJLICF()
+      throws NamingException
+   {
+      Properties env = new Properties();
+      env.setProperty(Context.INITIAL_CONTEXT_FACTORY, JNDI_LOGIN_INITIAL_CONTEXT_FACTORY);
+      env.setProperty(Context.SECURITY_PRINCIPAL, PROFILE_SERVICE_PRINCIPAL);
+      env.setProperty(Context.SECURITY_CREDENTIALS, PROFILE_SERVICE_CREDENTIALS);      
+      
+      InitialContext ctx = new InitialContext(env);
+      return ctx;
+   }
+   /**
+    * 
+    * @return
+    * @throws Exception
+    */
    protected ProfileService getProfileService()
       throws Exception
    {
@@ -180,6 +229,22 @@
       ProfileService ps = (ProfileService) ctx.lookup("SecureProfileService/remote");
       return ps;
    }
+   
+   /**
+    * Lookup of the ProfileService using a JNDI login InitialContextFactory
+    * @return
+    * @throws Exception
+    */
+   protected ProfileService getProfileServiceJLICF()
+      throws Exception
+   {
+      InitialContext ctx = getInitialContextJLICF();
+      Object ref = ctx.lookup(SECURE_PROFILE_SERVICE_JNDI_NAME);
+      log.debug(SECURE_PROFILE_SERVICE_JNDI_NAME+": "+ref);
+      ProfileService ps = (ProfileService) ref;
+      return ps;
+   }
+
    @Override
    protected ManagementView getManagementView()
       throws Exception
@@ -188,6 +253,13 @@
       ManagementView mgtView = (ManagementView) ctx.lookup("SecureManagementView/remote");
       return mgtView;
    }
+   protected ManagementView getManagementViewJLICF()
+      throws Exception
+   {
+      InitialContext ctx = getInitialContextJLICF();
+      ManagementView mgtView = (ManagementView) ctx.lookup("SecureManagementView/remote");
+      return mgtView;
+   }
 
    /**
     * Authenticates the client identified by the given {@code username} using the specified {@code password}.




More information about the jboss-cvs-commits mailing list