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 2007/01/20 20:52:37 UTC
svn commit: r498160 - in
/geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test:
java/org/apache/geronimo/web25/deployment/SpecSecurityParsingTest.java
resources/security/ resources/security/web1.xml
Author: djencks
Date: Sat Jan 20 11:52:36 2007
New Revision: 498160
URL: http://svn.apache.org/viewvc?view=rev&rev=498160
Log:
GERONIMO-2763 test that generates *.do:/login.do pattern
Added:
geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/java/org/apache/geronimo/web25/deployment/SpecSecurityParsingTest.java (with props)
geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/resources/security/
geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/resources/security/web1.xml (with props)
Added: geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/java/org/apache/geronimo/web25/deployment/SpecSecurityParsingTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/java/org/apache/geronimo/web25/deployment/SpecSecurityParsingTest.java?view=auto&rev=498160
==============================================================================
--- geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/java/org/apache/geronimo/web25/deployment/SpecSecurityParsingTest.java (added)
+++ geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/java/org/apache/geronimo/web25/deployment/SpecSecurityParsingTest.java Sat Jan 20 11:52:36 2007
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.web25.deployment;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.jar.JarFile;
+import java.security.PermissionCollection;
+
+import javax.security.jacc.WebResourcePermission;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.ModuleIDBuilder;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.j2ee.deployment.EARContext;
+import org.apache.geronimo.j2ee.deployment.Module;
+import org.apache.geronimo.kernel.Naming;
+import org.apache.geronimo.xbeans.javaee.WebAppType;
+import org.apache.geronimo.xbeans.javaee.WebAppDocument;
+import org.apache.geronimo.security.jacc.ComponentPermissions;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.XmlObject;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class SpecSecurityParsingTest extends TestCase {
+
+ private ClassLoader classLoader = this.getClass().getClassLoader();
+ private XmlOptions options = new XmlOptions();
+ private TestWebModuleBuilder builder = new TestWebModuleBuilder();
+ private Set<String> roleSet = new HashSet<String>();
+ private Map<String, PermissionCollection> rolePermissionMap = new HashMap<String, PermissionCollection>();
+
+
+ public void testParsing() throws Exception {
+ roleSet.add("Admin");
+ URL srcXml = classLoader.getResource("security/web1.xml");
+ WebAppDocument webAppDoc = WebAppDocument.Factory.parse(srcXml, options);
+ WebAppType webAppType = webAppDoc.getWebApp();
+ ComponentPermissions permissions = builder.buildSpecSecurityConfig(webAppType, roleSet, rolePermissionMap);
+ PermissionCollection unchecked = permissions.getUncheckedPermissions();
+ assertTrue(unchecked.implies(new WebResourcePermission("/login.do", "!")));
+ assertTrue(unchecked.implies(new WebResourcePermission("/foo", "!")));
+ assertFalse(unchecked.implies(new WebResourcePermission("/foo.do", "!")));
+ PermissionCollection adminPermissions = (PermissionCollection) permissions.getRolePermissions().get("Admin");
+ assertTrue(adminPermissions.implies(new WebResourcePermission("foo.do", "GET,POST")));
+ }
+
+ public static class TestWebModuleBuilder extends AbstractWebModuleBuilder {
+
+ protected TestWebModuleBuilder() {
+ super(null, null, null, null, null);
+ }
+
+ protected Module createModule(Object plan, JarFile moduleFile, String targetPath, URL specDDUrl, boolean standAlone, String contextRoot, AbstractName earName, Naming naming, ModuleIDBuilder idBuilder) throws DeploymentException {
+ return null;
+ }
+
+ public void initContext(EARContext earContext, Module module, ClassLoader cl) throws DeploymentException {
+ }
+
+ public void addGBeans(EARContext earContext, Module module, ClassLoader cl, Collection repository) throws DeploymentException {
+ }
+
+ public String getSchemaNamespace() {
+ return null;
+ }
+ }
+}
Propchange: geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/java/org/apache/geronimo/web25/deployment/SpecSecurityParsingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/java/org/apache/geronimo/web25/deployment/SpecSecurityParsingTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/java/org/apache/geronimo/web25/deployment/SpecSecurityParsingTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/resources/security/web1.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/resources/security/web1.xml?view=auto&rev=498160
==============================================================================
--- geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/resources/security/web1.xml (added)
+++ geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/resources/security/web1.xml Sat Jan 20 11:52:36 2007
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<web-app xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee">
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>Struts pages</web-resource-name>
+ <url-pattern>*.do</url-pattern>
+ <http-method>GET</http-method>
+ <http-method>POST</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>*</role-name>
+ </auth-constraint>
+ </security-constraint>
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>Login page</web-resource-name>
+ <url-pattern>/login.do</url-pattern>
+ <http-method>GET</http-method>
+ </web-resource-collection>
+ </security-constraint>
+
+</web-app>
Propchange: geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/resources/security/web1.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/resources/security/web1.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/test/resources/security/web1.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml