001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.web25.deployment;
017:
018: import java.io.File;
019: import java.net.URL;
020: import java.util.Collection;
021: import java.util.HashMap;
022: import java.util.Map;
023: import java.util.Set;
024: import java.util.Collections;
025: import java.util.ArrayList;
026: import java.util.jar.JarFile;
027:
028: import org.apache.geronimo.common.DeploymentException;
029: import org.apache.geronimo.deployment.ModuleIDBuilder;
030: import org.apache.geronimo.deployment.util.DeploymentUtil;
031: import org.apache.geronimo.deployment.util.UnpackedJarFile;
032: import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
033: import org.apache.geronimo.gbean.AbstractName;
034: import org.apache.geronimo.j2ee.deployment.EARContext;
035: import org.apache.geronimo.j2ee.deployment.Module;
036: import org.apache.geronimo.j2ee.deployment.ModuleBuilderExtension;
037: import org.apache.geronimo.kernel.Kernel;
038: import org.apache.geronimo.kernel.Naming;
039: import org.apache.geronimo.security.jacc.ComponentPermissions;
040: import org.apache.geronimo.testsupport.TestSupport;
041: import org.apache.geronimo.xbeans.javaee.WebAppDocument;
042: import org.apache.geronimo.xbeans.javaee.WebAppType;
043: import org.apache.xmlbeans.XmlObject;
044: import org.apache.xmlbeans.XmlOptions;
045:
046: /**
047: * @version $Rev: 516226 $ $Date: 2007-03-08 15:31:23 -0800 (Thu, 08 Mar 2007) $
048: */
049: public class SecurityConfigTest extends TestSupport {
050:
051: private ClassLoader classLoader = this .getClass().getClassLoader();
052:
053: private XmlOptions options = new XmlOptions();
054:
055: private WebModuleBuilder webModuleBuilder = new WebModuleBuilder(
056: null);
057:
058: public void testNoSecConstraint() throws Exception {
059: String warName = "war3";
060: File path = new File(BASEDIR, "src/test/resources/deployables/"
061: + warName);
062:
063: // parse the spec dd
064: String specDD = "";
065: WebAppType webApp = null;
066: UnpackedJarFile jarFile = new UnpackedJarFile(path);
067: URL specDDUrl = DeploymentUtil.createJarURL(jarFile,
068: "WEB-INF/web.xml");
069: // read in the entire specDD as a string
070: specDD = DeploymentUtil.readAll(specDDUrl);
071: // parse it
072: XmlObject parsed = XmlBeansUtil.parse(specDD);
073: WebAppDocument webAppDoc = webModuleBuilder
074: .convertToServletSchema(parsed);
075: webApp = webAppDoc.getWebApp();
076: Set securityRoles = AbstractWebModuleBuilder
077: .collectRoleNames(webApp);
078: Map rolePermissions = new HashMap();
079: try {
080: ComponentPermissions componentPermissions = webModuleBuilder
081: .buildSpecSecurityConfig(webApp, securityRoles,
082: rolePermissions);
083: } catch (IllegalArgumentException e) {
084: // This is a known issue
085: //System.out.println("Exception caught: " + e.getMessage());
086: }
087: }
088:
089: private static class WebModuleBuilder extends
090: AbstractWebModuleBuilder {
091:
092: protected WebModuleBuilder(Kernel kernel) {
093: super (kernel, null, null, null, null,
094: Collections.EMPTY_SET, null);
095: }
096:
097: protected Module createModule(Object plan, JarFile moduleFile,
098: String targetPath, URL specDDUrl, boolean standAlone,
099: String contextRoot, AbstractName earName,
100: Naming naming, ModuleIDBuilder idBuilder)
101: throws DeploymentException {
102: return null;
103: }
104:
105: public void initContext(EARContext earContext, Module module,
106: ClassLoader classLoader) throws DeploymentException {
107: }
108:
109: public void addGBeans(EARContext earContext, Module module,
110: ClassLoader classLoader, Collection repositories)
111: throws DeploymentException {
112: }
113:
114: public String getSchemaNamespace() {
115: return null;
116: }
117: }
118:
119: }
|