You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jg...@apache.org on 2005/04/25 23:10:43 UTC
svn commit: r164653 [1/2] - in /geronimo/trunk/modules/tomcat/src:
java/org/apache/geronimo/tomcat/ java/org/apache/geronimo/tomcat/deployment/
java/org/apache/geronimo/tomcat/realm/ java/org/apache/geronimo/tomcat/util/
java/org/apache/geronimo/tomcat/valve/
test-resources/deployables/war3/WEB-INF/ test/org/apache/geronimo/tomcat/
Author: jgenender
Date: Mon Apr 25 14:10:42 2005
New Revision: 164653
URL: http://svn.apache.org/viewcvs?rev=164653&view=rev
Log:
Support for Engine, Host, Connector, and Realms
Added:
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/BaseGBean.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ConnectorGBean.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/HostGBean.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ObjectRetriever.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/RealmGBean.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatClassLoader.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatEngine.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoEmbedded.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java
- copied, changed from r161874, geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoRealm.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatJAASRealm.java
- copied, changed from r161874, geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatJAASRealm.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/util/
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/util/SecurityHolder.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/InstanceContextValve.java
Removed:
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoRealm.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatJAASRealm.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/
Modified:
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/JAASTomcatPrincipal.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContext.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
geronimo/trunk/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/geronimo-web.xml
geronimo/trunk/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/web.xml
geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java
geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/JAASSecurityTest.java
geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/BaseGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/BaseGBean.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/BaseGBean.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/BaseGBean.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,40 @@
+/**
+*
+* 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.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.modeler.util.IntrospectionUtils;
+
+public abstract class BaseGBean {
+
+ protected void setParameters(Object object, Map map){
+ if (map != null){
+ Set keySet = map.keySet();
+ Iterator iterator = keySet.iterator();
+ while(iterator.hasNext()){
+ String name = (String)iterator.next();
+ String value = (String)map.get(name);
+
+ IntrospectionUtils.setProperty(object, name, value);
+ }
+ }
+
+ }
+}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ConnectorGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ConnectorGBean.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ConnectorGBean.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ConnectorGBean.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,81 @@
+/**
+*
+* 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.util.Map;
+
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.connector.Connector;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+
+public class ConnectorGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
+
+ private final Connector connector;
+ private final TomcatContainer container;
+
+ public ConnectorGBean(Map initParams, TomcatContainer container) throws Exception {
+ super(); // TODO: make it an attribute
+
+ if (container == null){
+ throw new IllegalArgumentException("container cannot be null.");
+ }
+
+ this.container = container;
+
+ //Create the Connector object
+ connector = new Connector();
+
+ //Set the parameters
+ setParameters(connector, initParams);
+
+ }
+
+ public Object getInternalObject() {
+ return connector;
+ }
+
+ public void doStart() throws LifecycleException {
+ container.addConnector(connector);
+ connector.start();
+ }
+
+ public void doStop() {
+ container.removeConnector(connector);
+ }
+
+ public void doFail() {
+ doStop();
+ }
+
+ public static final GBeanInfo GBEAN_INFO;
+
+ static {
+ GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("TomcatConnector", ConnectorGBean.class);
+ infoFactory.addAttribute("initParams", Map.class, true);
+ infoFactory.addReference("TomcatContainer", TomcatContainer.class, NameFactory.GERONIMO_SERVICE);
+ infoFactory.addOperation("getInternalObject");
+ infoFactory.setConstructor(new String[] { "initParams", "TomcatContainer"});
+ GBEAN_INFO = infoFactory.getBeanInfo();
+ }
+
+ public static GBeanInfo getGBeanInfo() {
+ return GBEAN_INFO;
+ }
+}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,77 @@
+/**
+*
+* 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.util.Map;
+
+import org.apache.catalina.Engine;
+import org.apache.catalina.Realm;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+
+public class EngineGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
+
+ private final Engine engine;
+
+ public EngineGBean(String className, Map initParams, ObjectRetriever realmGBean) throws Exception {
+ super(); // TODO: make it an attribute
+
+ if (className == null){
+ className = "org.apache.geronimo.tomcat.TomcatEngine";
+ }
+
+ engine = (Engine)Class.forName(className).newInstance();
+
+ //Set the parameters
+ setParameters(engine, initParams);
+
+ if (realmGBean != null){
+ engine.setRealm((Realm)realmGBean.getInternalObject());
+ }
+ }
+
+ public Object getInternalObject() {
+ return engine;
+ }
+
+ public void doFail() {
+ }
+
+ public void doStart() throws Exception {
+ }
+
+ public void doStop() throws Exception {
+ }
+
+ public static final GBeanInfo GBEAN_INFO;
+
+ static {
+ GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("TomcatEngine", EngineGBean.class);
+ infoFactory.addAttribute("className", String.class, true);
+ infoFactory.addAttribute("initParams", Map.class, true);
+ infoFactory.addReference("realmGBean", ObjectRetriever.class, NameFactory.GERONIMO_SERVICE);
+ infoFactory.addOperation("getInternalObject");
+ infoFactory.setConstructor(new String[] { "className", "initParams", "realmGBean" });
+ GBEAN_INFO = infoFactory.getBeanInfo();
+ }
+
+ public static GBeanInfo getGBeanInfo() {
+ return GBEAN_INFO;
+ }
+}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,137 @@
+/**
+ *
+ * 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.util.Iterator;
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.security.auth.Subject;
+import javax.security.jacc.PolicyContext;
+
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.core.StandardContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.naming.java.SimpleReadOnlyContext;
+import org.apache.geronimo.naming.reference.ClassLoaderAwareReference;
+import org.apache.geronimo.naming.reference.KernelAwareReference;
+import org.apache.geronimo.security.ContextManager;
+import org.apache.geronimo.security.IdentificationPrincipal;
+import org.apache.geronimo.security.SubjectId;
+import org.apache.geronimo.security.deploy.DefaultPrincipal;
+import org.apache.geronimo.security.util.ConfigurationUtil;
+import org.apache.geronimo.tomcat.util.SecurityHolder;
+import org.apache.geronimo.tomcat.valve.ComponentContextValve;
+import org.apache.geronimo.tomcat.valve.InstanceContextValve;
+import org.apache.geronimo.tomcat.valve.PolicyContextValve;
+import org.apache.geronimo.tomcat.valve.TransactionContextValve;
+import org.apache.geronimo.transaction.context.TransactionContextManager;
+
+public class GeronimoStandardContext extends StandardContext{
+
+ private static final Log log = LogFactory.getLog(GeronimoStandardContext.class);
+
+ private static final long serialVersionUID = 3834587716552831032L;
+
+ private Subject defaultSubject = null;
+
+ public void setContextProperties(TomcatContext ctx){
+
+ // create ReadOnlyContext
+ javax.naming.Context enc = null;
+ Map componentContext = ctx.getComponentContext();
+ try {
+ if (componentContext != null) {
+ for (Iterator iterator = componentContext.values().iterator(); iterator
+ .hasNext();) {
+ Object value = iterator.next();
+ if (value instanceof KernelAwareReference) {
+ ((KernelAwareReference) value).setKernel(ctx.getKernel());
+ }
+ if (value instanceof ClassLoaderAwareReference) {
+ ((ClassLoaderAwareReference) value)
+ .setClassLoader(getLoader().getClassLoader());
+ }
+ }
+ enc = new SimpleReadOnlyContext(componentContext);
+ }
+ } catch (NamingException ne) {
+ log.error(ne);
+ }
+
+ //Set the InstanceContextValve
+ InstanceContextValve instanceContextValve =
+ new InstanceContextValve(ctx.getUnshareableResources(),
+ ctx.getApplicationManagedSecurityResources(),
+ ctx.getTrackedConnectionAssociator());
+ addValve(instanceContextValve);
+
+ // Set ComponentContext valve
+ if (enc != null) {
+ ComponentContextValve contextValve = new ComponentContextValve(enc);
+ addValve(contextValve);
+ }
+
+ // Set TransactionContextValve
+ TransactionContextManager transactionContextManager = ctx.getTransactionContextManager();
+ if (transactionContextManager != null) {
+ TransactionContextValve transactionValve = new TransactionContextValve(
+ transactionContextManager);
+ addValve(transactionValve);
+ }
+
+ //Set a PolicyContext Valve
+ SecurityHolder securityHolder = ctx.getSecurityHolder();
+ if (securityHolder != null){
+ if (securityHolder.getPolicyContextID() != null) {
+
+ PolicyContext.setContextID(securityHolder.getPolicyContextID());
+
+ /**
+ * Register our default subject with the ContextManager
+ */
+ DefaultPrincipal defaultPrincipal = securityHolder.getDefaultPrincipal();
+ if (defaultPrincipal != null){
+ defaultSubject = ConfigurationUtil.generateDefaultSubject(defaultPrincipal);
+ ContextManager.registerSubject(defaultSubject);
+ SubjectId id = ContextManager.getSubjectId(defaultSubject);
+ defaultSubject.getPrincipals().add(new IdentificationPrincipal(id));
+ }
+
+ PolicyContextValve policyValve = new PolicyContextValve(
+ securityHolder.getPolicyContextID());
+ addValve(policyValve);
+ }
+ }
+ }
+
+ public synchronized void start() throws LifecycleException {
+ super.start();
+ }
+
+ public synchronized void stop() throws LifecycleException {
+ // Remove the defaultSubject
+ if (defaultSubject != null){
+ ContextManager.unregisterSubject(defaultSubject);
+ }
+
+ super.stop();
+ }
+
+
+}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/HostGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/HostGBean.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/HostGBean.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/HostGBean.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,91 @@
+/**
+*
+* 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.util.Map;
+
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.Realm;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+
+public class HostGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
+
+ private final Host host;
+
+ public HostGBean(String className, Map initParams, ObjectRetriever engineGBean, ObjectRetriever realmGBean) throws Exception {
+ super(); // TODO: make it an attribute
+
+ //Validate
+ if (className == null){
+ className = "org.apache.catalina.core.StandardHost";
+ }
+
+ if (engineGBean == null){
+ throw new IllegalArgumentException("engineGBean cannot be null.");
+ }
+
+ //Create the Host object
+ host = (Host)Class.forName(className).newInstance();
+
+ //Set the parameters
+ setParameters(host, initParams);
+
+ Engine engine = ((Engine)engineGBean.getInternalObject());
+ if (realmGBean != null)
+ host.setRealm((Realm)realmGBean.getInternalObject());
+ else
+ host.setRealm(engine.getRealm());
+
+ //Add the host to the engine
+ engine.addChild(host);
+
+ }
+
+ public Object getInternalObject() {
+ return host;
+ }
+
+ public void doFail() {
+ }
+
+ public void doStart() throws Exception {
+ }
+
+ public void doStop() throws Exception {
+ }
+
+ public static final GBeanInfo GBEAN_INFO;
+
+ static {
+ GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("TomcatHost", HostGBean.class);
+ infoFactory.addAttribute("className", String.class, true);
+ infoFactory.addAttribute("initParams", Map.class, true);
+ infoFactory.addReference("engineGBean", ObjectRetriever.class, NameFactory.GERONIMO_SERVICE);
+ infoFactory.addReference("realmGBean", ObjectRetriever.class, NameFactory.GERONIMO_SERVICE);
+ infoFactory.addOperation("getInternalObject");
+ infoFactory.setConstructor(new String[] { "className", "initParams", "engineGBean", "realmGBean" });
+ GBEAN_INFO = infoFactory.getBeanInfo();
+ }
+
+ public static GBeanInfo getGBeanInfo() {
+ return GBEAN_INFO;
+ }
+}
Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/JAASTomcatPrincipal.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/JAASTomcatPrincipal.java?rev=164653&r1=164652&r2=164653&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/JAASTomcatPrincipal.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/JAASTomcatPrincipal.java Mon Apr 25 14:10:42 2005
@@ -18,7 +18,6 @@
import java.security.Principal;
-import java.util.Stack;
import javax.security.auth.Subject;
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ObjectRetriever.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ObjectRetriever.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ObjectRetriever.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ObjectRetriever.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,22 @@
+/**
+*
+* 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;
+
+public interface ObjectRetriever {
+
+ public Object getInternalObject();
+}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/RealmGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/RealmGBean.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/RealmGBean.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/RealmGBean.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,69 @@
+/**
+*
+* 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.util.Map;
+
+import org.apache.catalina.Realm;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+
+public class RealmGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
+
+ private final Realm realm;
+
+ public RealmGBean(String className, Map initParams) throws Exception {
+ super(); // TODO: make it an attribute
+
+ assert className != null;
+
+ realm = (Realm)Class.forName(className).newInstance();
+
+ setParameters(realm, initParams);
+
+ }
+
+ public Object getInternalObject() {
+ return realm;
+ }
+
+ public void doFail() {
+ }
+
+ public void doStart() throws Exception {
+ }
+
+ public void doStop() throws Exception {
+ }
+
+ public static final GBeanInfo GBEAN_INFO;
+
+ static {
+ GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("TomcatRealm", RealmGBean.class);
+ infoFactory.addAttribute("className", String.class, true);
+ infoFactory.addAttribute("initParams", Map.class, true);
+
+ infoFactory.addOperation("getInternalObject");
+ infoFactory.setConstructor(new String[] { "className", "initParams" });
+ GBEAN_INFO = infoFactory.getBeanInfo();
+ }
+
+ public static GBeanInfo getGBeanInfo() {
+ return GBEAN_INFO;
+ }
+}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatClassLoader.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatClassLoader.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatClassLoader.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatClassLoader.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,116 @@
+/**
+*
+* Copyright 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.URL;
+import java.net.URLClassLoader;
+
+/**
+* @version $Rev$ $Date$
+*/
+public class TomcatClassLoader extends URLClassLoader {
+ private final boolean contextPriorityClassLoader;
+ private final ClassLoader parent;
+ private final ClassLoader resourceClassLoader;
+
+ public TomcatClassLoader(URL[] urls, URL resourceURL, ClassLoader parent, boolean contextPriorityClassLoader) {
+ super(urls, parent);
+
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent class loader is null");
+ }
+ URL[] resourceURLS;
+ if (resourceURL != null) {
+ resourceURLS = new URL[urls.length + 1];
+ System.arraycopy(urls, 0, resourceURLS, 0, urls.length);
+ resourceURLS[resourceURLS.length - 1] = resourceURL;
+ } else {
+ resourceURLS = urls;
+ }
+ resourceClassLoader = new ResourceClassLoader(resourceURLS, parent);
+
+ // hold on to the parent so we don't have to go throught the security check each time
+ this.parent = parent;
+ this.contextPriorityClassLoader = contextPriorityClassLoader;
+ }
+
+ public Class loadClass(String name) throws ClassNotFoundException {
+ if (!contextPriorityClassLoader ||
+ name.startsWith("java.") ||
+ name.startsWith("javax.") ||
+ name.startsWith("org.apache.geronimo.") ||
+ name.startsWith("org.apache.tomcat.") ||
+ name.startsWith("org.apache.naming.") ||
+ name.startsWith("org.apache.catalina.") ||
+ name.startsWith("org.xml.") ||
+ name.startsWith("org.w3c.")) {
+ return super.loadClass(name);
+ }
+
+ // first check if this class has already been loaded
+ Class clazz = findLoadedClass(name);
+ if (clazz != null) {
+ return clazz;
+ }
+
+ // try to load the class from this class loader
+ try {
+ clazz = findClass(name);
+ } catch (ClassNotFoundException ignored) {
+ }
+ if (clazz != null) {
+ return clazz;
+ }
+
+ // that didn't work... try the parent
+ return parent.loadClass(name);
+ }
+
+ public URL getResource(String name) {
+ return resourceClassLoader.getResource(name);
+ }
+
+ private class ResourceClassLoader extends URLClassLoader {
+
+ public ResourceClassLoader(URL[] urls, ClassLoader classLoader) {
+ super(urls, classLoader);
+ }
+
+ public URL getResource(String name) {
+ if (!contextPriorityClassLoader ||
+ name.startsWith("java/") ||
+ name.startsWith("javax/") ||
+ name.startsWith("org/apache/geronimo/") ||
+ name.startsWith("org/apache/tomcat") ||
+ name.startsWith("org/apache/naming") ||
+ name.startsWith("org/apache/catalina") ||
+ name.startsWith("org/xml/") ||
+ name.startsWith("org/w3c/")) {
+ return super.getResource(name);
+ }
+
+ // try to load the resource from this class loader
+ URL url = findResource(name);
+ if (url != null) {
+ return url;
+ }
+
+ // that didn't work... try the parent
+ return parent.getResource(name);
+ }
+ }
+}
Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java?rev=164653&r1=164652&r2=164653&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java Mon Apr 25 14:10:42 2005
@@ -16,17 +16,16 @@
*/
package org.apache.geronimo.tomcat;
+import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
-import org.apache.catalina.Host;
import org.apache.catalina.connector.Connector;
-import org.apache.catalina.core.StandardHost;
-import org.apache.catalina.startup.Embedded;
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.j2ee.j2eeobjectnames.NameFactory;
import org.apache.geronimo.system.serverinfo.ServerInfo;
/**
@@ -47,19 +46,9 @@
private static final String DEFAULT_CATALINA_HOME = "var/catalina";
/**
- * Work directory
- */
- private static final String WORK_DIR = "work";
-
- /**
* Reference to the org.apache.catalina.Embedded embedded.
*/
- private Embedded embedded;
-
- /**
- * Tomcat Host that will contain deployed contexts (webapps)
- */
- private Host host;
+ private TomcatGeronimoEmbedded embedded;
/**
* Tomcat Engine that will contain the host
@@ -86,8 +75,14 @@
/**
* GBean constructor (invoked dynamically when the gbean is declared in a plan)
*/
- public TomcatContainer(String catalinaHome, ServerInfo serverInfo) {
+ public TomcatContainer(String catalinaHome, ObjectRetriever engineGBean, ServerInfo serverInfo) {
setCatalinaHome(catalinaHome);
+
+ if (engineGBean == null){
+ throw new IllegalArgumentException("engineGBean cannot be null.");
+ }
+
+ this.engine = (Engine)engineGBean.getInternalObject();
this.serverInfo = serverInfo;
}
@@ -107,12 +102,12 @@
log.debug("doStart()");
log.info("Endorsed Dirs set to:" + System.getProperty("java.endorsed.dirs"));
-
+
// The comments are from the javadoc of the Embedded class
// 1. Instantiate a new instance of this class.
if (embedded == null) {
- embedded = new Embedded();
+ embedded = new TomcatGeronimoEmbedded();
}
// Assemble FileLogger as a gbean
@@ -126,39 +121,11 @@
// the default Realm if you are using container-managed security.
embedded.setUseNaming(false);
- // 3. Call createEngine() to create an Engine object, and then call its
- // property setters as desired.
- engine = embedded.createEngine();
- engine.setName("tomcat.engine");
- engine.setDefaultHost("localhost");
-
- // Set a default realm for Geronimo, or Tomcat will use JAASRealm
- // TomcatJAASRealm realm = new TomcatJAASRealm();
- // realm.setUserClassNames("org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal");
- // realm.setRoleClassNames("org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal");
- // engine.setRealm(realm);
-
// 4. Call createHost() to create at least one virtual Host associated
// with the newly created Engine, and then call its property setters as
// desired. After you customize this Host, add it to the corresponding
// Engine with engine.addChild(host).
- host = embedded.createHost("localhost", "");
- // TODO: Make it the gbean's attribute or tomcatwebappcontext's one
- ((StandardHost) host).setWorkDir(WORK_DIR);
-
- engine.addChild(host);
-
- // 5. Call createContext() to create at least one Context associated
- // with each newly created Host, and then call its property setters as
- // desired. You SHOULD create a Context with a pathname equal to a
- // zero-length string, which will be used to process all requests not
- // mapped to some other Context. After you customize this Context, add
- // it to the corresponding Host with host.addChild(context).
- // TODO: Make a default webapp configurable - another gbean?
- defaultContext = embedded.createContext("", "");
- defaultContext.setParentClassLoader(this.getClass().getClassLoader());
- host.addChild(defaultContext);
-
+
// 6. Call addEngine() to attach this Engine to the set of defined
// Engines for this object.
embedded.addEngine(engine);
@@ -171,7 +138,6 @@
public void doStop() throws Exception {
if (embedded != null) {
embedded.stop();
- embedded.getServer().await();
embedded = null;
}
}
@@ -186,15 +152,29 @@
* @see org.apache.catalina.startup.Embedded
* @see org.apache.catalina.Host
*/
- public void addContext(TomcatContext ctx) {
+ public void addContext(TomcatContext ctx) throws Exception{
Context anotherCtxObj = embedded.createContext(ctx.getPath(), ctx.getDocBase());
- anotherCtxObj.setParentClassLoader(this.getClass().getClassLoader());
+ anotherCtxObj.setParentClassLoader(ctx.getWebClassLoader());
+ //anotherCtxObj.setParentClassLoader(this.getClass().getClassLoader());
- // Set the context for thew Tomcat implementation
+ // Set the context for the Tomcat implementation
ctx.setContext(anotherCtxObj);
- // Have the context to set its properties
- ctx.setContextProperties();
+ // Have the context to set its properties if its a GeronimoStandardContext
+ if (anotherCtxObj instanceof GeronimoStandardContext)
+ ((GeronimoStandardContext)anotherCtxObj).setContextProperties(ctx);
+
+ //Was a virtual server defined?
+ String virtualServer = ctx.getVirtualServer();
+ if (virtualServer == null)
+ virtualServer = engine.getDefaultHost();
+
+ Container host = engine.findChild(virtualServer);
+ if (host == null){
+ throw new IllegalArgumentException("Invalid virtual host '" + virtualServer +"'. Do you have a matchiing Host entry in the plan?");
+ }
+
+ anotherCtxObj.setRealm(host.getRealm());
host.addChild(anotherCtxObj);
}
@@ -205,9 +185,8 @@
if (context != null)
embedded.removeContext(context);
- ctx.setContext(null);
}
-
+
public void setCatalinaHome(String catalinaHome) {
System.setProperty("catalina.home", catalinaHome);
}
@@ -225,9 +204,11 @@
static {
GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Tomcat Web Container", TomcatContainer.class);
- infoFactory.setConstructor(new String[] { "catalinaHome", "ServerInfo" });
+ infoFactory.setConstructor(new String[] { "catalinaHome", "engineGBean", "ServerInfo" });
infoFactory.addAttribute("catalinaHome", String.class, true);
+
+ infoFactory.addReference("engineGBean", ObjectRetriever.class, NameFactory.GERONIMO_SERVICE);
infoFactory.addReference("ServerInfo", ServerInfo.class, "GBean");
Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContext.java?rev=164653&r1=164652&r2=164653&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContext.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContext.java Mon Apr 25 14:10:42 2005
@@ -16,13 +16,19 @@
*/
package org.apache.geronimo.tomcat;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.catalina.Context;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.tomcat.util.SecurityHolder;
+import org.apache.geronimo.transaction.TrackedConnectionAssociator;
+import org.apache.geronimo.transaction.context.TransactionContextManager;
/**
* @version $Rev: 106522 $ $Date: 2004-11-25 01:28:57 +0100 (Thu, 25 Nov 2004) $
*/
public interface TomcatContext {
- public void setContextProperties();
public String getPath();
@@ -31,4 +37,23 @@
public Context getContext();
public String getDocBase();
+
+ public SecurityHolder getSecurityHolder();
+
+ public String getVirtualServer();
+
+ public ClassLoader getWebClassLoader();
+
+ public Map getComponentContext();
+
+ public Kernel getKernel();
+
+ public TransactionContextManager getTransactionContextManager();
+
+ public Set getApplicationManagedSecurityResources();
+
+ public TrackedConnectionAssociator getTrackedConnectionAssociator();
+
+ public Set getUnshareableResources();
+
}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatEngine.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatEngine.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatEngine.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatEngine.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,48 @@
+/**
+*
+* 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 org.apache.catalina.Engine;
+import org.apache.catalina.Realm;
+import org.apache.catalina.core.StandardEngine;
+import org.apache.geronimo.tomcat.realm.TomcatJAASRealm;
+
+public class TomcatEngine extends StandardEngine implements Engine{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3834312825844611385L;
+
+ public Realm getRealm() {
+ if (realm != null)
+ return realm;
+
+ if (parent != null){
+ Realm configured = parent.getRealm();
+ if (configured != null)
+ return configured;
+ }
+
+ //No realms found up the chain, so lets create a default JAAS Realm
+ TomcatJAASRealm defaultRealm = new TomcatJAASRealm();
+ defaultRealm.setUserClassNames("org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal");
+ defaultRealm.setRoleClassNames("org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal");
+ this.setRealm(defaultRealm);
+ return defaultRealm;
+ }
+}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoEmbedded.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoEmbedded.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoEmbedded.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoEmbedded.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,49 @@
+/**
+*
+* 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 org.apache.catalina.Context;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.startup.ContextConfig;
+import org.apache.catalina.startup.Embedded;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class TomcatGeronimoEmbedded extends Embedded{
+
+ private static final Log log = LogFactory.getLog(TomcatGeronimoEmbedded.class);
+
+ public Context createContext(String path, String docBase) {
+
+ if( log.isDebugEnabled() )
+ log.debug("Creating context '" + path + "' with docBase '" +
+ docBase + "'");
+
+ GeronimoStandardContext context = new GeronimoStandardContext();
+
+ context.setDocBase(docBase);
+ context.setPath(path);
+
+ ContextConfig config = new ContextConfig();
+ config.setCustomAuthenticators(authenticators);
+ ((Lifecycle) context).addLifecycleListener(config);
+
+ return (context);
+
+ }
+
+}
Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java?rev=164653&r1=164652&r2=164653&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java Mon Apr 25 14:10:42 2005
@@ -20,41 +20,28 @@
import java.net.URI;
import java.net.URL;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import javax.management.ObjectName;
+
import org.apache.catalina.Context;
-import org.apache.catalina.Realm;
-import org.apache.catalina.core.StandardContext;
-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.security.deploy.Security;
-import org.apache.geronimo.security.jacc.RoleDesignateSource;
-import org.apache.geronimo.naming.reference.KernelAwareReference;
-import org.apache.geronimo.naming.reference.ClassLoaderAwareReference;
-import org.apache.geronimo.naming.java.SimpleReadOnlyContext;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.j2ee.management.J2EEApplication;
+import org.apache.geronimo.j2ee.management.J2EEServer;
+import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.jmx.JMXUtil;
-import org.apache.geronimo.tomcat.valve.ComponentContextValve;
-import org.apache.geronimo.tomcat.valve.TransactionContextValve;
-import org.apache.geronimo.tomcat.valve.PolicyContextValve;
+import org.apache.geronimo.security.jacc.RoleDesignateSource;
+import org.apache.geronimo.tomcat.util.SecurityHolder;
import org.apache.geronimo.transaction.TrackedConnectionAssociator;
import org.apache.geronimo.transaction.context.OnlineUserTransaction;
import org.apache.geronimo.transaction.context.TransactionContextManager;
-import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.j2ee.management.J2EEApplication;
-import org.apache.geronimo.j2ee.management.J2EEServer;
-import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
-
-import javax.management.ObjectName;
-import javax.naming.NamingException;
/**
* Wrapper for a WebApplicationContext that sets up its J2EE environment.
@@ -67,6 +54,8 @@
protected final TomcatContainer container;
+ private final ClassLoader webClassLoader;
+
protected Context context = null;
private final URI webAppRoot;
@@ -74,43 +63,42 @@
private String path = null;
private String docBase = null;
-
- private final LoginConfig loginConfig;
-
- private final Realm tomcatRealm;
-
- private final Set securityConstraints;
-
- private final Set securityRoles;
+
+ private String virtualServer = null;
private final Map componentContext;
-
+
private final Kernel kernel;
+
+ private final Set unshareableResources;
+
+ private final Set applicationManagedSecurityResources;
+
+ private final TrackedConnectionAssociator trackedConnectionAssociator;
private final TransactionContextManager transactionContextManager;
- private final String policyContextID;
-
private final RoleDesignateSource roleDesignateSource;
+
+ private final SecurityHolder securityHolder;
private final J2EEServer server;
private final J2EEApplication application;
public TomcatWebAppContext(
+ ClassLoader classLoader,
String objectName,
String originalSpecDD,
URI webAppRoot,
URI[] webClassPath,
+ boolean contextPriorityClassLoader,
URL configurationBaseUrl,
- LoginConfig loginConfig,
- Realm tomcatRealm,
- Set securityConstraints,
- String policyContextID,
- String loginDomainName,
- Security securityConfig,
- Set securityRoles,
+ SecurityHolder securityHolder,
+ String virtualServer,
Map componentContext,
+ Set unshareableResources,
+ Set applicationManagedSecurityResources,
OnlineUserTransaction userTransaction,
TransactionContextManager transactionContextManager,
TrackedConnectionAssociator trackedConnectionAssociator,
@@ -119,8 +107,9 @@
J2EEServer server,
J2EEApplication application,
Kernel kernel)
- throws NamingException {
+ throws Exception {
+ assert classLoader != null;
assert webAppRoot != null;
assert webClassPath != null;
assert configurationBaseUrl != null;
@@ -133,24 +122,36 @@
this.container = container;
this.setDocBase(this.webAppRoot.getPath());
- this.tomcatRealm = tomcatRealm;
- this.policyContextID = policyContextID;
- this.securityConstraints = securityConstraints;
- this.securityRoles = securityRoles;
- this.loginConfig = loginConfig;
+ this.virtualServer = virtualServer;
+ this.securityHolder = securityHolder;
this.componentContext = componentContext;
this.transactionContextManager = transactionContextManager;
+ this.unshareableResources = unshareableResources;
+ this.applicationManagedSecurityResources = applicationManagedSecurityResources;
+ this.trackedConnectionAssociator = trackedConnectionAssociator;
this.roleDesignateSource = roleDesignateSource;
this.server = server;
this.application = application;
+
+ URI root = URI.create(configurationBaseUrl.toString());
+ webAppRoot = root.resolve(webAppRoot);
+ URL webAppRootURL = webAppRoot.toURL();
+
+ URL[] urls = new URL[webClassPath.length];
+ for (int i = 0; i < webClassPath.length; i++) {
+ URI classPathEntry = webClassPath[i];
+ classPathEntry = root.resolve(classPathEntry);
+ urls[i] = classPathEntry.toURL();
+ }
+ this.webClassLoader = new TomcatClassLoader(urls, webAppRootURL, classLoader, contextPriorityClassLoader);
this.kernel = kernel;
ObjectName myObjectName = JMXUtil.getObjectName(objectName);
verifyObjectName(myObjectName);
- if (tomcatRealm != null){
+ if (securityHolder != null){
if (roleDesignateSource == null) {
throw new IllegalArgumentException("RoleDesignateSource must be supplied for a secure web app");
}
@@ -172,77 +173,24 @@
this.docBase = docBase;
}
- public void setContextProperties() {
- context.setDocBase(webAppRoot.getPath());
- context.setPath(path);
-
- // Security
- if (tomcatRealm != null) {
- if (tomcatRealm instanceof TomcatGeronimoRealm) {
- ((TomcatGeronimoRealm) tomcatRealm).setContext(context);
- }
-
- context.setRealm(tomcatRealm);
- }
-
- if (loginConfig != null)
- context.setLoginConfig(loginConfig);
-
- // Add the security constraints
- if (securityConstraints != null) {
- Iterator conIterator = securityConstraints.iterator();
- while (conIterator.hasNext()) {
- context.addConstraint((SecurityConstraint) conIterator.next());
- }
- }
-
- // Add the security roles
- if (securityRoles != null) {
- Iterator secIterator = securityRoles.iterator();
- while (secIterator.hasNext()) {
- context.addSecurityRole((String) secIterator.next());
- }
- }
+ public Map getComponentContext() {
+ return componentContext;
+ }
- // create ReadOnlyContext
- javax.naming.Context enc = null;
- try {
- if (componentContext != null) {
- for (Iterator iterator = componentContext.values().iterator(); iterator
- .hasNext();) {
- Object value = iterator.next();
- if (value instanceof KernelAwareReference) {
- ((KernelAwareReference) value).setKernel(kernel);
- }
- if (value instanceof ClassLoaderAwareReference) {
- ((ClassLoaderAwareReference) value)
- .setClassLoader(context.getLoader()
- .getClassLoader());
- }
- }
- enc = new SimpleReadOnlyContext(componentContext);
- }
- } catch (NamingException ne) {
- log.error(ne);
- }
+ public String getVirtualServer() {
+ return virtualServer;
+ }
- // Set the valves for the context
- if (enc != null) {
- ComponentContextValve contextValve = new ComponentContextValve(enc);
- ((StandardContext) context).addValve(contextValve);
- }
+ public ClassLoader getWebClassLoader() {
+ return webClassLoader;
+ }
- if (transactionContextManager != null) {
- TransactionContextValve transactionValve = new TransactionContextValve(
- transactionContextManager);
- ((StandardContext) context).addValve(transactionValve);
- }
+ public Kernel getKernel() {
+ return kernel;
+ }
- if (policyContextID != null) {
- PolicyContextValve policyValve = new PolicyContextValve(
- policyContextID);
- ((StandardContext) context).addValve(policyValve);
- }
+ public TransactionContextManager getTransactionContextManager() {
+ return transactionContextManager;
}
public Context getContext() {
@@ -261,6 +209,23 @@
this.path = path;
}
+ public SecurityHolder getSecurityHolder() {
+ return securityHolder;
+ }
+
+
+ public Set getApplicationManagedSecurityResources() {
+ return applicationManagedSecurityResources;
+ }
+
+ public TrackedConnectionAssociator getTrackedConnectionAssociator() {
+ return trackedConnectionAssociator;
+ }
+
+ public Set getUnshareableResources() {
+ return unshareableResources;
+ }
+
/**
* ObjectName must match this pattern: <p/>
* domain:j2eeType=WebModule,name=MyName,J2EEServer=MyServer,J2EEApplication=MyApplication
@@ -326,29 +291,26 @@
"Tomcat WebApplication Context", TomcatWebAppContext.class,
NameFactory.WEB_MODULE);
+ infoBuilder.addAttribute("classLoader", ClassLoader.class, false);
infoBuilder.addAttribute("objectName", String.class, false);
infoBuilder.addAttribute("deploymentDescriptor", String.class, true);
infoBuilder.addAttribute("webAppRoot", URI.class, true);
infoBuilder.addAttribute("webClassPath", URI[].class, true);
+ infoBuilder.addAttribute("contextPriorityClassLoader", boolean.class, true);
infoBuilder.addAttribute("configurationBaseUrl", URL.class, true);
infoBuilder.addAttribute("path", String.class, true);
- infoBuilder.addAttribute("loginConfig", LoginConfig.class, true);
-
- infoBuilder.addAttribute("tomcatRealm", Realm.class, true);
- infoBuilder.addAttribute("securityConstraints", Set.class, true);
-
- infoBuilder.addAttribute("policyContextID", String.class, true);
- infoBuilder.addAttribute("loginDomainName", String.class, true);
- infoBuilder.addAttribute("securityConfig", Security.class, true);
- infoBuilder.addAttribute("securityRoles", Set.class, true);
+ infoBuilder.addAttribute("securityHolder", SecurityHolder.class, true);
+ infoBuilder.addAttribute("virtualServer", String.class, true);
infoBuilder.addAttribute("componentContext", Map.class, true);
+ infoBuilder.addAttribute("unshareableResources", Set.class, true);
+ infoBuilder.addAttribute("applicationManagedSecurityResources", Set.class, true);
infoBuilder.addAttribute("userTransaction",
OnlineUserTransaction.class, true);
- infoBuilder.addReference("TransactionContextManager",
+ infoBuilder.addReference("transactionContextManager",
TransactionContextManager.class, NameFactory.JTA_RESOURCE);
- infoBuilder.addReference("TrackedConnectionAssociator",
+ infoBuilder.addReference("trackedConnectionAssociator",
TrackedConnectionAssociator.class, NameFactory.JCA_RESOURCE);
infoBuilder.addReference("Container", TomcatContainer.class,
@@ -360,22 +322,21 @@
infoBuilder.addAttribute("kernel", Kernel.class, false);
infoBuilder.setConstructor(new String[] {
+ "classLoader",
"objectName",
"deploymentDescriptor",
"webAppRoot",
"webClassPath",
+ "contextPriorityClassLoader",
"configurationBaseUrl",
- "loginConfig",
- "tomcatRealm",
- "securityConstraints",
- "policyContextID",
- "loginDomainName",
- "securityConfig",
- "securityRoles",
+ "securityHolder",
+ "virtualServer",
"componentContext",
+ "unshareableResources",
+ "applicationManagedSecurityResources",
"userTransaction",
- "TransactionContextManager",
- "TrackedConnectionAssociator",
+ "transactionContextManager",
+ "trackedConnectionAssociator",
"Container",
"RoleDesignateSource",
"J2EEServer",
Copied: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java (from r161874, geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoRealm.java)
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java?p2=geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java&p1=geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoRealm.java&r1=161874&r2=164653&rev=164653&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoRealm.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java Mon Apr 25 14:10:42 2005
@@ -14,14 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.tomcat;
+package org.apache.geronimo.tomcat.realm;
import java.io.IOException;
import java.security.AccessControlContext;
import java.security.AccessControlException;
-import java.security.PermissionCollection;
import java.security.Principal;
-import java.util.Map;
+
import javax.security.auth.Subject;
import javax.security.auth.login.AccountExpiredException;
import javax.security.auth.login.CredentialExpiredException;
@@ -46,27 +45,18 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.security.ContextManager;
-import org.apache.geronimo.security.IdentificationPrincipal;
-import org.apache.geronimo.security.SubjectId;
-import org.apache.geronimo.security.deploy.DefaultPrincipal;
import org.apache.geronimo.security.jacc.PolicyContextHandlerContainerSubject;
-import org.apache.geronimo.security.util.ConfigurationUtil;
+import org.apache.geronimo.tomcat.JAASTomcatPrincipal;
public class TomcatGeronimoRealm extends JAASRealm {
private static final Log log = LogFactory.getLog(TomcatGeronimoRealm.class);
- private final String policyContextID;
- private final Subject defaultSubject;
- private final DefaultPrincipal defaultPrincipal;
- private final PermissionCollection checked;
- private final PermissionCollection excluded;
- private final Map roleDesignates;
- private final String loginDomainName;
-
- private Context context = null;
+// private Context context = null;
private static ThreadLocal currentRequest = new ThreadLocal();
+
+ private boolean enabled = false;
/**
* Descriptive information about this <code>Realm</code> implementation.
@@ -78,30 +68,7 @@
*/
protected static final String name = "TomcatGeronimoRealm";
- public TomcatGeronimoRealm(String policyContextID,
- DefaultPrincipal defaultPrincipal,
- String loginDomainName,
- PermissionCollection checkedPermissions,
- PermissionCollection excludedPermissions,
- Map roleDesignates) {
-
- assert policyContextID != null;
- assert defaultPrincipal != null;
-
- this.policyContextID = policyContextID;
- this.defaultPrincipal = defaultPrincipal;
- this.loginDomainName = loginDomainName;
- this.defaultSubject = ConfigurationUtil.generateDefaultSubject(defaultPrincipal);
- this.checked = checkedPermissions;
- this.excluded = excludedPermissions;
- this.roleDesignates = roleDesignates;
-
- /**
- * Register our default subject with the ContextManager
- */
- ContextManager.registerSubject(defaultSubject);
- SubjectId id = ContextManager.getSubjectId(defaultSubject);
- defaultSubject.getPrincipals().add(new IdentificationPrincipal(id));
+ public TomcatGeronimoRealm() {
}
@@ -208,7 +175,7 @@
//If we have no principal, then we should use the default.
if (principal == null) {
- ContextManager.setCurrentCaller(defaultSubject);
+ return false;
} else {
ContextManager.setCurrentCaller(((JAASTomcatPrincipal) principal).getSubject());
}
@@ -239,6 +206,7 @@
String relativeURI = requestURI.substring(contextPath.length());
String servletPath = relativeURI;
String name = null;
+ Context context = request.getContext();
//Try exact match
if (!(relativeURI.equals("/")))
@@ -360,7 +328,7 @@
}
try {
- loginContext = new LoginContext(loginDomainName, new JAASCallbackHandler(this, username, credentials));
+ loginContext = new LoginContext(appName, new JAASCallbackHandler(this, username, credentials));
} catch (Throwable e) {
log.error(sm.getString("jaasRealm.unexpectedError"), e);
return (null);
@@ -452,7 +420,6 @@
}
-
/**
* Gracefully shut down active use of the public methods of this <code>Component</code>.
*
@@ -464,12 +431,5 @@
// Perform normal superclass finalization
super.stop();
- // Remove the defaultSubject
- ContextManager.unregisterSubject(defaultSubject);
}
-
- public void setContext(Context context) {
- this.context = context;
- }
-
}
Copied: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatJAASRealm.java (from r161874, geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatJAASRealm.java)
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatJAASRealm.java?p2=geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatJAASRealm.java&p1=geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatJAASRealm.java&r1=161874&r2=164653&rev=164653&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatJAASRealm.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatJAASRealm.java Mon Apr 25 14:10:42 2005
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.tomcat;
+package org.apache.geronimo.tomcat.realm;
import java.security.Principal;
import javax.security.auth.Subject;
@@ -35,27 +35,26 @@
/**
* @version $Rev: 106522 $ $Date: 2004-11-25 01:28:57 +0100 (Thu, 25 Nov 2004) $
*/
-public class TomcatJAASRealm extends JAASRealm {
+public class TomcatJAASRealm extends JAASRealm implements Cloneable {
private static final Log log = LogFactory.getLog(TomcatJAASRealm.class);
+
+ private static final String DEFAULT_NAME = "tomcat";
/**
* Descriptive information about this <code>Realm</code> implementation.
*/
- protected static final String info = "org.apache.geronimo.tomcat.TomcatJAASRealm/1.0";
+ protected static final String info = "org.apache.geronimo.tomcat.realm.TomcatJAASRealm/1.0";
/**
* Descriptive information about this <code>Realm</code> implementation.
*/
protected static final String name = "TomcatJAASRealm";
- private String loginDomainName = null;
- public TomcatJAASRealm(String loginDomainName) {
+ public TomcatJAASRealm() {
super();
-
- this.loginDomainName = loginDomainName;
-
}
+
/**
* Return the <code>Principal</code> associated with the specified
* username and credentials, if there is one; otherwise return
@@ -76,7 +75,7 @@
try {
LoginContext loginContext = null;
if (appName == null)
- appName = "Tomcat";
+ appName = DEFAULT_NAME;
if (log.isDebugEnabled())
log.debug(sm.getString("jaasRealm.beginLogin", username, appName));
@@ -90,7 +89,7 @@
}
try {
- loginContext = new LoginContext(loginDomainName, new JAASCallbackHandler(this, username, credentials));
+ loginContext = new LoginContext(appName, new JAASCallbackHandler(this, username, credentials));
} catch (Throwable e) {
log.error(sm.getString("jaasRealm.unexpectedError"), e);
return (null);
@@ -161,4 +160,7 @@
}
}
+ public Object clone() throws CloneNotSupportedException{
+ return super.clone();
+ }
}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/util/SecurityHolder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/util/SecurityHolder.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/util/SecurityHolder.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/util/SecurityHolder.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,77 @@
+/**
+ *
+ * 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.util;
+
+import java.security.PermissionCollection;
+import org.apache.geronimo.security.deploy.DefaultPrincipal;
+
+public class SecurityHolder
+{
+
+ private String policyContextID;
+ private DefaultPrincipal defaultPrincipal;
+ private PermissionCollection checked;
+ private PermissionCollection excluded;
+
+ public SecurityHolder()
+ {
+ policyContextID = null;
+ defaultPrincipal = null;
+ checked = null;
+ excluded = null;
+ }
+
+ public PermissionCollection getChecked()
+ {
+ return checked;
+ }
+
+ public void setChecked(PermissionCollection checked)
+ {
+ this.checked = checked;
+ }
+
+ public DefaultPrincipal getDefaultPrincipal()
+ {
+ return defaultPrincipal;
+ }
+
+ public void setDefaultPrincipal(DefaultPrincipal defaultPrincipal)
+ {
+ this.defaultPrincipal = defaultPrincipal;
+ }
+
+ public PermissionCollection getExcluded()
+ {
+ return excluded;
+ }
+
+ public void setExcluded(PermissionCollection excluded)
+ {
+ this.excluded = excluded;
+ }
+
+ public String getPolicyContextID()
+ {
+ return policyContextID;
+ }
+
+ public void setPolicyContextID(String policyContextID)
+ {
+ this.policyContextID = policyContextID;
+ }
+}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/InstanceContextValve.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/InstanceContextValve.java?rev=164653&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/InstanceContextValve.java (added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/InstanceContextValve.java Mon Apr 25 14:10:42 2005
@@ -0,0 +1,68 @@
+/**
+ *
+ * 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.valve;
+
+import java.io.IOException;
+import java.util.Set;
+
+import javax.resource.ResourceException;
+import javax.servlet.ServletException;
+
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.apache.catalina.valves.ValveBase;
+import org.apache.geronimo.transaction.DefaultInstanceContext;
+import org.apache.geronimo.transaction.InstanceContext;
+import org.apache.geronimo.transaction.TrackedConnectionAssociator;
+
+/**
+ * @version $Rev: $ $Date: $
+ */
+public class InstanceContextValve extends ValveBase {
+
+ private final Set unshareableResources;
+
+ private final Set applicationManagedSecurityResources;
+
+ private final TrackedConnectionAssociator trackedConnectionAssociator;
+
+ public InstanceContextValve(Set unshareableResources,
+ Set applicationManagedSecurityResources,
+ TrackedConnectionAssociator trackedConnectionAssociator) {
+ this.unshareableResources = unshareableResources;
+ this.applicationManagedSecurityResources = applicationManagedSecurityResources;
+ this.trackedConnectionAssociator = trackedConnectionAssociator;
+ }
+
+ public void invoke(Request request, Response response) throws IOException,
+ ServletException {
+
+ try {
+ InstanceContext oldContext = trackedConnectionAssociator
+ .enter(new DefaultInstanceContext(unshareableResources,
+ applicationManagedSecurityResources));
+
+ // Pass this request on to the next valve in our pipeline
+ getNext().invoke(request, response);
+
+ // Set the old one back
+ trackedConnectionAssociator.exit((InstanceContext) oldContext);
+ } catch (ResourceException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
Modified: geronimo/trunk/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/geronimo-web.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/geronimo-web.xml?rev=164653&r1=164652&r2=164653&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/geronimo-web.xml (original)
+++ geronimo/trunk/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/geronimo-web.xml Mon Apr 25 14:10:42 2005
@@ -24,7 +24,7 @@
<context-root>/test</context-root>
<context-priority-classloader>false</context-priority-classloader>
<sec:security>
- <sec:default-principal realm-name="demo-properties-realm">
+ <sec:default-principal realm-name="geronimo-properties-realm">
<sec:principal class="org.apache.geronimo.security.realm.providers.PropertiesFileUserPrincipal" name="metro"/>
</sec:default-principal>
</sec:security>
Modified: geronimo/trunk/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/web.xml?rev=164653&r1=164652&r2=164653&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/web.xml (original)
+++ geronimo/trunk/modules/tomcat/src/test-resources/deployables/war3/WEB-INF/web.xml Mon Apr 25 14:10:42 2005
@@ -52,7 +52,7 @@
<login-config>
<auth-method>FORM</auth-method>
- <realm-name>Test JAAS Realm</realm-name>
+ <realm-name>geronimo-properties-realm</realm-name>
<form-login-config>
<form-login-page>/auth/logon.html?param=test</form-login-page>
<form-error-page>/auth/logonError.html?param=test</form-error-page>