djencks 2004/02/14 10:49:43
Modified: modules/jetty/src/java/org/apache/geronimo/jetty/deployment
AbstractModule.java JettyModule.java
modules/jetty/src/schema geronimo-jetty.xsd
modules/jetty/src/test/org/apache/geronimo/jetty/deployment
DeploymentTest.java
modules/jetty/src/test-resources/deployables/war1/WEB-INF
geronimo-web.xml
Removed: modules/jetty/src/test-resources/deployables/war1
geronimo-web2.xml
Log:
start adding security to jetty
Revision Changes Path
1.6 +28 -1
incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/AbstractModule.java
Index: AbstractModule.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/AbstractModule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractModule.java 14 Feb 2004 01:50:15 -0000 1.5
+++ AbstractModule.java 14 Feb 2004 18:49:43 -0000 1.6
@@ -58,6 +58,10 @@
import java.net.URI;
import java.util.Collections;
import java.util.Properties;
+import java.util.Collection;
+import java.util.ArrayList;
+import java.io.InputStream;
+import java.io.IOException;
import javax.management.ObjectName;
import javax.naming.Context;
@@ -66,6 +70,7 @@
import org.apache.geronimo.deployment.ConfigurationCallback;
import org.apache.geronimo.deployment.DeploymentException;
import org.apache.geronimo.deployment.DeploymentModule;
+import org.apache.geronimo.deployment.util.UnclosableInputStream;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import org.apache.geronimo.jetty.JettyWebApplicationContext;
import org.apache.geronimo.kernel.Kernel;
@@ -73,6 +78,9 @@
import org.apache.geronimo.naming.java.ProxyFactory;
import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppType;
import org.apache.geronimo.xbeans.j2ee.WebAppType;
+import org.apache.geronimo.xbeans.j2ee.WebAppDocument;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.XmlException;
/**
*
@@ -147,5 +155,24 @@
}
public void complete() {
+ }
+
+ protected void extractAndValidateDeploymentDescriptor(InputStream is)
throws DeploymentException {
+ try {
+ WebAppDocument webAppDoc = WebAppDocument.Factory.parse(new
UnclosableInputStream(is));
+ //validate
+ XmlOptions xmlOptions = new XmlOptions();
+ xmlOptions.setLoadLineNumbers();
+ Collection errors = new ArrayList();
+ xmlOptions.setErrorListener(errors);
+ if (!webAppDoc.validate(xmlOptions)) {
+ throw new DeploymentException("Invalid deployment
descriptor: errors: " + errors);
+ }
+ webApp = webAppDoc.getWebApp();
+ } catch (IOException e) {
+ throw new DeploymentException("Unable to read deployment
descriptor", e);
+ } catch (XmlException e) {
+ throw new DeploymentException("Unable to parse deployment
descriptor", e);
+ }
}
}
1.12 +10 -20
incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModule.java
Index: JettyModule.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModule.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- JettyModule.java 14 Feb 2004 01:50:15 -0000 1.11
+++ JettyModule.java 14 Feb 2004 18:49:43 -0000 1.12
@@ -65,11 +65,8 @@
import org.apache.geronimo.deployment.ConfigurationCallback;
import org.apache.geronimo.deployment.DeploymentException;
-import org.apache.geronimo.deployment.util.UnclosableInputStream;
-import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppType;
-import org.apache.geronimo.xbeans.j2ee.WebAppDocument;
import org.apache.geronimo.naming.java.ProxyFactory;
-import org.apache.xmlbeans.XmlException;
+import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppType;
/**
*
@@ -103,44 +100,37 @@
// unpack archive into Configuration
try {
ZipEntry entry;
- boolean addedClasses= false;
- while ((entry= zipArchive.getNextEntry()) != null) {
- String name= entry.getName();
+ boolean addedClasses = false;
+ while ((entry = zipArchive.getNextEntry()) != null) {
+ String name = entry.getName();
if (name.endsWith("/")) {
continue;
}
callback.addFile(uri.resolve(name), zipArchive);
if (name.equals("WEB-INF/web-app.xml")) {
- WebAppDocument webAppDoc =
WebAppDocument.Factory.parse(new UnclosableInputStream(zipArchive));
- webApp = webAppDoc.getWebApp();
+ extractAndValidateDeploymentDescriptor(zipArchive);
}
// If we do not give the context priority over
classloading, then we add the standard locations to our classpath.
if (!contextPriorityClassLoader) {
if (!addedClasses &&
name.startsWith("WEB-INF/classes/")) {
callback.addToClasspath(classes);
- }
- else if (name.startsWith("WEB-INF/lib/")) {
+ } else if (name.startsWith("WEB-INF/lib/")) {
if (name.indexOf('/', 12) == -1 &&
(name.endsWith(".jar") || name.endsWith(".zip"))) {
callback.addToClasspath(uri.resolve(name));
}
}
}
}
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new DeploymentException("Unable to unpack WAR
content", e);
- } catch (XmlException e) {
- throw new DeploymentException("Unable to parse WAR content",
e);
}
- }
- else {
+ } else {
// copy directory into Configuration
try {
copyDir(callback, uri, moduleDirectory);
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new DeploymentException("Unable to copy archive
directory", e);
}
}
1.4 +3 -0
incubator-geronimo/modules/jetty/src/schema/geronimo-jetty.xsd
Index: geronimo-jetty.xsd
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/jetty/src/schema/geronimo-jetty.xsd,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- geronimo-jetty.xsd 14 Feb 2004 01:50:15 -0000 1.3
+++ geronimo-jetty.xsd 14 Feb 2004 18:49:43 -0000 1.4
@@ -3,12 +3,14 @@
xmlns:jetty="http://geronimo.apache.org/xml/ns/web/jetty"
targetNamespace="http://geronimo.apache.org/xml/ns/web/jetty"
xmlns:ger="http://geronimo.apache.org/xml/ns/j2ee"
+ xmlns:sec="http://geronimo.apache.org/xml/ns/security"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.0">
<xsd:import namespace="http://geronimo.apache.org/xml/ns/j2ee"
schemaLocation="../../../naming/src/schema/geronimo-naming.xsd"/>
+ <xsd:import namespace="http://geronimo.apache.org/xml/ns/security"
schemaLocation="../../../security/src/schema/geronimo-security.xsd"/>
<xsd:element name="web-app" type="jetty:web-appType"/>
@@ -17,6 +19,7 @@
<xsd:element name="context-root" type="jetty:context-rootType"/>
<xsd:element name="context-priority-classloader"
type="xsd:boolean"/>
<xsd:group ref="ger:jndiEnvironmentRefsGroup"/>
+ <xsd:element name="security" type="sec:securityType"
minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
1.8 +15 -2
incubator-geronimo/modules/jetty/src/test/org/apache/geronimo/jetty/deployment/DeploymentTest.java
Index: DeploymentTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/jetty/src/test/org/apache/geronimo/jetty/deployment/DeploymentTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DeploymentTest.java 14 Feb 2004 01:50:15 -0000 1.7
+++ DeploymentTest.java 14 Feb 2004 18:49:43 -0000 1.8
@@ -67,6 +67,8 @@
import java.net.URL;
import java.net.HttpURLConnection;
import java.util.Collections;
+import java.util.Collection;
+import java.util.ArrayList;
import java.util.jar.JarOutputStream;
import javax.enterprise.deploy.spi.Target;
import javax.enterprise.deploy.spi.TargetModuleID;
@@ -76,11 +78,13 @@
import javax.enterprise.deploy.shared.StateType;
import org.apache.geronimo.deployment.URLDeployer;
+import org.apache.geronimo.deployment.DeploymentException;
import org.apache.geronimo.deployment.plugin.local.LocalServer;
import org.apache.geronimo.deployment.service.ServiceDeployer;
import org.apache.geronimo.deployment.util.URLInfo;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppDocument;
+import org.apache.xmlbeans.XmlOptions;
/**
*
@@ -94,9 +98,17 @@
public void testReadGeronimoDD() throws Exception {
File war = new
File(URI.create(classLoader.getResource("deployables/war1/").toString()));
- File dd = new File(war, "geronimo-web2.xml");
+ File dd = new File(war, "WEB-INF/geronimo-web.xml");
InputStream is = new FileInputStream(dd);
JettyWebAppDocument doc = JettyWebAppDocument.Factory.parse(is);
+ XmlOptions xmlOptions = new XmlOptions();
+ xmlOptions.setLoadLineNumbers();
+ Collection errors = new ArrayList();
+ xmlOptions.setErrorListener(errors);
+ if (!doc.validate(xmlOptions)) {
+ System.out.println("Errors: " + errors);
+ throw new DeploymentException("Invalid deployment descriptor:
errors: " + errors);
+ }
assertEquals("/test",
doc.getWebApp().getContextRoot().getStringValue());
}
@@ -161,6 +173,7 @@
private void waitFor(ProgressObject result) throws InterruptedException {
result.addProgressListener(new ProgressListener() {
public void handleProgressEvent(ProgressEvent event) {
+ System.out.println(event);
synchronized (DeploymentTest.this) {
DeploymentTest.this.notify();
}
1.5 +9 -1
incubator-geronimo/modules/jetty/src/test-resources/deployables/war1/WEB-INF/geronimo-web.xml
Index: geronimo-web.xml
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/jetty/src/test-resources/deployables/war1/WEB-INF/geronimo-web.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- geronimo-web.xml 12 Feb 2004 16:29:00 -0000 1.4
+++ geronimo-web.xml 14 Feb 2004 18:49:43 -0000 1.5
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jetty:web-app xmlns:jetty="http://geronimo.apache.org/xml/ns/web/jetty">
+<jetty:web-app xmlns:jetty="http://geronimo.apache.org/xml/ns/web/jetty"
+ xmlns:ger="http://geronimo.apache.org/xml/ns/j2ee"
+ xmlns:sec="http://geronimo.apache.org/xml/ns/security">
<jetty:context-root>/test</jetty:context-root>
<jetty:context-priority-classloader>false</jetty:context-priority-classloader>
+ <jetty:security>
+ <sec:default-principal realm-name="foo">
+ <sec:principal
class="org.apache.geronimo.security.DefaultPrincipal"
+ name="bar"/>
+ </sec:default-principal>
+ </jetty:security>
</jetty:web-app>