geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r386763 - in /geronimo/branches/1.1/modules: jetty/src/java/org/apache/geronimo/jetty/ jetty/src/test/org/apache/geronimo/jetty/ security/src/java/org/apache/geronimo/security/jaas/ security/src/java/org/apache/geronimo/security/jaas/client...
Date Fri, 17 Mar 2006 23:15:30 GMT
Author: djencks
Date: Fri Mar 17 15:15:27 2006
New Revision: 386763

URL: http://svn.apache.org/viewcvs?rev=386763&view=rev
Log:
Modify jetty tests to not use a kernel.  Modify some bits of security to also not require
a kernel.

Modified:
    geronimo/branches/1.1/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
    geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/AbstractWebModuleTest.java
    geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java
    geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ContainerTest.java
    geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/SecurityTest.java
    geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/GeronimoLoginConfiguration.java
    geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/client/JaasLoginCoordinator.java
    geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/server/JaasLoginService.java
    geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/realm/GenericSecurityRealm.java
    geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/realm/providers/PropertiesFileLoginModule.java

Modified: geronimo/branches/1.1/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java?rev=386763&r1=386762&r2=386763&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
(original)
+++ geronimo/branches/1.1/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
Fri Mar 17 15:15:27 2006
@@ -204,8 +204,10 @@
         this.server = server;
         this.application = application;
         this.objectName = objectName;
-        ObjectName myObjectName = JMXUtil.getObjectName(objectName);
-        verifyObjectName(myObjectName);
+        if (objectName != null) {
+            ObjectName myObjectName = JMXUtil.getObjectName(objectName);
+            verifyObjectName(myObjectName);
+        }
 
         this.jettyContainer = jettyContainer;
 

Modified: geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/AbstractWebModuleTest.java?rev=386763&r1=386762&r2=386763&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/AbstractWebModuleTest.java
(original)
+++ geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/AbstractWebModuleTest.java
Fri Mar 17 15:15:27 2006
@@ -17,15 +17,8 @@
 package org.apache.geronimo.jetty;
 
 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.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
 import org.apache.geronimo.jetty.connector.HTTPConnector;
-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.DefaultPrincipal;
 import org.apache.geronimo.security.deploy.PrincipalInfo;
@@ -35,20 +28,21 @@
 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.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;
+import org.mortbay.http.Authenticator;
 import org.mortbay.jetty.servlet.FormAuthenticator;
 
-import javax.management.ObjectName;
-import java.io.File;
 import java.net.URI;
+import java.net.URL;
 import java.security.PermissionCollection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -58,41 +52,16 @@
  * @version $Rev$ $Date$
  */
 public class AbstractWebModuleTest extends TestCase {
-    protected Kernel kernel;
-    private GBeanData container;
-    private ObjectName containerName;
-    private ObjectName connectorName;
-    private GBeanData connector;
-    private ObjectName webModuleName;
-    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("jetty.test", "test", "null",
NameFactory.WEB_MODULE, "jettyTest", null, null);
-    private GBeanData loginConfigurationGBean;
-    protected ObjectName loginConfigurationName;
-    private GBeanData securityServiceGBean;
-    protected ObjectName securityServiceName;
-    private ObjectName loginServiceName;
-    private GBeanData loginServiceGBean;
-    protected GBeanData propertiesLMGBean;
-    protected ObjectName propertiesLMName;
-    protected ObjectName propertiesRealmName;
-    private GBeanData propertiesRealmGBean;
-    private ObjectName serverInfoName;
-    private GBeanData serverInfoGBean;
+    protected ClassLoader cl;
     protected final static String securityRealmName = "demo-properties-realm";
+    private HTTPConnector connector;
+    protected JettyContainerImpl container;
+    private TransactionContextManager transactionContextManager;
+    private ConnectionTrackingCoordinator connectionTrackingCoordinator;
+    private URL configurationBaseURL;
 
-    public void testDummy() throws Exception {
-    }
 
-    protected void setUpStaticContentServlet() throws Exception {
-        GBeanData staticContentServletGBeanData = new GBeanData(JettyServletHolder.GBEAN_INFO);
-        staticContentServletGBeanData.setAttribute("servletName", "default");
-        staticContentServletGBeanData.setAttribute("servletClass", "org.mortbay.jetty.servlet.Default");
+    protected void setUpStaticContentServlet(JettyServletRegistration webModule) throws Exception
{
         Map staticContentServletInitParams = new HashMap();
         staticContentServletInitParams.put("acceptRanges", "true");
         staticContentServletInitParams.put("dirAllowed", "true");
@@ -100,200 +69,139 @@
         staticContentServletInitParams.put("delAllowed", "false");
         staticContentServletInitParams.put("redirectWelcome", "false");
         staticContentServletInitParams.put("minGzipLength", "8192");
-        staticContentServletGBeanData.setAttribute("initParams", staticContentServletInitParams);
-        staticContentServletGBeanData.setAttribute("loadOnStartup", new Integer(0));
-        staticContentServletGBeanData.setAttribute("servletMappings", Collections.singleton(new
String("/")));
-        ObjectName staticContentServletObjectName = NameFactory.getComponentName(null, null,
null, NameFactory.WEB_MODULE, null, (String) staticContentServletGBeanData.getAttribute("servletName"),
NameFactory.SERVLET, moduleContext);
-        staticContentServletGBeanData.setName(staticContentServletObjectName);
-        staticContentServletGBeanData.setReferencePattern("JettyServletRegistration", webModuleName);
-
-        start(staticContentServletGBeanData);
-    }
 
-    protected void setUpInsecureAppContext() throws Exception {
-        GBeanData app = new GBeanData(webModuleName, JettyWebAppContext.GBEAN_INFO);
-        app.setAttribute("uri", URI.create("war1/"));
-        app.setAttribute("componentContext", Collections.EMPTY_MAP);
-        OnlineUserTransaction userTransaction = new OnlineUserTransaction();
-        app.setAttribute("userTransaction", userTransaction);
-        //we have no classes or libs.
-        app.setAttribute("configurationBaseUrl", new File("src/test-resources/deployables/").toURL());
-        app.setReferencePattern("TransactionContextManager", tcmName);
-        app.setReferencePattern("TrackedConnectionAssociator", ctcName);
-        app.setReferencePattern("JettyContainer", containerName);
+        new JettyServletHolder("test:name=staticservlet",
+                "default",
+                "org.mortbay.jetty.servlet.Default",
+                null,
+                staticContentServletInitParams,
+                null,
+                Collections.singleton("/"),
+                null,
+                null,
+                null,
+                webModule);
 
-        app.setAttribute("contextPath", "/test");
+    }
 
-        start(app);
+    protected JettyWebAppContext setUpAppContext(String realmName, String securityRealmName,
Authenticator authenticator, String policyContextId, RoleDesignateSource roleDesignateSource,
PermissionCollection excludedPermissions, DefaultPrincipal defaultPrincipal, PermissionCollection
checkedPermissions, String uriString) throws Exception {
+
+        JettyWebAppContext app = new JettyWebAppContext(null,
+                null,
+                URI.create(uriString),
+                null,
+                null,
+                Collections.EMPTY_MAP,
+                new OnlineUserTransaction(),
+                cl,
+                configurationBaseURL,
+                null,
+                null,
+                "context",
+                null,
+                null,
+                false,
+                null,
+                null,
+                null,
+                null,
+                authenticator,
+                realmName,
+                null,
+                0,
+                policyContextId,
+                securityRealmName,
+                defaultPrincipal,
+                checkedPermissions,
+                excludedPermissions,
+                transactionContextManager,
+                connectionTrackingCoordinator,
+                container,
+                roleDesignateSource,
+                null,
+                null,
+                null);
+        app.setContextPath("/test");
+        app.doStart();
+        return app;
     }
 
-    protected void setUpSecureAppContext(Map roleDesignates, Map principalRoleMap, ComponentPermissions
componentPermissions, DefaultPrincipal defaultPrincipal, PermissionCollection checked, Set
securityRoles) throws Exception {
-        ObjectName jaccBeanName = NameFactory.getComponentName(null, null, null, null, "foo",
NameFactory.JACC_MANAGER, moduleContext);
-        GBeanData jaccBeanData = new GBeanData(jaccBeanName, ApplicationPolicyConfigurationManager.GBEAN_INFO);
+    protected JettyWebAppContext setUpSecureAppContext(Map roleDesignates, Map principalRoleMap,
ComponentPermissions componentPermissions, DefaultPrincipal defaultPrincipal, PermissionCollection
checked, Set securityRoles) throws Exception {
+        String policyContextId = "TEST";
         Map contextIDToPermissionsMap = new HashMap();
-        contextIDToPermissionsMap.put("TEST", componentPermissions);
-        jaccBeanData.setAttribute("contextIdToPermissionsMap", contextIDToPermissionsMap);
-        jaccBeanData.setAttribute("principalRoleMap", principalRoleMap);
-        jaccBeanData.setAttribute("roleDesignates", roleDesignates);
-        start(jaccBeanData);
-
-        GBeanData app = new GBeanData(webModuleName, JettyWebAppContext.GBEAN_INFO);
-        app.setAttribute("securityRealmName", "demo-properties-realm");
-        app.setAttribute("defaultPrincipal", defaultPrincipal);
-        app.setAttribute("checkedPermissions", checked);
-        app.setAttribute("excludedPermissions", componentPermissions.getExcludedPermissions());
-        app.setReferencePattern("RoleDesignateSource", jaccBeanName);
+        contextIDToPermissionsMap.put(policyContextId, componentPermissions);
+        ApplicationPolicyConfigurationManager jacc = new ApplicationPolicyConfigurationManager(contextIDToPermissionsMap,
principalRoleMap, roleDesignates, cl);
+        jacc.doStart();
 
         FormAuthenticator formAuthenticator = new FormAuthenticator();
         formAuthenticator.setLoginPage("/auth/logon.html?param=test");
         formAuthenticator.setErrorPage("/auth/logonError.html?param=test");
-        app.setAttribute("realmName", "Test JAAS Realm");
-        app.setAttribute("authenticator", formAuthenticator);
-        app.setAttribute("policyContextID", "TEST");
-        app.setAttribute("uri", URI.create("war3/"));
-        app.setAttribute("componentContext", Collections.EMPTY_MAP);
-
-        OnlineUserTransaction userTransaction = new OnlineUserTransaction();
-        app.setAttribute("userTransaction", userTransaction);
-        app.setAttribute("configurationBaseUrl", new File("src/test-resources/deployables/").toURL());
-        app.setReferencePattern("TransactionContextManager", tcmName);
-        app.setReferencePattern("TrackedConnectionAssociator", ctcName);
-        app.setReferencePattern("JettyContainer", containerName);
-
-        app.setAttribute("contextPath", "/test");
+        return setUpAppContext("Test JAAS Realm",
+                "demo-properties-realm",
+                formAuthenticator,
+                policyContextId,
+                jacc,
+                componentPermissions.getExcludedPermissions(),
+                defaultPrincipal,
+                checked, "war3/");
 
-        start(app);
     }
 
     protected void setUpSecurity() throws Exception {
+        String domainName = "demo-properties-realm";
+
+        ServerInfo serverInfo = new BasicServerInfo(".");
+
+        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);
-
-        serverInfoName = new ObjectName("geronimo.system:name=ServerInfo");
-        serverInfoGBean = new GBeanData(serverInfoName, BasicServerInfo.GBEAN_INFO);
-        serverInfoGBean.setAttribute("baseDirectory", ".");
-
-        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("reclaimPeriod", new Long(1000 * 1000));
-        loginServiceGBean.setAttribute("algorithm", "HmacSHA1");
-        loginServiceGBean.setAttribute("password", "secret");
-
-        propertiesLMName = new ObjectName("geronimo.security:type=LoginModule,name=demo-properties-login");
-        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);
-        //TODO should this be called securityRealmName?
-        propertiesLMGBean.setAttribute("loginDomainName", "demo-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=demo-properties-realm");
-        propertiesRealmGBean = new GBeanData(propertiesRealmName, GenericSecurityRealm.GBEAN_INFO);
-        propertiesRealmGBean.setReferencePattern("ServerInfo", serverInfoName);
-        propertiesRealmGBean.setAttribute("realmName", "demo-properties-realm");
-        propertiesRealmGBean.setReferencePattern("LoginService", loginServiceName);
-//        Properties config = new Properties();
-//        config.setProperty("LoginModule.1.REQUIRED", propertiesLMName.getCanonicalName());
-//        propertiesRealmGBean.setAttribute("loginModuleConfiguration", config);
-        propertiesRealmGBean.setReferencePattern("LoginModuleConfiguration", testUseName);
+
+        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());
-
-        start(loginConfigurationGBean);
-        start(serverInfoGBean);
-        start(securityServiceGBean);
-        start(loginServiceGBean);
-        start(propertiesLMGBean);
-        start(lmUseGBean);
-        start(propertiesRealmGBean);
+        GenericSecurityRealm realm = new GenericSecurityRealm(domainName, loginModuleUse,
true, true, (PrincipalInfo) principalEditor.getValue(), serverInfo,  cl, null, loginService);
 
-    }
+        loginService.setRealms(Collections.singleton(realm));
+        loginService.doStart();
 
-    protected void tearDownSecurity() throws Exception {
-        stop(propertiesRealmName);
-        stop(propertiesLMName);
-        stop(loginServiceName);
-        stop(securityServiceName);
-        stop(serverInfoName);
-        stop(loginConfigurationName);
-    }
+        GeronimoLoginConfiguration loginConfiguration = new GeronimoLoginConfiguration();
+        loginConfiguration.setConfigurations(Collections.singleton(realm));
+        loginConfiguration.doStart();
 
-    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());
-        }
     }
 
-    private void stop(ObjectName name) throws Exception {
-        kernel.stopGBean(name);
-        kernel.unloadGBean(name);
+    protected void tearDownSecurity() throws Exception {
     }
 
     protected void setUp() throws Exception {
         cl = this.getClass().getClassLoader();
-        containerName = NameFactory.getWebComponentName(null, null, null, null, "jettyContainer",
"WebResource", moduleContext);
-        connectorName = NameFactory.getWebComponentName(null, null, null, null, "jettyConnector",
"WebResource", moduleContext);
-        webModuleName = NameFactory.getModuleName(null, null, null, null, "testModule", moduleContext);
-
-        tmName = NameFactory.getComponentName(null, null, null, null, null, "TransactionManager",
NameFactory.TRANSACTION_MANAGER, moduleContext);
-        tcmName = NameFactory.getComponentName(null, 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();
-        container = new GBeanData(containerName, JettyContainerImpl.GBEAN_INFO);
-
-        connector = new GBeanData(connectorName, HTTPConnector.GBEAN_INFO);
-        connector.setAttribute("port", new Integer(5678));
-        connector.setAttribute("maxThreads", new Integer(50));
-        connector.setAttribute("minThreads", new Integer(10));
-        connector.setReferencePattern("JettyContainer", 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);
+
+        configurationBaseURL = cl.getResource("deployables/");
+
+        container = new JettyContainerImpl("test:name=JettyContainer");
+        container.doStart();
+        connector = new HTTPConnector(container);
+        connector.setPort(5678);
+        connector.setMaxThreads(50);
+        connector.setMinThreads(10);
+        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);
-        stop(connectorName);
-        stop(containerName);
-        kernel.shutdown();
+        connector.doStop();
     }
 }

Modified: geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java?rev=386763&r1=386762&r2=386763&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java
(original)
+++ geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java
Fri Mar 17 15:15:27 2006
@@ -28,9 +28,9 @@
 public class ApplicationTest extends AbstractWebModuleTest {
 
     public void testApplication() throws Exception {
-        setUpInsecureAppContext();
+        JettyWebAppContext app = setUpAppContext(null, null, null, null, null, null, null,
null, "war1/");
 
-        setUpStaticContentServlet();
+        setUpStaticContentServlet(app);
 
         HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:5678/test/hello.txt").openConnection();
         BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

Modified: geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ContainerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ContainerTest.java?rev=386763&r1=386762&r2=386763&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ContainerTest.java
(original)
+++ geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ContainerTest.java
Fri Mar 17 15:15:27 2006
@@ -37,27 +37,9 @@
 /**
  * @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;
-
-    public void testServer() throws Exception {
-        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(containerName));
-    }
+public class ContainerTest extends AbstractWebModuleTest {
 
     public void testHTTPConnector() throws Exception {
-        GBeanData connector = new GBeanData(connectorName, HTTPConnector.GBEAN_INFO);
-        connector.setAttribute("port", new Integer(5678));
-        connector.setAttribute("maxThreads", new Integer(50));
-        connector.setAttribute("minThreads", new Integer(10));
-        connector.setReferencePatterns("JettyContainer", containerPatterns);
-        start(connector);
-
-        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(connectorName));
 
         HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:5678").openConnection();
         try {
@@ -68,22 +50,13 @@
             assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode());
             connection.disconnect();
         }
-        stop(connectorName);
     }
 
     public void testWebServiceHandler() throws Exception {
-        GBeanData connector = new GBeanData(connectorName, HTTPConnector.GBEAN_INFO);
-        connector.setAttribute("port", new Integer(5678));
-        connector.setAttribute("maxThreads", new Integer(50));
-        connector.setAttribute("minThreads", new Integer(10));
-        connector.setReferencePatterns("JettyContainer", containerPatterns);
-        start(connector);
-
-        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(connectorName));
 
         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:5678"
+ contextPath).openConnection();
         try {
@@ -93,7 +66,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:5678" + contextPath).openConnection();
         try {
             connection.getInputStream();
@@ -103,32 +76,6 @@
             assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode());
             connection.disconnect();
         }
-        stop(connectorName);
-    }
-
-    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 setUp() throws Exception {
-        containerName = new ObjectName("geronimo.jetty:role=Container");
-        containerPatterns = new HashSet();
-        containerPatterns.add(containerName);
-        connectorName = new ObjectName("geronimo.jetty:role=Connector");
-        kernel = KernelFactory.newInstance().createKernel("test.kernel");
-        kernel.boot();
-        container = new GBeanData(containerName, JettyContainerImpl.GBEAN_INFO);
-        start(container);
-    }
-
-    protected void tearDown() throws Exception {
-        stop(containerName);
-        kernel.shutdown();
-    }
 }

Modified: geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/SecurityTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/SecurityTest.java?rev=386763&r1=386762&r2=386763&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/SecurityTest.java
(original)
+++ geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/SecurityTest.java
Fri Mar 17 15:15:27 2006
@@ -160,8 +160,8 @@
     }
 
     protected void startWebApp(Map roleDesignates, Map principalRoleMap, ComponentPermissions
componentPermissions, DefaultPrincipal defaultPrincipal, PermissionCollection checked, Set
securityRoles) throws Exception {
-        setUpSecureAppContext(roleDesignates, principalRoleMap, componentPermissions, defaultPrincipal,
checked, securityRoles);
-        setUpStaticContentServlet();
+        JettyWebAppContext app = setUpSecureAppContext(roleDesignates, principalRoleMap,
componentPermissions, defaultPrincipal, checked, securityRoles);
+        setUpStaticContentServlet(app);
 //        start(appName, app);
     }
 

Modified: geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/GeronimoLoginConfiguration.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/GeronimoLoginConfiguration.java?rev=386763&r1=386762&r2=386763&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/GeronimoLoginConfiguration.java
(original)
+++ geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/GeronimoLoginConfiguration.java
Fri Mar 17 15:15:27 2006
@@ -65,8 +65,10 @@
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) sm.checkPermission(SecurityServiceImpl.CONFIGURE);
 
-        ReferenceCollection ref = (ReferenceCollection) configurations;
-        ref.addReferenceCollectionListener(this);
+        if (configurations instanceof ReferenceCollection) {
+            ReferenceCollection ref = (ReferenceCollection) configurations;
+            ref.addReferenceCollectionListener(this);
+        }
 
         this.configurations = configurations;
 

Modified: geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/client/JaasLoginCoordinator.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/client/JaasLoginCoordinator.java?rev=386763&r1=386762&r2=386763&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/client/JaasLoginCoordinator.java
(original)
+++ geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/client/JaasLoginCoordinator.java
Fri Mar 17 15:15:27 2006
@@ -55,6 +55,7 @@
     public final static String OPTION_KERNEL = "kernel";
     public final static String OPTION_REALM = "realm";
     public final static String OPTION_SERVICENAME = "serviceName";
+    public final static String OPTION_SERVICE_INSTANCE = "serviceInstance";
     private String serverHost;
     private int serverPort;
     private String realmName;
@@ -82,7 +83,12 @@
         } catch (MalformedObjectNameException e) {
             throw new IllegalArgumentException("option " + OPTION_SERVICENAME + "is not a
valid ObjectName: " + options.get(OPTION_SERVICENAME));
         }
-        service = connect();
+        if (port != null || kernelName != null) {
+            service = connect();
+        } else {
+            //primarily for testing without a kernel
+            service = (JaasLoginServiceMBean) options.get(OPTION_SERVICE_INSTANCE);
+        }
         handler = callbackHandler;
         if (subject == null) {
             this.subject = new Subject();

Modified: geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/server/JaasLoginService.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/server/JaasLoginService.java?rev=386763&r1=386762&r2=386763&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/server/JaasLoginService.java
(original)
+++ geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/server/JaasLoginService.java
Fri Mar 17 15:15:27 2006
@@ -16,35 +16,14 @@
  */
 package org.apache.geronimo.security.jaas.server;
 
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.Principal;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import javax.crypto.Mac;
-import javax.crypto.SecretKey;
-import javax.crypto.spec.SecretKeySpec;
-import javax.security.auth.Subject;
-import javax.security.auth.callback.Callback;
-import javax.security.auth.login.LoginException;
-import javax.security.auth.spi.LoginModule;
-
 import EDU.oswego.cs.dl.util.concurrent.ClockDaemon;
 import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.geronimo.common.GeronimoSecurityException;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
-import org.apache.geronimo.gbean.ReferenceCollection;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.security.ContextManager;
 import org.apache.geronimo.security.IdentificationPrincipal;
@@ -52,6 +31,25 @@
 import org.apache.geronimo.security.jaas.LoginUtils;
 import org.apache.geronimo.security.realm.SecurityRealm;
 
+import javax.crypto.Mac;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 
 /**
  * The single point of contact for Geronimo JAAS realms.  Instead of attempting
@@ -67,7 +65,7 @@
     private final static int DEFAULT_MAX_LOGIN_DURATION = 1000 * 3600 * 24; // 1 day
     private final static ClockDaemon clockDaemon;
     private static long nextLoginModuleId = System.currentTimeMillis();
-    private ReferenceCollection realms;
+    private Collection realms;
     private Object expiredLoginScanIdentifier;
     private final String objectName;
     private final SecretKey key;
@@ -100,7 +98,7 @@
      * GBean property
      */
     public void setRealms(Collection realms) {
-        this.realms = (ReferenceCollection) realms;
+        this.realms = realms;
         //todo: add listener to drop logins when realm is removed
     }
 
@@ -161,7 +159,7 @@
      *         methods in this class.
      */
     public JaasSessionId connectToRealm(String realmName) {
-        SecurityRealm realm = null;
+        SecurityRealm realm;
         realm = getRealm(realmName);
         if (realm == null) {
             throw new GeronimoSecurityException("No such realm (" + realmName + ")");
@@ -210,10 +208,12 @@
         try {
             module.login();
         } catch (LoginException e) {
+            //expected
         }
         try {
             module.abort();
         } catch (LoginException e) {
+            //makes no difference
         }
         return session.getHandler().finalizeCallbackList();
     }

Modified: geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/realm/GenericSecurityRealm.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/realm/GenericSecurityRealm.java?rev=386763&r1=386762&r2=386763&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/realm/GenericSecurityRealm.java
(original)
+++ geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/realm/GenericSecurityRealm.java
Fri Mar 17 15:15:27 2006
@@ -159,9 +159,16 @@
     public JaasLoginModuleConfiguration generateConfiguration() {
         Map options = new HashMap();
         options.put(JaasLoginCoordinator.OPTION_REALM, realmName);
-        options.put(JaasLoginCoordinator.OPTION_KERNEL, kernel.getKernelName());
-        if (loginService != null) {
-            options.put(JaasLoginCoordinator.OPTION_SERVICENAME, loginService.getObjectName());
+        if (kernel != null) {
+            options.put(JaasLoginCoordinator.OPTION_KERNEL, kernel.getKernelName());
+            if (loginService != null) {
+                options.put(JaasLoginCoordinator.OPTION_SERVICENAME, loginService.getObjectName());
+            }
+        } else {
+            if (loginService != null) {
+                //this can be used for testing without a kernel.
+                options.put(JaasLoginCoordinator.OPTION_SERVICE_INSTANCE, loginService);
+            }
         }
 
         return new JaasLoginModuleConfiguration(JaasLoginCoordinator.class.getName(), LoginModuleControlFlag.REQUIRED,
options, true, realmName, wrapPrincipals, JaasLoginCoordinator.class.getClassLoader());

Modified: geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/realm/providers/PropertiesFileLoginModule.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/realm/providers/PropertiesFileLoginModule.java?rev=386763&r1=386762&r2=386763&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/realm/providers/PropertiesFileLoginModule.java
(original)
+++ geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/realm/providers/PropertiesFileLoginModule.java
Fri Mar 17 15:15:27 2006
@@ -17,6 +17,21 @@
 
 package org.apache.geronimo.security.realm.providers;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.common.GeronimoSecurityException;
+import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.FailedLoginException;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
@@ -27,23 +42,6 @@
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
-import javax.security.auth.Subject;
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.security.auth.login.LoginException;
-import javax.security.auth.login.FailedLoginException;
-import javax.security.auth.spi.LoginModule;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.common.GeronimoSecurityException;
-import org.apache.geronimo.kernel.KernelRegistry;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
-import org.apache.geronimo.system.serverinfo.ServerInfo;
 
 
 /**
@@ -69,7 +67,6 @@
         this.subject = subject;
         this.handler = callbackHandler;
         try {
-            Kernel kernel = KernelRegistry.getKernel((String)options.get(JaasLoginModuleUse.KERNEL_NAME_LM_OPTION));
             ServerInfo serverInfo = (ServerInfo) options.get(JaasLoginModuleUse.SERVERINFO_LM_OPTION);
             final String users = (String)options.get(USERS_URI);
             final String groups = (String)options.get(GROUPS_URI);
@@ -78,14 +75,14 @@
             }
             URI usersURI = new URI(users);
             URI groupsURI = new URI(groups);
-            loadProperties(kernel, serverInfo, usersURI, groupsURI);
+            loadProperties(serverInfo, usersURI, groupsURI);
         } catch (Exception e) {
             log.error("Initialization failed", e);
             throw new IllegalArgumentException("Unable to configure properties file login
module: "+e.getMessage());
         }
     }
 
-    public void loadProperties(Kernel kernel, ServerInfo serverInfo, URI userURI, URI groupURI)
throws GeronimoSecurityException {
+    public void loadProperties(ServerInfo serverInfo, URI userURI, URI groupURI) throws GeronimoSecurityException
{
         try {
             URI userFile = serverInfo.resolve(userURI);
             URI groupFile = serverInfo.resolve(groupURI);



Mime
View raw message