Uploaded image for project: 'Geronimo'
  1. Geronimo
  2. GERONIMO-533

Removed the TomcatSecureWebAppContext and placed code in TomcatWebAppContext

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0-M4
    • Fix Version/s: None
    • Component/s: Tomcat
    • Labels:
      None
    • Environment:

      MacOSX

      Description

      Removed the TomcatSecureWebAppContext and instead placed the security code in TomcatWebAppContext, similarly to Jetty. Updated the unit tests to reflect this change. Also changed the TomcatModuleBuilder to use the GbeanData instead of the deprecated GBeanMbean.

      Diff is included below.

      Index: src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
      ===================================================================
      — src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java (revision 123364)
      +++ src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java (working copy)
      @@ -132,7 +132,7 @@
      // securityRoles, Map legacySecurityConstraintMap) throws Exception {
      protected ObjectName setUpSecureAppContext(SecurityConstraint[] securityConstraints, String[] securityRoles)
      throws Exception {

      • GBeanData app = new GBeanData(webModuleName, TomcatSecureWebAppContext.GBEAN_INFO);
        + 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("configurationBaseUrl", new File("target/var/catalina/webapps/war3/WEB-INF/web.xml").toURL());
        Index: src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
        ===================================================================
          • src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java (revision 123364)
            +++ src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java (working copy)
            @@ -38,7 +38,7 @@
            import org.apache.geronimo.deployment.util.DeploymentUtil;
            import org.apache.geronimo.gbean.GBeanInfo;
            import org.apache.geronimo.gbean.GBeanInfoBuilder;
            -import org.apache.geronimo.gbean.jmx.GBeanMBean;
            +import org.apache.geronimo.gbean.GBeanData;
            import org.apache.geronimo.j2ee.deployment.EARContext;
            import org.apache.geronimo.j2ee.deployment.Module;
            import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
            @@ -97,9 +97,9 @@
            throw new DeploymentException("Could not construct module name", e);
            }
      • GBeanMBean gbean;
        + GBeanData gbean;
        try { - gbean = new GBeanMBean(TomcatWebAppContext.GBEAN_INFO); + gbean = new GBeanData(webModuleName, TomcatWebAppContext.GBEAN_INFO); gbean.setAttribute("webAppRoot", baseUri); gbean.setAttribute("webClassPath", webClassPath); @@ -110,7 +110,7 @@ }

        catch (Exception e)

        { throw new DeploymentException("Unable to initialize webapp GBean", e); }
      • earContext.addGBean(webModuleName, gbean);
        + earContext.addGBean(gbean);
        return null;
        }

      Index: src/java/org/apache/geronimo/tomcat/TomcatSecureWebAppContext.java
      ===================================================================
      — src/java/org/apache/geronimo/tomcat/TomcatSecureWebAppContext.java (revision 123364)
      +++ src/java/org/apache/geronimo/tomcat/TomcatSecureWebAppContext.java (working copy)
      @@ -1,142 +0,0 @@
      -/**

      • *
      • * Copyright 2003-2004 The Apache Software Foundation
      • *
      • * Licensed under the Apache License, Version 2.0 (the "License");
      • * you may not use this file except in compliance with the License.
      • * You may obtain a copy of the License at
      • *
      • * http://www.apache.org/licenses/LICENSE-2.0
      • *
      • * Unless required by applicable law or agreed to in writing, software
      • * distributed under the License is distributed on an "AS IS" BASIS,
      • * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      • * See the License for the specific language governing permissions and
      • * limitations under the License.
      • */
        -package org.apache.geronimo.tomcat;
        -
        -import java.net.URI;
        -import java.net.URL;
        -
        -import org.apache.catalina.Realm;
        -import org.apache.catalina.deploy.LoginConfig;
        -import org.apache.catalina.deploy.SecurityConstraint;
        -import org.apache.commons.logging.Log;
        -import org.apache.commons.logging.LogFactory;
        -
        -import org.apache.geronimo.gbean.GBeanInfo;
        -import org.apache.geronimo.gbean.GBeanInfoBuilder;
        -import org.apache.geronimo.gbean.GBeanLifecycle;
        -import org.apache.geronimo.gbean.WaitingException;
        -
        -
        -/**
      • * Wrapper for a WebApplicationContext that sets up its J2EE environment.
      • *
      • * @version $Rev: 56022 $ $Date: 2004-10-30 07:16:18 +0200 (Sat, 30 Oct 2004) $
      • */
        -public class TomcatSecureWebAppContext extends TomcatWebAppContext implements GBeanLifecycle {
        -
      • private final static Log log = LogFactory.getLog(org.apache.geronimo.tomcat.TomcatSecureWebAppContext.class);
        -
      • private final LoginConfig loginConfig;
        -
      • private final Realm tomcatRealm;
        -
      • private final SecurityConstraint[] securityConstraints;
        -
      • private final String[] securityRoles;
        -
      • public TomcatSecureWebAppContext(URI webAppRoot, URI[] webClassPath, URL configurationBaseUrl, String authMethod,
      • String realmName, String loginPage, String errorPage, Realm tomcatRealm,
      • SecurityConstraint[] securityConstraints, String[] securityRoles, TomcatContainer container) { - - super(webAppRoot, webClassPath, configurationBaseUrl, container); - - assert authMethod != null; - assert realmName != null; - assert loginPage != null; - assert errorPage != null; - assert tomcatRealm != null; - assert securityConstraints != null; - assert securityRoles != null; - - this.tomcatRealm = tomcatRealm; - this.securityConstraints = securityConstraints; - this.securityRoles = securityRoles; - - loginConfig = new LoginConfig(); - loginConfig.setAuthMethod(authMethod); - loginConfig.setRealmName(realmName); - loginConfig.setLoginPage(loginPage); - loginConfig.setErrorPage(errorPage); - - }

        -

      • public void setContextProperties() {
      • super.setContextProperties();
        -
      • context.setRealm(tomcatRealm);
      • context.setLoginConfig(loginConfig);
        -
      • // Add the security constraints
      • for (int i = 0; i < securityConstraints.length; i++) { - SecurityConstraint sc = securityConstraints[i]; - context.addConstraint(sc); - }

        -

      • // Add the security roles
      • for (int i = 0; i < securityRoles.length; i++) { - context.addSecurityRole(securityRoles[i]); - }
      • }
        -
      • public void doStart() throws WaitingException, Exception { - super.doStart(); - log.info("TomcatSecureWebAppContext started"); - }

        -

      • public void doStop() throws Exception { - super.doStop(); - log.info("TomcatSecureWebAppContext stopped"); - }

        -

      • public void doFail() { - super.doFail(); - log.info("TomcatSecureWebAppContext failed"); - }

        -

      • public static final GBeanInfo GBEAN_INFO;
        -
      • static {
      • GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Tomcat Secure WebApplication Context", TomcatSecureWebAppContext.class);
        -
      • infoFactory.addAttribute("webAppRoot", URI.class, true);
      • infoFactory.addAttribute("webClassPath", URI[].class, true);
      • infoFactory.addAttribute("configurationBaseUrl", URL.class, true);
        -
      • infoFactory.addAttribute("path", String.class, true);
        -
      • infoFactory.addAttribute("authMethod", String.class, true);
      • infoFactory.addAttribute("realmName", String.class, true);
      • infoFactory.addAttribute("loginPage", String.class, true);
      • infoFactory.addAttribute("errorPage", String.class, true);
        -
      • infoFactory.addAttribute("tomcatRealm", Realm.class, true);
      • infoFactory.addAttribute("securityConstraints", SecurityConstraint[].class, true);
      • infoFactory.addAttribute("securityRoles", String[].class, true);
        -
      • infoFactory.addReference("Container", TomcatContainer.class);
        -
      • infoFactory.setConstructor(new String[] {"webAppRoot", "webClassPath", "configurationBaseUrl", "authMethod", - "realmName", "loginPage", "errorPage", "tomcatRealm", "securityConstraints", "securityRoles", - "Container"}

        );
        -

      • GBEAN_INFO = infoFactory.getBeanInfo();
      • }
        -
      • public static GBeanInfo getGBeanInfo() { - return GBEAN_INFO; - }

        -}
        Index: src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
        ===================================================================

          • src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java (revision 123364)
            +++ src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java (working copy)
            @@ -21,6 +21,9 @@
            import java.net.URL;

      import org.apache.catalina.Context;
      +import org.apache.catalina.Realm;
      +import org.apache.catalina.deploy.SecurityConstraint;
      +import org.apache.catalina.deploy.LoginConfig;
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;

      @@ -49,8 +52,19 @@

      private String docBase = null;

      • public TomcatWebAppContext(URI webAppRoot, URI[] webClassPath, URL configurationBaseUrl, TomcatContainer container) {
        + private final LoginConfig loginConfig;

      + private final Realm tomcatRealm;
      +
      + private final SecurityConstraint[] securityConstraints;
      +
      + private final String[] securityRoles;
      +
      +
      + public TomcatWebAppContext(URI webAppRoot, URI[] webClassPath, URL configurationBaseUrl, String authMethod,
      + String realmName, String loginPage, String errorPage, Realm tomcatRealm,
      + SecurityConstraint[] securityConstraints, String[] securityRoles,
      + TomcatContainer container) {
      assert webAppRoot != null;
      assert webClassPath != null;
      assert configurationBaseUrl != null;
      @@ -60,6 +74,19 @@
      this.container = container;

      this.setDocBase(this.webAppRoot.getPath());
      + this.tomcatRealm = tomcatRealm;
      + this.securityConstraints = securityConstraints;
      + this.securityRoles = securityRoles;
      +
      + if (authMethod != null)

      { + loginConfig = new LoginConfig(); + loginConfig.setAuthMethod(authMethod); + loginConfig.setRealmName(realmName); + loginConfig.setLoginPage(loginPage); + loginConfig.setErrorPage(errorPage); + }

      else

      { + loginConfig = null; + }

      }

      public String getDocBase() {
      @@ -73,6 +100,28 @@
      public void setContextProperties() {
      context.setDocBase(webAppRoot.getPath());
      context.setPath(path);
      +
      + //Security
      + if (tomcatRealm != null)
      + context.setRealm(tomcatRealm);
      +
      + if (loginConfig != null)
      + context.setLoginConfig(loginConfig);
      +
      + // Add the security constraints
      + if (securityConstraints != null) {
      + for (int i = 0; i < securityConstraints.length; i++)

      { + SecurityConstraint sc = securityConstraints[i]; + context.addConstraint(sc); + }

      + }
      +
      + // Add the security roles
      + if (securityRoles != null) {
      + for (int i = 0; i < securityRoles.length; i++)

      { + context.addSecurityRole(securityRoles[i]); + }

      + }
      }

      public Context getContext() {
      @@ -109,7 +158,7 @@

      public void doFail()

      { container.removeContext(this); - + log.info("TomcatWebAppContext failed"); }

      @@ -124,9 +173,20 @@

      infoFactory.addAttribute("path", String.class, true);

      + infoFactory.addAttribute("authMethod", String.class, true);
      + infoFactory.addAttribute("realmName", String.class, true);
      + infoFactory.addAttribute("loginPage", String.class, true);
      + infoFactory.addAttribute("errorPage", String.class, true);
      +
      + infoFactory.addAttribute("tomcatRealm", Realm.class, true);
      + infoFactory.addAttribute("securityConstraints", SecurityConstraint[].class, true);
      + infoFactory.addAttribute("securityRoles", String[].class, true);
      +
      infoFactory.addReference("Container", TomcatContainer.class);

      • infoFactory.setConstructor(new String[] {"webAppRoot", "webClassPath", "configurationBaseUrl", "Container"}

        );
        + infoFactory.setConstructor(new String[]

        {"webAppRoot", "webClassPath", "configurationBaseUrl", "authMethod", + "realmName", "loginPage", "errorPage", "tomcatRealm", + "securityConstraints", "securityRoles", "Container"}

        );

      GBEAN_INFO = infoFactory.getBeanInfo();
      }

        Attachments

        1. tomcat.diff
          12 kB
          Jeff Genender

          Activity

            People

            • Assignee:
              maguro Alan Cabrera
              Reporter:
              jgenender Jeff Genender
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: