You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2006/03/19 23:43:02 UTC

svn commit: r387050 - in /geronimo/branches/1.1/modules: mail/src/test/org/apache/geronimo/mail/ tomcat/src/java/org/apache/geronimo/tomcat/ tomcat/src/test-resources/deployables/war3/WEB-INF/ tomcat/src/test/org/apache/geronimo/tomcat/

Author: djencks
Date: Sun Mar 19 14:43:00 2006
New Revision: 387050

URL: http://svn.apache.org/viewcvs?rev=387050&view=rev
Log:
fix mail test, fix tomcat module

Modified:
    geronimo/branches/1.1/modules/mail/src/test/org/apache/geronimo/mail/MailGBeanTest.java
    geronimo/branches/1.1/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java
    geronimo/branches/1.1/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
    geronimo/branches/1.1/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/web.xml
    geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
    geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java
    geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java
    geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/JAASSecurityTest.java
    geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java

Modified: geronimo/branches/1.1/modules/mail/src/test/org/apache/geronimo/mail/MailGBeanTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/mail/src/test/org/apache/geronimo/mail/MailGBeanTest.java?rev=387050&r1=387049&r2=387050&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/mail/src/test/org/apache/geronimo/mail/MailGBeanTest.java (original)
+++ geronimo/branches/1.1/modules/mail/src/test/org/apache/geronimo/mail/MailGBeanTest.java Sun Mar 19 14:43:00 2006
@@ -16,42 +16,29 @@
  */
 package org.apache.geronimo.mail;
 
+import java.util.Collections;
 import java.util.Properties;
+
 import javax.mail.Session;
 import javax.mail.Store;
 import javax.mail.Transport;
-import javax.management.ObjectName;
 
 import junit.framework.TestCase;
 
-import org.apache.geronimo.gbean.GBeanData;
-import org.apache.geronimo.kernel.KernelFactory;
-import org.apache.geronimo.kernel.Kernel;
-
 
 /**
  * @version $Rev$ $Date$
  */
 public class MailGBeanTest extends TestCase {
 
-    private Kernel kernel;
-    private ObjectName mailName;
-    private ObjectName protocolName;
-    private static final String KERNEL_NAME = "testKernel";
-
     public void testProperties() throws Exception {
         Properties properties = new Properties();
         properties.put("mail.store.protocol", "testStore");
         properties.put("mail.transport.protocol", "testTransport");
 
-        mailName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,J2EEType=JavaMailResource,name=default");
-        GBeanData cmf = new GBeanData(mailName, MailGBean.getGBeanInfo());
-        cmf.setAttribute("useDefault", new Boolean(true));
-        cmf.setAttribute("properties", properties);
-        kernel.loadGBean(cmf, MailGBean.class.getClassLoader());
-        kernel.startGBean(mailName);
-
-        Object proxy = kernel.invoke(mailName, "$getResource");
+        MailGBean mail = new MailGBean("test:name=mail", null, Boolean.TRUE, properties, null, null, null, null, null, null);
+        mail.doStart();
+        Object proxy = mail.$getResource();
 
         assertNotNull(proxy);
         assertTrue(proxy instanceof Session);
@@ -64,7 +51,6 @@
         assertNotNull(transport);
         assertTrue(transport instanceof TestTransport);
 
-        kernel.stopGBean(mailName);
     }
 
     public void testDefaultOverrides() throws Exception {
@@ -72,16 +58,9 @@
         properties.put("mail.store.protocol", "POOKIE");
         properties.put("mail.transport.protocol", "BEAR");
 
-        mailName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,J2EEType=JavaMailResource,name=default");
-        GBeanData cmf = new GBeanData(mailName, MailGBean.getGBeanInfo());
-        cmf.setAttribute("useDefault", new Boolean(true));
-        cmf.setAttribute("properties", properties);
-        cmf.setAttribute("storeProtocol", "test");
-        cmf.setAttribute("transportProtocol", "test");
-        kernel.loadGBean(cmf, MailGBean.class.getClassLoader());
-        kernel.startGBean(mailName);
-
-        Object proxy = kernel.invoke(mailName, "$getResource");
+        MailGBean mail = new MailGBean("test:name=mail", null, Boolean.TRUE, properties, null, "test", "test", null, null, null);
+        mail.doStart();
+        Object proxy = mail.$getResource();
 
         assertNotNull(proxy);
         assertTrue(proxy instanceof Session);
@@ -94,7 +73,6 @@
         assertNotNull(transport);
         assertTrue(transport instanceof TestTransport);
 
-        kernel.stopGBean(mailName);
     }
 
     public void testSMTPOverrides() throws Exception {
@@ -103,24 +81,12 @@
         properties.put("mail.transport.protocol", "BEAR");
         properties.put("mail.smtp.ehlo", "true");
 
-        mailName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,J2EEType=JavaMailResource,name=default");
-        GBeanData cmf = new GBeanData(mailName, MailGBean.getGBeanInfo());
-        cmf.setReferencePattern("Protocols", new ObjectName("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,*"));
-        cmf.setAttribute("useDefault", new Boolean(true));
-        cmf.setAttribute("properties", properties);
-        cmf.setAttribute("storeProtocol", "test");
-        cmf.setAttribute("transportProtocol", "test");
-
-
-        kernel.loadGBean(cmf, MailGBean.class.getClassLoader());
-        kernel.startGBean(mailName);
-
-        protocolName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,name=smtp");
-        GBeanData smtp = new GBeanData(protocolName, SMTPTransportGBean.getGBeanInfo());
-        kernel.loadGBean(smtp, SMTPTransportGBean.class.getClassLoader());
-        kernel.startGBean(protocolName);
+        SMTPTransportGBean protocol = new SMTPTransportGBean("test:name=smtp", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
+        protocol.doStart();
 
-        Object proxy = kernel.invoke(mailName, "$getResource");
+        MailGBean mail = new MailGBean("test:name=mail", Collections.singleton(protocol), Boolean.TRUE, properties, null, "test", "test", null, null, null);
+        mail.doStart();
+        Object proxy = mail.$getResource();
 
         assertNotNull(proxy);
         assertTrue(proxy instanceof Session);
@@ -136,8 +102,6 @@
         TestTransport testTransport = (TestTransport) transport;
         assertFalse(testTransport.isEHLO());
 
-        kernel.stopGBean(protocolName);
-        kernel.stopGBean(mailName);
     }
 
     public void testPOP3Overrides() throws Exception {
@@ -146,22 +110,12 @@
         properties.put("mail.transport.protocol", "BEAR");
         properties.put("mail.pop3.ehlo", "true");
 
-        mailName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,J2EEType=JavaMailResource,name=default");
-        GBeanData cmf = new GBeanData(mailName, MailGBean.getGBeanInfo());
-        cmf.setReferencePattern("Protocols", new ObjectName("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,*"));
-        cmf.setAttribute("useDefault", new Boolean(true));
-        cmf.setAttribute("properties", properties);
-        cmf.setAttribute("storeProtocol", "test");
-        cmf.setAttribute("transportProtocol", "test");
-        kernel.loadGBean(cmf, MailGBean.class.getClassLoader());
-        kernel.startGBean(mailName);
-
-        protocolName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,name=pop3");
-        GBeanData pop3 = new GBeanData(protocolName, SMTPTransportGBean.getGBeanInfo()); // todo shouldn't this be POP3Store?
-        kernel.loadGBean(pop3, SMTPTransportGBean.class.getClassLoader());
-        kernel.startGBean(protocolName);
+        POP3StoreGBean protocol = new POP3StoreGBean("test:name=pop3", null, null, null, null, null, null, null, null, null, null, null, null, null, null);
+        protocol.doStart();
 
-        Object proxy = kernel.invoke(mailName, "$getResource");
+        MailGBean mail = new MailGBean("test:name=mail", Collections.singleton(protocol), Boolean.TRUE, properties, null, "test", "test", null, null, null);
+        mail.doStart();
+        Object proxy = mail.$getResource();
 
         assertNotNull(proxy);
         assertTrue(proxy instanceof Session);
@@ -174,8 +128,6 @@
         assertNotNull(transport);
         assertTrue(transport instanceof TestTransport);
 
-        kernel.stopGBean(protocolName);
-        kernel.stopGBean(mailName);
     }
 
     public void testIMAPOverrides() throws Exception {
@@ -184,25 +136,14 @@
         properties.put("mail.transport.protocol", "BEAR");
         properties.put("mail.imap.ehlo", "true");
 
-        mailName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,J2EEType=JavaMailResource,name=default");
-        GBeanData cmf = new GBeanData(mailName, MailGBean.getGBeanInfo());
-        cmf.setReferencePattern("Protocols", new ObjectName("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,*"));
-        cmf.setAttribute("useDefault", new Boolean(true));
-        cmf.setAttribute("properties", properties);
-        cmf.setAttribute("storeProtocol", "testStore");
-        cmf.setAttribute("transportProtocol", "testTransport");
-        kernel.loadGBean(cmf, MailGBean.class.getClassLoader());
-        kernel.startGBean(mailName);
+        IMAPStoreGBean protocol = new IMAPStoreGBean("test:name=imap", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
+        protocol.doStart();
 
-        protocolName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,name=imap");
-        GBeanData imap = new GBeanData(protocolName, IMAPStoreGBean.getGBeanInfo());
+        MailGBean mail = new MailGBean("test:name=mail", Collections.singleton(protocol), Boolean.TRUE, properties, null, "test", "test", null, null, null);
+        mail.doStart();
+        Object proxy = mail.$getResource();
 
 
-        kernel.loadGBean(imap, IMAPStoreGBean.class.getClassLoader());
-        kernel.startGBean(protocolName);
-
-        Object proxy = kernel.invoke(mailName, "$getResource");
-
         assertNotNull(proxy);
         assertTrue(proxy instanceof Session);
 
@@ -214,16 +155,6 @@
         assertNotNull(transport);
         assertTrue(transport instanceof TestTransport);
 
-        kernel.stopGBean(protocolName);
-        kernel.stopGBean(mailName);
     }
 
-    protected void setUp() throws Exception {
-        kernel = KernelFactory.newInstance().createKernel(KERNEL_NAME);
-        kernel.boot();
-    }
-
-    protected void tearDown() throws Exception {
-        kernel.shutdown();
-    }
 }

Modified: geronimo/branches/1.1/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java?rev=387050&r1=387049&r2=387050&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java (original)
+++ geronimo/branches/1.1/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java Sun Mar 19 14:43:00 2006
@@ -113,34 +113,36 @@
         }
 
         //Add the hosts
-        ReferenceCollection refs = (ReferenceCollection)hosts;
-        refs.addReferenceCollectionListener(new ReferenceCollectionListener() {
+        if (hosts instanceof ReferenceCollection) {
+            ReferenceCollection refs = (ReferenceCollection)hosts;
+            refs.addReferenceCollectionListener(new ReferenceCollectionListener() {
 
-            public void memberAdded(ReferenceCollectionEvent event) {
-                Object o = event.getMember();
-                ObjectRetriever objectRetriever = (ObjectRetriever) o;
-                String hostName = ((Host)objectRetriever.getInternalObject()).getName();
-                if (!hostName.equals(defaultHostName))
-                    addHost(objectRetriever);
-            }
+                public void memberAdded(ReferenceCollectionEvent event) {
+                    Object o = event.getMember();
+                    ObjectRetriever objectRetriever = (ObjectRetriever) o;
+                    String hostName = ((Host)objectRetriever.getInternalObject()).getName();
+                    if (!hostName.equals(defaultHostName))
+                        addHost(objectRetriever);
+                }
 
-            public void memberRemoved(ReferenceCollectionEvent event) {
-                Object o = event.getMember();
-                ObjectRetriever objectRetriever = (ObjectRetriever) o;
-                String hostName = ((Host)objectRetriever.getInternalObject()).getName();
+                public void memberRemoved(ReferenceCollectionEvent event) {
+                    Object o = event.getMember();
+                    ObjectRetriever objectRetriever = (ObjectRetriever) o;
+                    String hostName = ((Host)objectRetriever.getInternalObject()).getName();
+                    if (!hostName.equals(defaultHostName))
+                        removeHost(objectRetriever);
+                }
+            });
+            Iterator iterator = refs.iterator();
+            while (iterator.hasNext()){
+                ObjectRetriever objRetriever = (ObjectRetriever)iterator.next();
+                String hostName = ((Host)objRetriever.getInternalObject()).getName();
                 if (!hostName.equals(defaultHostName))
-                    removeHost(objectRetriever);
+                    addHost(objRetriever);
             }
-        });
-        
-        Iterator iterator = refs.iterator();
-        while (iterator.hasNext()){
-            ObjectRetriever objRetriever = (ObjectRetriever)iterator.next();
-            String hostName = ((Host)objRetriever.getInternalObject()).getName();
-            if (!hostName.equals(defaultHostName))
-                addHost(objRetriever);
         }
-        
+
+
         //Add clustering
         if (clusterGBean != null){
             engine.setCluster((Cluster)clusterGBean.getInternalObject());

Modified: geronimo/branches/1.1/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java?rev=387050&r1=387049&r2=387050&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java (original)
+++ geronimo/branches/1.1/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java Sun Mar 19 14:43:00 2006
@@ -217,8 +217,10 @@
         this.classLoader = classLoader;
 
         this.kernel = kernel;
-        ObjectName myObjectName = JMXUtil.getObjectName(objectName);
-        verifyObjectName(myObjectName);
+        if (objectName != null) {
+            ObjectName myObjectName = JMXUtil.getObjectName(objectName);
+            verifyObjectName(myObjectName);
+        }
 
         if (securityHolder != null){
             if (roleDesignateSource == null) {

Modified: geronimo/branches/1.1/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/web.xml?rev=387050&r1=387049&r2=387050&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/web.xml (original)
+++ geronimo/branches/1.1/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/web.xml Sun Mar 19 14:43:00 2006
@@ -38,7 +38,7 @@
         </web-resource-collection>
         <auth-constraint>
             <role-name>content-administrator</role-name>
-            <role-name>auto-administrator</role-name> -->
+            <role-name>auto-administrator</role-name>
         </auth-constraint>
     </security-constraint>
 

Modified: geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java?rev=387050&r1=387049&r2=387050&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java (original)
+++ geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java Sun Mar 19 14:43:00 2006
@@ -18,28 +18,15 @@
 
 import java.io.File;
 import java.net.URI;
-import java.security.PermissionCollection;
-import java.security.Permissions;
+import java.net.URL;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
 import java.util.Properties;
-import java.util.Set;
-import javax.management.ObjectName;
 
 import junit.framework.TestCase;
-
-import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinatorGBean;
-import org.apache.geronimo.gbean.GBeanData;
-import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
-import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
-import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.KernelFactory;
-import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
 import org.apache.geronimo.security.SecurityServiceImpl;
-import org.apache.geronimo.security.deploy.DefaultPrincipal;
 import org.apache.geronimo.security.deploy.PrincipalInfo;
 import org.apache.geronimo.security.jaas.GeronimoLoginConfiguration;
 import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
@@ -47,12 +34,14 @@
 import org.apache.geronimo.security.jaas.server.JaasLoginService;
 import org.apache.geronimo.security.jacc.ApplicationPolicyConfigurationManager;
 import org.apache.geronimo.security.jacc.ComponentPermissions;
+import org.apache.geronimo.security.jacc.RoleDesignateSource;
 import org.apache.geronimo.security.realm.GenericSecurityRealm;
 import org.apache.geronimo.system.serverinfo.BasicServerInfo;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
 import org.apache.geronimo.tomcat.util.SecurityHolder;
 import org.apache.geronimo.transaction.context.OnlineUserTransaction;
-import org.apache.geronimo.transaction.context.TransactionContextManagerGBean;
-import org.apache.geronimo.transaction.manager.TransactionManagerImplGBean;
+import org.apache.geronimo.transaction.context.TransactionContextManager;
+import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
 
 
 /**
@@ -60,353 +49,145 @@
  */
 public class AbstractWebModuleTest extends TestCase {
 
-    protected static final String POLICY_CONTEXT_ID = "securetest";
-    protected static final String REALM_NAME = "usable-realm";
-
-    protected Kernel kernel;
-    private GBeanData container;
-    private ObjectName containerName;
-    private ObjectName connectorName;
-    private GBeanData connector;
-    private ObjectName engineName;
-    private GBeanData engine;
-    private ObjectName hostName;
-    private GBeanData host;
-    private ObjectName realmName;
-    private GBeanData realm;
-    private ObjectName webModuleName;
-    private ObjectName contextRealmName;
-    private ObjectName tmName;
-    private ObjectName ctcName;
-    private GBeanData tm;
-    private GBeanData ctc;
-    private ObjectName tcmName;
-    private GBeanData tcm;
-    private ClassLoader cl;
-    private J2eeContext moduleContext = new J2eeContextImpl("tomcat.test", "test", "null", NameFactory.WEB_MODULE, "tomcatTest", null, null);
-    private GBeanData securityServiceGBean;
-    protected ObjectName securityServiceName;
-    private ObjectName loginServiceName;
-    private GBeanData loginServiceGBean;
-    private GBeanData loginConfigurationGBean;
-    protected ObjectName loginConfigurationName;
-    protected GBeanData propertiesLMGBean;
-    protected ObjectName propertiesLMName;
-    protected ObjectName propertiesRealmName;
-    private GBeanData propertiesRealmGBean;
-    protected ObjectName propertiesRealmName2;
-    private GBeanData propertiesRealmGBean2;
-    private ObjectName serverInfoName;
-    private GBeanData serverInfoGBean;
+    protected ClassLoader cl;
+    protected final static String securityRealmName = "demo-properties-realm";
+    private ConnectorGBean connector;
+    protected TomcatContainer container;
+    private TransactionContextManager transactionContextManager;
+    private ConnectionTrackingCoordinator connectionTrackingCoordinator;
 
-    public void testDummy() {
-    }
-
-    protected void setUpInsecureAppContext() throws Exception {
+    protected static final String POLICY_CONTEXT_ID = "securetest";
+    private GeronimoLoginConfiguration loginConfiguration;
 
-        GBeanData app = new GBeanData(webModuleName, TomcatWebAppContext.GBEAN_INFO);
-        app.setAttribute("webAppRoot", new File("target/var/catalina/webapps/war1/").toURI());
-        app.setAttribute("webClassPath", new URI[]{});
-        app.setAttribute("configurationBaseUrl", new File("target/var/catalina/webapps/war1/WEB-INF/web.xml").toURL());
-        app.setAttribute("componentContext", Collections.EMPTY_MAP);
-        app.setReferencePattern("Container", containerName);
-        OnlineUserTransaction userTransaction = new OnlineUserTransaction();
-        app.setAttribute("userTransaction", userTransaction);
-        app.setReferencePattern("TransactionContextManager", tcmName);
-        app.setReferencePattern("TrackedConnectionAssociator", ctcName);
-        app.setAttribute("contextPath", "/test");
+    protected TomcatWebAppContext setUpInsecureAppContext(URI relativeWebAppRoot, URL configurationBaseURL, SecurityHolder securityHolder, RoleDesignateSource roleDesignateSource, ObjectRetriever tomcatRealm, ValveGBean valveChain) throws Exception {
 
-        start(app);
+        TomcatWebAppContext app = new TomcatWebAppContext(cl,
+                null,
+                null,
+                relativeWebAppRoot,
+                new URI[]{},
+                false,
+                configurationBaseURL,
+                securityHolder,
+                null,
+                Collections.EMPTY_MAP,
+                null,
+                null,
+                new OnlineUserTransaction(),
+                transactionContextManager,
+                connectionTrackingCoordinator,
+                container,
+                roleDesignateSource,
+                tomcatRealm,
+                valveChain,
+                null,
+                null,
+                false,
+                null,
+                null,
+                null,
+                null);
+        app.setContextPath("/test");
+        app.doStart();
+        return app;
     }
 
-    protected void setUpJAASSecureAppContext() throws Exception {
-        //Will use Context Level Security
-        ObjectName jaccBeanName = NameFactory.getComponentName(null, null, null, null, "foo", NameFactory.JACC_MANAGER, moduleContext);
-        GBeanData jaccBeanData = new GBeanData(jaccBeanName, ApplicationPolicyConfigurationManager.GBEAN_INFO);
-        PermissionCollection excludedPermissions = new Permissions();
-        PermissionCollection uncheckedPermissions = new Permissions();
-        ComponentPermissions componentPermissions = new ComponentPermissions(excludedPermissions, uncheckedPermissions, new HashMap());
+    protected TomcatWebAppContext setUpSecureAppContext(Map roleDesignates, Map principalRoleMap, ComponentPermissions componentPermissions, RealmGBean realm, SecurityHolder securityHolder) throws Exception {
         Map contextIDToPermissionsMap = new HashMap();
         contextIDToPermissionsMap.put(POLICY_CONTEXT_ID, componentPermissions);
-        jaccBeanData.setAttribute("contextIdToPermissionsMap", contextIDToPermissionsMap);
-        jaccBeanData.setAttribute("principalRoleMap", new HashMap());
-        jaccBeanData.setAttribute("roleDesignates", new HashMap());
-        start(jaccBeanData);
-
-        //Set a context level Realm and ignore the Engine level to test that
-        //the override along with a Security Realm Name set overrides the Engine
-        Map initParams = new HashMap();
-        initParams.put("userClassNames", "org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal");
-        initParams.put("roleClassNames", "org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal");
-        contextRealmName = NameFactory.getWebComponentName(null, null, null, null, "tomcatContextRealm", "WebResource", moduleContext);
-        GBeanData contextRealm = new GBeanData(contextRealmName, RealmGBean.GBEAN_INFO);
-        contextRealm.setAttribute("className", "org.apache.geronimo.tomcat.realm.TomcatJAASRealm");
-        contextRealm.setAttribute("initParams", initParams);
-        start(contextRealm);
-
-        //Force a new realm name and ignore the application name
-        SecurityHolder securityHolder = new SecurityHolder();
-        securityHolder.setSecurityRealm(REALM_NAME);
-
-        GBeanData app = new GBeanData(webModuleName, TomcatWebAppContext.GBEAN_INFO);
-        app.setAttribute("webAppRoot", new File("target/var/catalina/webapps/war3/").toURI());
-        app.setAttribute("webClassPath", new URI[]{});
-        app.setAttribute("securityHolder", securityHolder);
-        app.setAttribute("configurationBaseUrl", new File("target/var/catalina/webapps/war3/WEB-INF/web.xml").toURL());
-        app.setAttribute("contextPath", "/securetest");
-        app.setReferencePattern("TomcatRealm", contextRealmName);
-        app.setReferencePattern("RoleDesignateSource", jaccBeanName);
-
-        OnlineUserTransaction userTransaction = new OnlineUserTransaction();
-        app.setAttribute("userTransaction", userTransaction);
-        app.setReferencePattern("TransactionContextManager", tcmName);
-        app.setReferencePattern("TrackedConnectionAssociator", ctcName);
-
-        app.setAttribute("componentContext", Collections.EMPTY_MAP);
-        app.setReferencePattern("Container", containerName);
-        app.setAttribute("kernel", null);
+        ApplicationPolicyConfigurationManager jacc = new ApplicationPolicyConfigurationManager(contextIDToPermissionsMap, principalRoleMap, roleDesignates, cl);
+        jacc.doStart();
 
-        start(app);
+        URL configurationBaseURL = new File("target/var/catalina/webapps/war3/WEB-INF/web.xml").toURL();
+        return setUpInsecureAppContext(new File("target/var/catalina/webapps/war3/").toURI(),
+                configurationBaseURL,
+                securityHolder,
+                jacc,
+                realm,
+                null);
     }
 
-    protected ObjectName setUpSecureAppContext(Map roleDesignates,
-                                               Map principalRoleMap,
-                                               ComponentPermissions componentPermissions,
-                                               DefaultPrincipal defaultPrincipal,
-                                               PermissionCollection checked)
-            throws Exception
-    {
-
-        //Will use the Engine level security
-        ObjectName jaccBeanName = NameFactory.getComponentName(null, null, null, null, "foo", NameFactory.JACC_MANAGER, moduleContext);
-        GBeanData jaccBeanData = new GBeanData(jaccBeanName, ApplicationPolicyConfigurationManager.GBEAN_INFO);
-        Map contextIDToPermissionsMap = new HashMap();
-        contextIDToPermissionsMap.put(POLICY_CONTEXT_ID, componentPermissions);
-        jaccBeanData.setAttribute("contextIdToPermissionsMap", contextIDToPermissionsMap);
-        jaccBeanData.setAttribute("principalRoleMap", principalRoleMap);
-        jaccBeanData.setAttribute("roleDesignates", roleDesignates);
-        start(jaccBeanData);
-
-        SecurityHolder securityHolder = new SecurityHolder();
-        securityHolder.setChecked(checked);
-        securityHolder.setExcluded(componentPermissions.getExcludedPermissions());
-        securityHolder.setPolicyContextID(POLICY_CONTEXT_ID);
-        securityHolder.setDefaultPrincipal(defaultPrincipal);
-        securityHolder.setSecurityRealm("Geronimo");
-        GBeanData app = new GBeanData(webModuleName, TomcatWebAppContext.GBEAN_INFO);
-        app.setAttribute("classLoader", cl);
-        app.setAttribute("webAppRoot", new File("target/var/catalina/webapps/war3/").toURI());
-        app.setAttribute("webClassPath", new URI[]{});
-        app.setAttribute("contextPriorityClassLoader", Boolean.FALSE);
-        app.setAttribute("securityHolder", securityHolder);
-        app.setAttribute("configurationBaseUrl", new File("target/var/catalina/webapps/war3/WEB-INF/web.xml").toURL());
-        app.setAttribute("contextPath", "/securetest");
-        app.setReferencePattern("RoleDesignateSource", jaccBeanName);
-
-        OnlineUserTransaction userTransaction = new OnlineUserTransaction();
-        app.setAttribute("userTransaction", userTransaction);
-        app.setReferencePattern("TransactionContextManager", tcmName);
-        app.setReferencePattern("TrackedConnectionAssociator", ctcName);
-
-        app.setAttribute("componentContext", Collections.EMPTY_MAP);
-        app.setReferencePattern("Container", containerName);
-        start(app);
+    protected void setUpSecurity() throws Exception {
+        String domainName = "demo-properties-realm";
 
-        return webModuleName;
-    }
+        ServerInfo serverInfo = new BasicServerInfo(".");
 
-    protected void setUpSecurity() throws Exception {
+        new SecurityServiceImpl(cl, serverInfo, "org.apache.geronimo.security.jacc.GeronimoPolicyConfigurationFactory", "org.apache.geronimo.security.jacc.GeronimoPolicy", null, null, null, null);
 
-        loginConfigurationName = new ObjectName("geronimo.security:type=LoginConfiguration");
-        loginConfigurationGBean = new GBeanData(loginConfigurationName, GeronimoLoginConfiguration.getGBeanInfo());
-        Set configurations = new HashSet();
-        configurations.add(new ObjectName("geronimo.server:j2eeType=SecurityRealm,*"));
-        configurations.add(new ObjectName("geronimo.server:j2eeType=ConfigurationEntry,*"));
-        loginConfigurationGBean.setReferencePatterns("Configurations", configurations);
-
-        securityServiceName = new ObjectName("geronimo.server:j2eeType=SecurityService");
-        securityServiceGBean = new GBeanData(securityServiceName, SecurityServiceImpl.GBEAN_INFO);
-        securityServiceGBean.setReferencePattern("ServerInfo", serverInfoName);
-        securityServiceGBean.setAttribute("policyConfigurationFactory", "org.apache.geronimo.security.jacc.GeronimoPolicyConfigurationFactory");
-        securityServiceGBean.setAttribute("policyProvider", "org.apache.geronimo.security.jacc.GeronimoPolicy");
-
-        loginServiceName = new ObjectName("test:name=TestLoginService");
-        loginServiceGBean = new GBeanData(loginServiceName, JaasLoginService.GBEAN_INFO);
-        loginServiceGBean.setReferencePattern("Realms", new ObjectName("geronimo.server:j2eeType=SecurityRealm,*"));
-        loginServiceGBean.setAttribute("algorithm", "HmacSHA1");
-        loginServiceGBean.setAttribute("password", "secret");
-
-        propertiesLMName = new ObjectName("geronimo.security:type=LoginModule,name=Geronimo");
-        propertiesLMGBean = new GBeanData(propertiesLMName, LoginModuleGBean.GBEAN_INFO);
-        propertiesLMGBean.setAttribute("loginModuleClass", "org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule");
-        propertiesLMGBean.setAttribute("serverSide", Boolean.TRUE);
         Properties options = new Properties();
         options.setProperty("usersURI", "src/test-resources/data/users.properties");
         options.setProperty("groupsURI", "src/test-resources/data/groups.properties");
-        propertiesLMGBean.setAttribute("options", options);
-        propertiesLMGBean.setAttribute("wrapPrincipals", Boolean.TRUE);
-        propertiesLMGBean.setAttribute("loginDomainName", "geronimo-properties-realm");
-
-        ObjectName testUseName = new ObjectName("geronimo.security:type=LoginModuleUse,name=properties");
-        GBeanData lmUseGBean = new GBeanData(testUseName, JaasLoginModuleUse.getGBeanInfo());
-        lmUseGBean.setAttribute("controlFlag", "REQUIRED");
-        lmUseGBean.setReferencePattern("LoginModule", propertiesLMName);
-
-        propertiesRealmName = new ObjectName("geronimo.server:j2eeType=SecurityRealm,name=geronimo-properties-realm");
-        propertiesRealmGBean = new GBeanData(propertiesRealmName, GenericSecurityRealm.GBEAN_INFO);
-        propertiesRealmGBean.setReferencePattern("ServerInfo", serverInfoName);
-        propertiesRealmGBean.setAttribute("realmName", "Geronimo");
-        propertiesRealmGBean.setReferencePattern("LoginModuleConfiguration", testUseName);
-        propertiesRealmGBean.setReferencePattern("LoginService", loginServiceName);
+
+        LoginModuleGBean loginModule = new LoginModuleGBean("org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule", null, true, true, cl);
+        loginModule.setLoginDomainName(domainName);
+        loginModule.setOptions(options);
+
+        JaasLoginModuleUse loginModuleUse = new JaasLoginModuleUse(loginModule, null, "REQUIRED", null);
+
+        JaasLoginService loginService = new JaasLoginService("HmacSHA1", "secret", cl, null);
+
         PrincipalInfo.PrincipalEditor principalEditor = new PrincipalInfo.PrincipalEditor();
         principalEditor.setAsText("metro,org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal,false");
-        propertiesRealmGBean.setAttribute("defaultPrincipal", principalEditor.getValue());
+        GenericSecurityRealm realm = new GenericSecurityRealm(domainName, loginModuleUse, true, true, (PrincipalInfo) principalEditor.getValue(), serverInfo, cl, null, loginService);
 
-        propertiesRealmName2 = new ObjectName("geronimo.server:j2eeType=SecurityRealm,name=geronimo-properties-realm-2");
-        propertiesRealmGBean2 = new GBeanData(propertiesRealmName2, GenericSecurityRealm.GBEAN_INFO);
-        propertiesRealmGBean2.setReferencePattern("ServerInfo", serverInfoName);
-        propertiesRealmGBean2.setAttribute("realmName", REALM_NAME);
-        propertiesRealmGBean2.setReferencePattern("LoginModuleConfiguration", testUseName);
-        propertiesRealmGBean2.setReferencePattern("LoginService", loginServiceName);
-        PrincipalInfo.PrincipalEditor principalEditor2 = new PrincipalInfo.PrincipalEditor();
-        principalEditor2.setAsText("metro,org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal,false");
-        propertiesRealmGBean2.setAttribute("defaultPrincipal", principalEditor2.getValue());
-
-        start(loginConfigurationGBean);
-        start(securityServiceGBean);
-        start(loginServiceGBean);
-        start(propertiesLMGBean);
-        start(lmUseGBean);
-        start(propertiesRealmGBean);
-        start(propertiesRealmGBean2);
+        loginService.setRealms(Collections.singleton(realm));
+        loginService.doStart();
 
-    }
+        loginConfiguration = new GeronimoLoginConfiguration();
+        loginConfiguration.setConfigurations(Collections.singleton(realm));
+        loginConfiguration.doStart();
 
-    protected void tearDownJAASWebApp() throws Exception {
-        stop(webModuleName);
-        stop(contextRealmName);
     }
 
     protected void tearDownSecurity() throws Exception {
-        stop(propertiesRealmName2);
-        stop(propertiesRealmName);
-        stop(propertiesLMName);
-        stop(loginServiceName);
-        stop(securityServiceName);
-        stop(loginConfigurationName);
-    }
-
-    private void start(GBeanData gbeanData) throws Exception {
-        kernel.loadGBean(gbeanData, cl);
-        kernel.startGBean(gbeanData.getName());
-        if (kernel.getGBeanState(gbeanData.getName()) != State.RUNNING_INDEX) {
-            fail("gbean not started: " + gbeanData.getName());
-        }
-    }
-
-    protected void stop(ObjectName name) throws Exception {
-        kernel.stopGBean(name);
-        kernel.unloadGBean(name);
+        loginConfiguration.doStop();
     }
 
     protected void setUp(String realmClass) throws Exception {
         cl = this.getClass().getClassLoader();
-        containerName = NameFactory.getWebComponentName(null, null, null, null, "tomcatContainer", "WebResource", moduleContext);
-        connectorName = NameFactory.getWebComponentName(null, null, null, null, "tomcatConnector", "WebResource", moduleContext);
-        if (realmClass != null)
-            realmName = NameFactory.getWebComponentName(null, null, null, null, "tomcatRealm", "WebResource", moduleContext);
-        engineName = NameFactory.getWebComponentName(null, null, null, null, "tomcatEngine", "WebResource", moduleContext);
-        hostName = NameFactory.getWebComponentName(null, null, null, null, "tomcatHost", "WebResource", moduleContext);
-        webModuleName = NameFactory.getModuleName(null, null, null, null, "testModule", moduleContext);
-
-        tmName = NameFactory.getComponentName(null, null, null, null, "TransactionManager", NameFactory.TRANSACTION_MANAGER, moduleContext);
-        tcmName = NameFactory.getComponentName(null, null, null, null, "TransactionContextManager", NameFactory.TRANSACTION_CONTEXT_MANAGER, moduleContext);
-
-        ctcName = new ObjectName("geronimo.test:role=ConnectionTrackingCoordinator");
-
-        kernel = KernelFactory.newInstance().createKernel("test.kernel");
-        kernel.boot();
-
-        //ServerInfo
-        serverInfoName = new ObjectName("geronimo.system:role=ServerInfo");
-        serverInfoGBean = new GBeanData(serverInfoName, BasicServerInfo.GBEAN_INFO);
-        serverInfoGBean.setAttribute("baseDirectory", ".");
-
-        start(serverInfoGBean);
-
-        //Default Realm
-        Map initParams = new HashMap();
 
+        RealmGBean realm = null;
         if (realmClass != null) {
+            Map initParams = new HashMap();
             initParams.put("userClassNames", "org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal");
             initParams.put("roleClassNames", "org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal");
-            realm = new GBeanData(realmName, RealmGBean.GBEAN_INFO);
-            realm.setAttribute("className", realmClass);
-            realm.setAttribute("initParams", initParams);
-            start(realm);
+            realm = new RealmGBean(realmClass, initParams);
+            realm.doStart();
         }
 
         //Default Host
-        initParams.clear();
+        Map initParams = new HashMap();
         initParams.put("workDir", "work");
         initParams.put("name", "localhost");
         initParams.put("appBase", "");
-        host = new GBeanData(hostName, HostGBean.GBEAN_INFO);
-        host.setAttribute("className", "org.apache.catalina.core.StandardHost");
-        host.setAttribute("initParams", initParams);
-        start(host);
 
+        HostGBean host = new HostGBean("org.apache.catalina.core.StandardHost", initParams, null, realm, null, null, null);
         //Default Engine
-        initParams.clear();
-        initParams.put("name", "Geronimo");
-        engine = new GBeanData(engineName, EngineGBean.GBEAN_INFO);
-        engine.setAttribute("className", "org.apache.geronimo.tomcat.TomcatEngine");
-        engine.setAttribute("initParams", initParams);
-        engine.setReferencePattern("DefaultHost", hostName);
-        if (realmClass != null)
-            engine.setReferencePattern("RealmGBean", realmName);
-        engine.setReferencePattern("Hosts", hostName);
-        start(engine);
-
-        // Need to override the constructor for unit tests
-        container = new GBeanData(containerName, TomcatContainer.GBEAN_INFO);
-        container.setAttribute("classLoader", cl);
-        container.setAttribute("catalinaHome", "target/var/catalina");
-        container.setReferencePattern("EngineGBean", engineName);
-        container.setReferencePattern("ServerInfo", serverInfoName);
-
-        connector = new GBeanData(connectorName, ConnectorGBean.GBEAN_INFO);
-        connector.setAttribute("port", new Integer(8181));
-        connector.setAttribute("host", "localhost");
-        connector.setAttribute("name", "HTTP");
-        connector.setReferencePattern("TomcatContainer", containerName);
-
-        start(container);
-        start(connector);
-
-        tm = new GBeanData(tmName, TransactionManagerImplGBean.GBEAN_INFO);
-        Set patterns = new HashSet();
-        patterns.add(ObjectName.getInstance("geronimo.server:j2eeType=JCAManagedConnectionFactory,*"));
-        tm.setAttribute("defaultTransactionTimeoutSeconds", new Integer(10));
-        tm.setReferencePatterns("ResourceManagers", patterns);
-        start(tm);
-        tcm = new GBeanData(tcmName, TransactionContextManagerGBean.GBEAN_INFO);
-        tcm.setReferencePattern("TransactionManager", tmName);
-        start(tcm);
-        ctc = new GBeanData(ctcName, ConnectionTrackingCoordinatorGBean.GBEAN_INFO);
-        start(ctc);
+        initParams = Collections.singletonMap("name", "Geronimo");
+
+        EngineGBean engine = new EngineGBean("org.apache.geronimo.tomcat.TomcatEngine",
+                initParams,
+                host,
+                Collections.singleton(host),
+                realm,
+                null,
+                null,
+                null);
+        engine.doStart();
+
+        ServerInfo serverInfo = new BasicServerInfo(".");
+        container = new TomcatContainer(cl, "target/var/catalina", engine, serverInfo, null);
+        container.doStart();
+
+        connector = new ConnectorGBean("HTTP", null, "localhost", 8181, container);
+        connector.doStart();
+
+        TransactionManagerImpl tm = new TransactionManagerImpl(10, null, null, Collections.EMPTY_LIST);
+        transactionContextManager = new TransactionContextManager(tm, tm);
+        connectionTrackingCoordinator = new ConnectionTrackingCoordinator();
     }
 
     protected void tearDown() throws Exception {
-        stop(ctcName);
-        stop(tmName);
-        if (realmName != null)
-            stop(realmName);
-        stop(hostName);
-        stop(engineName);
-        stop(connectorName);
-        stop(containerName);
-        stop(serverInfoName);
-        kernel.shutdown();
+        connector.doStop();
     }
 }

Modified: geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java?rev=387050&r1=387049&r2=387050&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java (original)
+++ geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java Sun Mar 19 14:43:00 2006
@@ -17,6 +17,7 @@
 package org.apache.geronimo.tomcat;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
@@ -28,7 +29,12 @@
 public class ApplicationTest extends AbstractWebModuleTest {
 
     public void testApplication() throws Exception {
-        setUpInsecureAppContext();
+        setUpInsecureAppContext(new File("target/var/catalina/webapps/war1/").toURI(),
+                new File("target/var/catalina/webapps/war1/WEB-INF/web.xml").toURL(),
+                null,
+                null,
+                null,
+                null);
 
         HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/test/hello.txt")
                 .openConnection();

Modified: geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java?rev=387050&r1=387049&r2=387050&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java (original)
+++ geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java Sun Mar 19 14:43:00 2006
@@ -21,81 +21,21 @@
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Properties;
-import java.util.ArrayList;
-import java.util.Set;
-import javax.management.ObjectName;
 
-import junit.framework.TestCase;
-import sun.misc.BASE64Encoder;
-
-import org.apache.geronimo.gbean.GBeanData;
-import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
-import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
-import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.KernelFactory;
-import org.apache.geronimo.kernel.management.State;
-import org.apache.geronimo.security.SecurityServiceImpl;
-import org.apache.geronimo.security.deploy.PrincipalInfo;
-import org.apache.geronimo.security.jaas.GeronimoLoginConfiguration;
-import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
-import org.apache.geronimo.security.jaas.LoginModuleGBean;
-import org.apache.geronimo.security.jaas.server.JaasLoginService;
-import org.apache.geronimo.security.realm.GenericSecurityRealm;
-import org.apache.geronimo.system.serverinfo.BasicServerInfo;
 import org.apache.geronimo.tomcat.app.MockWebServiceContainer;
-import org.apache.geronimo.webservices.WebServiceContainer;
-
-import org.apache.geronimo.gbean.ReferenceCollection;
-import org.apache.geronimo.gbean.ReferenceCollectionEvent;
-import org.apache.geronimo.gbean.ReferenceCollectionListener;
+import sun.misc.BASE64Encoder;
 
 
 /**
  * @version $Rev$ $Date$
  */
-public class ContainerTest extends TestCase {
-    private ClassLoader cl = this.getClass().getClassLoader();
-    private Kernel kernel;
-    private GBeanData container;
-    private ObjectName containerName;
-    private Set containerPatterns;
-    private ObjectName connectorName;
-    private GBeanData connector;
-    private ObjectName engineName;
-    private GBeanData engine;
-    private ObjectName hostName;
-    private GBeanData host;
-    private J2eeContext moduleContext = new J2eeContextImpl("tomcat.test", "test", "null", NameFactory.WEB_MODULE, "tomcatTest", null, null);
-    private ObjectName serverInfoName;
-    private GBeanData serverInfoGBean;
-    private GBeanData securityServiceGBean;
-    private ObjectName securityServiceName;
-    private ObjectName loginServiceName;
-    private GBeanData loginServiceGBean;
-    private GBeanData loginConfigurationGBean;
-    private ObjectName loginConfigurationName;
-    private GBeanData propertiesLMGBean;
-    private ObjectName propertiesLMName;
-    private ObjectName propertiesRealmName;
-    private GBeanData propertiesRealmGBean;
-
+public class ContainerTest extends AbstractWebModuleTest {
 
     public void testWebServiceHandler() throws Exception {
 
-        setUpWeb();
-
-        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(connectorName));
-        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(containerName));
-
         String contextPath = "/foo/webservice.ws";
         MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer();
-        kernel.invoke(containerName, "addWebService", new Object[]{contextPath, null, webServiceInvoker, null, null, null, null, cl}, new String[]{String.class.getName(), String[].class.getName(), WebServiceContainer.class.getName(), String.class.getName(), String.class.getName(), String.class.getName(), String.class.getName(), ClassLoader.class.getName()});
-
+        container.addWebService(contextPath, null, webServiceInvoker, null, null, null,null, cl);
         HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181" + contextPath).openConnection();
         try {
             BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
@@ -104,7 +44,7 @@
         } finally {
             connection.disconnect();
         }
-        kernel.invoke(containerName, "removeWebService", new Object[]{contextPath}, new String[]{String.class.getName()});
+        container.removeWebService(contextPath);
         connection = (HttpURLConnection) new URL("http://localhost:8181" + contextPath).openConnection();
         try {
             connection.getInputStream();
@@ -115,21 +55,15 @@
             connection.disconnect();
         }
 
-        tearDownWeb();
     }
 
     public void testSecureWebServiceHandler() throws Exception {
 
-        setUpWeb();
-
-        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(connectorName));
-        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(containerName));
-
         setUpSecurity();
 
         String contextPath = "/foo/webservice.ws";
         MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer();
-        kernel.invoke(containerName, "addWebService", new Object[]{contextPath, null, webServiceInvoker, "Geronimo", "Geronimo", "NONE", "BASIC", cl}, new String[]{String.class.getName(), String[].class.getName(), WebServiceContainer.class.getName(), String.class.getName(), String.class.getName(), String.class.getName(), String.class.getName(), ClassLoader.class.getName()});
+        container.addWebService(contextPath, null, webServiceInvoker, securityRealmName, securityRealmName, "NONE", "BASIC", cl);
 
         //Veryify its secured
         HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181" + contextPath).openConnection();
@@ -153,7 +87,7 @@
         } finally {
             connection.disconnect();
         }
-        kernel.invoke(containerName, "removeWebService", new Object[]{contextPath}, new String[]{String.class.getName()});
+        container.removeWebService(contextPath);
         connection = (HttpURLConnection) new URL("http://localhost:8181" + contextPath).openConnection();
         try {
             connection.getInputStream();
@@ -164,186 +98,11 @@
             connection.disconnect();
         }
 
-        tearDownSecurity();
-        tearDownWeb();
-    }
-
-    private void start(GBeanData instance) throws Exception {
-        kernel.loadGBean(instance, cl);
-        kernel.startGBean(instance.getName());
-    }
-
-    private void stop(ObjectName name) throws Exception {
-        kernel.stopGBean(name);
-        kernel.unloadGBean(name);
     }
 
-    protected void setUpSecurity() throws Exception {
-
-        loginConfigurationName = new ObjectName("geronimo.security:type=LoginConfiguration");
-        loginConfigurationGBean = new GBeanData(loginConfigurationName, GeronimoLoginConfiguration.getGBeanInfo());
-        Set configurations = new HashSet();
-        configurations.add(new ObjectName("geronimo.server:j2eeType=SecurityRealm,*"));
-        configurations.add(new ObjectName("geronimo.server:j2eeType=ConfigurationEntry,*"));
-        loginConfigurationGBean.setReferencePatterns("Configurations", configurations);
-
-        securityServiceName = new ObjectName("geronimo.server:j2eeType=SecurityService");
-        securityServiceGBean = new GBeanData(securityServiceName, SecurityServiceImpl.GBEAN_INFO);
-        securityServiceGBean.setReferencePattern("ServerInfo", serverInfoName);
-        securityServiceGBean.setAttribute("policyConfigurationFactory", "org.apache.geronimo.security.jacc.GeronimoPolicyConfigurationFactory");
-        securityServiceGBean.setAttribute("policyProvider", "org.apache.geronimo.security.jacc.GeronimoPolicy");
-
-        loginServiceName = new ObjectName("test:name=TestLoginService");
-        loginServiceGBean = new GBeanData(loginServiceName, JaasLoginService.GBEAN_INFO);
-        loginServiceGBean.setReferencePattern("Realms", new ObjectName("geronimo.server:j2eeType=SecurityRealm,*"));
-        loginServiceGBean.setAttribute("algorithm", "HmacSHA1");
-        loginServiceGBean.setAttribute("password", "secret");
-
-        propertiesLMName = new ObjectName("geronimo.security:type=LoginModule,name=Geronimo");
-        propertiesLMGBean = new GBeanData(propertiesLMName, LoginModuleGBean.GBEAN_INFO);
-        propertiesLMGBean.setAttribute("loginModuleClass", "org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule");
-        propertiesLMGBean.setAttribute("serverSide", Boolean.TRUE);
-        Properties options = new Properties();
-        options.setProperty("usersURI", "src/test-resources/data/users.properties");
-        options.setProperty("groupsURI", "src/test-resources/data/groups.properties");
-        propertiesLMGBean.setAttribute("options", options);
-        propertiesLMGBean.setAttribute("loginDomainName", "geronimo-properties-realm");
-
-        ObjectName testUseName = new ObjectName("geronimo.security:type=LoginModuleUse,name=properties");
-        GBeanData lmUseGBean = new GBeanData(testUseName, JaasLoginModuleUse.getGBeanInfo());
-        lmUseGBean.setAttribute("controlFlag", "REQUIRED");
-        lmUseGBean.setReferencePattern("LoginModule", propertiesLMName);
-
-        propertiesRealmName = new ObjectName("geronimo.server:j2eeType=SecurityRealm,name=geronimo-properties-realm");
-        propertiesRealmGBean = new GBeanData(propertiesRealmName, GenericSecurityRealm.GBEAN_INFO);
-        propertiesRealmGBean.setReferencePattern("ServerInfo", serverInfoName);
-        propertiesRealmGBean.setAttribute("realmName", "Geronimo");
-        propertiesRealmGBean.setReferencePattern("LoginModuleConfiguration", testUseName);
-        propertiesRealmGBean.setReferencePattern("LoginService", loginServiceName);
-        PrincipalInfo.PrincipalEditor principalEditor = new PrincipalInfo.PrincipalEditor();
-        principalEditor.setAsText("metro,org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal,false");
-        propertiesRealmGBean.setAttribute("defaultPrincipal", principalEditor.getValue());
-
-        start(loginConfigurationGBean);
-        start(securityServiceGBean);
-        start(loginServiceGBean);
-        start(propertiesLMGBean);
-        start(lmUseGBean);
-        start(propertiesRealmGBean);
-
-    }
-
-    protected void tearDownSecurity() throws Exception {
-        stop(propertiesRealmName);
-        stop(propertiesLMName);
-        stop(loginServiceName);
-        stop(securityServiceName);
-        stop(loginConfigurationName);
-    }
-
-    private void setUpWeb() throws Exception {
-        containerName = NameFactory.getWebComponentName(null, null, null, null, "tomcatContainer", "WebResource", moduleContext);
-        connectorName = NameFactory.getWebComponentName(null, null, null, null, "tomcatConnector", "WebResource", moduleContext);
-        containerPatterns = new HashSet();
-        containerPatterns.add(containerName);
-        connectorName = new ObjectName("geronimo.tomcat:role=Connector");
-        connectorName = NameFactory.getWebComponentName(null, null, null, null, "tomcatConnector", "WebResource", moduleContext);
-        engineName = NameFactory.getWebComponentName(null, null, null, null, "tomcatEngine", "WebResource", moduleContext);
-        hostName = NameFactory.getWebComponentName(null, null, null, null, "tomcatHost", "WebResource", moduleContext);
-        kernel = KernelFactory.newInstance().createKernel("test.kernel");
-        kernel.boot();
-
-        //ServerInfo
-        serverInfoName = new ObjectName("geronimo.system:role=ServerInfo");
-        serverInfoGBean = new GBeanData(serverInfoName, BasicServerInfo.GBEAN_INFO);
-        serverInfoGBean.setAttribute("baseDirectory", ".");
-        start(serverInfoGBean);
-
-        Map initParams = new HashMap();
-
-        //Default Host
-        initParams.clear();
-        initParams.put("workDir", "work");
-        initParams.put("name", "localhost");
-        initParams.put("appBase", "");
-        host = new GBeanData(hostName, HostGBean.GBEAN_INFO);
-        host.setAttribute("className", "org.apache.catalina.core.StandardHost");
-        host.setAttribute("initParams", initParams);
-        start(host);
-
-        //Default Engine
-        ReferenceCollection hosts = new TestReferenceCollection();
-        hosts.add(host);
-
-        initParams.clear();
-        initParams.put("name", "Geronimo");
-        engine = new GBeanData(engineName, EngineGBean.GBEAN_INFO);
-        engine.setAttribute("className", "org.apache.geronimo.tomcat.TomcatEngine");
-        engine.setReferencePattern("DefaultHost", hostName);
-        engine.setAttribute("initParams", initParams);
-        engine.setReferencePattern("Hosts", hostName);
-        start(engine);
-
-        container = new GBeanData(containerName, TomcatContainer.GBEAN_INFO);
-        container.setAttribute("classLoader", cl);
-        container.setAttribute("catalinaHome", "target/var/catalina");
-        container.setReferencePattern("EngineGBean", engineName);
-        container.setReferencePattern("ServerInfo", serverInfoName);
-        start(container);
-
-        connector = new GBeanData(connectorName, ConnectorGBean.GBEAN_INFO);
-        connector.setAttribute("name", "HTTP");
-        connector.setAttribute("port", new Integer(8181));
-        connector.setReferencePattern("TomcatContainer", containerName);
-        start(connector);
-    }
-
-    private void tearDownWeb() throws Exception {
-        stop(connectorName);
-        stop(containerName);
-        stop(hostName);
-        stop(engineName);
-        stop(serverInfoName);
-        kernel.shutdown();
-    }
-
-   private class TestReferenceCollection extends ArrayList implements ReferenceCollection {
-
-       ReferenceCollectionListener referenceCollectionListener;
-
-       public void addReferenceCollectionListener(ReferenceCollectionListener listener) {
-           this.referenceCollectionListener = listener;
-       }
-
-       public void removeReferenceCollectionListener(ReferenceCollectionListener listener) {
-           this.referenceCollectionListener = null;
-       }
-
-       public boolean add(Object o) {
-           boolean result = super.add(o);
-           if (referenceCollectionListener != null) {
-               referenceCollectionListener.memberAdded(new ReferenceCollectionEvent(null, o));
-           }
-           return result;
-       }
-
-       public boolean remove(Object o) {
-           boolean result = super.remove(o);
-           if (referenceCollectionListener != null) {
-               referenceCollectionListener.memberRemoved(new ReferenceCollectionEvent(null, o));
-           }
-           return result;
-       }
-
-        public ObjectName[] getMemberObjectNames() {
-            ObjectName names[] = new ObjectName[this.size()];
-            for(int i=0; i < this.size(); i++){
-                GBeanData data = (GBeanData)this.get(i);
-                names[i] = data.getName();
-            }
-            return names;
-    }
 
+    protected void setUp() throws Exception {
+        super.setUp(null);
    }
 
 }

Modified: geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/JAASSecurityTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/JAASSecurityTest.java?rev=387050&r1=387049&r2=387050&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/JAASSecurityTest.java (original)
+++ geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/JAASSecurityTest.java Sun Mar 19 14:43:00 2006
@@ -20,8 +20,16 @@
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.util.Map;
+import java.util.HashMap;
+import java.security.PermissionCollection;
+import java.security.Permissions;
+
 import javax.management.ObjectName;
 
+import org.apache.geronimo.tomcat.util.SecurityHolder;
+import org.apache.geronimo.security.jacc.ComponentPermissions;
+
 /**
  * Tests the JAAS security for Tomcat
  *
@@ -36,7 +44,7 @@
         startWebApp();
 
         //Begin the test
-        HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/securetest/protected/hello.txt").openConnection();
+        HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/test/protected/hello.txt").openConnection();
         connection.setInstanceFollowRedirects(false);
         assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
         //Be sure we have been given the login page
@@ -46,7 +54,7 @@
 
         String cookie = connection.getHeaderField("Set-Cookie");
         cookie = cookie.substring(0, cookie.lastIndexOf(';'));
-        String location = "http://localhost:8181/securetest/protected/j_security_check?j_username=alan&j_password=starcraft";
+        String location = "http://localhost:8181/test/protected/j_security_check?j_username=alan&j_password=starcraft";
         connection = (HttpURLConnection) new URL(location).openConnection();
         connection.setRequestMethod("POST");
         connection.setRequestProperty("Cookie", cookie);
@@ -68,7 +76,7 @@
         startWebApp();
 
         //Begin the test
-        HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/securetest/protected/hello.txt").openConnection();
+        HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/test/protected/hello.txt").openConnection();
         connection.setInstanceFollowRedirects(false);
         assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
 
@@ -79,7 +87,7 @@
 
         String cookie = connection.getHeaderField("Set-Cookie");
         cookie = cookie.substring(0, cookie.lastIndexOf(';'));
-        String location = "http://localhost:8181/securetest/protected/j_security_check?j_username=alan&j_password=basspassword";
+        String location = "http://localhost:8181/test/protected/j_security_check?j_username=alan&j_password=basspassword";
 
         connection = (HttpURLConnection) new URL(location).openConnection();
         connection.setRequestMethod("POST");
@@ -107,7 +115,7 @@
         Thread.sleep(5000);
 
         //Begin the test
-        HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/securetest/protected/hello.txt").openConnection();
+        HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/test/protected/hello.txt").openConnection();
         connection.setInstanceFollowRedirects(false);
         assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
 
@@ -118,16 +126,16 @@
 
         String cookie = connection.getHeaderField("Set-Cookie");
         cookie = cookie.substring(0, cookie.lastIndexOf(';'));
-        String location = "http://localhost:8181/securetest/protected/j_security_check?j_username=izumi&j_password=violin";
+        String location = "http://localhost:8181/test/protected/j_security_check?j_username=izumi&j_password=violin";
 
         connection = (HttpURLConnection) new URL(location).openConnection();
         connection.setRequestMethod("POST");
-        connection.setRequestProperty("Referer","http://localhost:8181/securetest/auth/logon.html?param=test");
+        connection.setRequestProperty("Referer","http://localhost:8181/test/auth/logon.html?param=test");
         connection.setRequestProperty("Cookie", cookie);
         connection.setInstanceFollowRedirects(false);
         assertEquals(HttpURLConnection.HTTP_MOVED_TEMP, connection.getResponseCode());
 
-        connection = (HttpURLConnection) new URL("http://localhost:8181/securetest/protected/hello.txt").openConnection();
+        connection = (HttpURLConnection) new URL("http://localhost:8181/test/protected/hello.txt").openConnection();
         connection.setRequestProperty("Cookie", cookie);
         connection.setInstanceFollowRedirects(false);
         reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
@@ -140,16 +148,34 @@
     }
 
     protected void startWebApp() throws Exception {
-        setUpJAASSecureAppContext();
+        //Set a context level Realm and ignore the Engine level to test that
+        //the override along with a Security Realm Name set overrides the Engine
+        Map initParams = new HashMap();
+        initParams.put("userClassNames", "org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal");
+        initParams.put("roleClassNames", "org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal");
+
+        RealmGBean realm = new RealmGBean("org.apache.geronimo.tomcat.realm.TomcatJAASRealm", initParams);
+        realm.doStart();
+
+        PermissionCollection excludedPermissions = new Permissions();
+        PermissionCollection uncheckedPermissions = new Permissions();
+        ComponentPermissions componentPermissions = new ComponentPermissions(excludedPermissions, uncheckedPermissions, new HashMap());
+        //Force a new realm name and ignore the application name
+        SecurityHolder securityHolder = new SecurityHolder();
+        securityHolder.setSecurityRealm(securityRealmName);
+        setUpSecureAppContext(new HashMap(),
+                new HashMap(),
+                componentPermissions,
+                realm,
+                securityHolder);
     }
 
     protected void stopWebApp() throws Exception {
-        tearDownJAASWebApp();
     }
 
     protected void setUp() throws Exception {
         super.setUp("org.apache.geronimo.tomcat.realm.TomcatJAASRealm");
-        setUpSecurity();        
+        setUpSecurity();
    }
 
     protected void tearDown() throws Exception {

Modified: geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java?rev=387050&r1=387049&r2=387050&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java (original)
+++ geronimo/branches/1.1/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java Sun Mar 19 14:43:00 2006
@@ -28,6 +28,7 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+
 import javax.management.ObjectName;
 import javax.security.jacc.WebResourcePermission;
 import javax.security.jacc.WebUserDataPermission;
@@ -38,6 +39,7 @@
 import org.apache.geronimo.security.deploy.Security;
 import org.apache.geronimo.security.deployment.SecurityBuilder;
 import org.apache.geronimo.security.jacc.ComponentPermissions;
+import org.apache.geronimo.tomcat.util.SecurityHolder;
 
 
 /**
@@ -92,10 +94,10 @@
         ComponentPermissions componentPermissions = new ComponentPermissions(excludedPermissions, uncheckedPermissions, rolePermissions);
 
         startWebApp(roleDesignates, principalRoleMap, componentPermissions,
-                    defaultPrincipal, permissions);
+                defaultPrincipal, permissions);
 
         //Begin the test
-        HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/securetest/protected/hello.txt").openConnection();
+        HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/test/protected/hello.txt").openConnection();
         connection.setInstanceFollowRedirects(false);
         assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
 
@@ -106,16 +108,16 @@
 
         String cookie = connection.getHeaderField("Set-Cookie");
         cookie = cookie.substring(0, cookie.lastIndexOf(';'));
-        String location = "http://localhost:8181/securetest/protected/j_security_check?j_username=alan&j_password=starcraft";
+        String location = "http://localhost:8181/test/protected/j_security_check?j_username=alan&j_password=starcraft";
 
         connection = (HttpURLConnection) new URL(location).openConnection();
         connection.setRequestMethod("POST");
-        connection.setRequestProperty("Referer","http://localhost:8181/securetest/auth/logon.html?param=test");
+        connection.setRequestProperty("Referer", "http://localhost:8181/test/auth/logon.html?param=test");
         connection.setRequestProperty("Cookie", cookie);
         connection.setInstanceFollowRedirects(false);
         assertEquals(HttpURLConnection.HTTP_MOVED_TEMP, connection.getResponseCode());
 
-        connection = (HttpURLConnection) new URL("http://localhost:8181/securetest/protected/hello.txt").openConnection();
+        connection = (HttpURLConnection) new URL("http://localhost:8181/test/protected/hello.txt").openConnection();
         connection.setRequestProperty("Cookie", cookie);
         connection.setInstanceFollowRedirects(false);
         reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
@@ -125,7 +127,7 @@
         connection.disconnect();
 
         //Now lets try it with izumi
-        connection = (HttpURLConnection) new URL("http://localhost:8181/securetest/protected/hello.txt").openConnection();
+        connection = (HttpURLConnection) new URL("http://localhost:8181/test/protected/hello.txt").openConnection();
         connection.setInstanceFollowRedirects(false);
         assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
 
@@ -137,7 +139,7 @@
         assertEquals("<!-- Login Page -->", reader.readLine());
         reader.close();
 
-        location = "http://localhost:8181/securetest/protected/j_security_check?j_username=izumi&j_password=violin";
+        location = "http://localhost:8181/test/protected/j_security_check?j_username=izumi&j_password=violin";
 
         connection = (HttpURLConnection) new URL(location).openConnection();
         connection.setRequestMethod("POST");
@@ -146,7 +148,7 @@
         assertEquals(HttpURLConnection.HTTP_MOVED_TEMP, connection.getResponseCode());
 
         try {
-            connection = (HttpURLConnection) new URL("http://localhost:8181/securetest/protected/hello.txt").openConnection();
+            connection = (HttpURLConnection) new URL("http://localhost:8181/test/protected/hello.txt").openConnection();
             connection.setRequestProperty("Cookie", cookie);
             connection.setInstanceFollowRedirects(false);
             reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
@@ -162,22 +164,30 @@
         stopWebApp();
     }
 
-    protected void startWebApp(
+    protected TomcatWebAppContext startWebApp(
             Map roleDesignates,
             Map principalRoleMap,
             ComponentPermissions componentPermissions,
             DefaultPrincipal defaultPrincipal,
-            PermissionCollection checked) throws Exception
-    {
+            PermissionCollection checked) throws Exception {
 
-        appName = setUpSecureAppContext(roleDesignates, principalRoleMap,
-                                        componentPermissions, defaultPrincipal, checked);
+        SecurityHolder securityHolder = new SecurityHolder();
+        securityHolder.setSecurity(true);
+        securityHolder.setChecked(checked);
+        securityHolder.setExcluded(componentPermissions.getExcludedPermissions());
+        securityHolder.setPolicyContextID(POLICY_CONTEXT_ID);
+        securityHolder.setDefaultPrincipal(defaultPrincipal);
+        securityHolder.setSecurityRealm(securityRealmName);
+        return setUpSecureAppContext(roleDesignates,
+                principalRoleMap,
+                componentPermissions,
+                null,
+                securityHolder);
 
 
     }
 
     protected void stopWebApp() throws Exception {
-        stop(appName);
     }
 
     public void buildPrincipalRoleMap(Security security, Map roleDesignates, Map principalRoleMap) {