[jboss-cvs] JBossAS SVN: r60407 - in trunk/embedded: src/main/java/org/jboss/embedded and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 7 16:57:48 EST 2007
Author: bill.burke at jboss.com
Date: 2007-02-07 16:57:48 -0500 (Wed, 07 Feb 2007)
New Revision: 60407
Added:
trunk/embedded/src/main/java/org/jboss/embedded/tomcat/TomcatWebinfScanner.java
trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/
trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/SecurityAssociationValve.java
trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/SecuritySetupListener.java
trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/TomcatLoginModule.java
trunk/embedded/src/test/resources/war-security/
trunk/embedded/src/test/resources/war-security/Test.jsp
trunk/embedded/src/test/resources/war-security/WEB-INF/
trunk/embedded/src/test/resources/war-security/WEB-INF/web.xml
trunk/embedded/src/test/resources/war-security/hello.html
Modified:
trunk/embedded/build-test.xml
trunk/embedded/build.xml
trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroup.java
trunk/embedded/src/main/java/org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.java
Log:
add global scanner for Tomcat
start trying to embedded JBoss JAAS into Tomcat
Modified: trunk/embedded/build-test.xml
===================================================================
--- trunk/embedded/build-test.xml 2007-02-07 21:45:54 UTC (rev 60406)
+++ trunk/embedded/build-test.xml 2007-02-07 21:57:48 UTC (rev 60407)
@@ -191,6 +191,13 @@
<include name="EjbTestCase.jsp"/>
</fileset>
</war>
+ <war warfile="${build.lib}/war-security.war"
+ webxml="${resources}/war-security/WEB-INF/web.xml">
+ <fileset dir="${resources}/war-security">
+ <include name="*.html"/>
+ <include name="*.jsp"/>
+ </fileset>
+ </war>
</target>
Modified: trunk/embedded/build.xml
===================================================================
--- trunk/embedded/build.xml 2007-02-07 21:45:54 UTC (rev 60406)
+++ trunk/embedded/build.xml 2007-02-07 21:57:48 UTC (rev 60407)
@@ -324,6 +324,8 @@
<jar jarfile="${build.lib}/embedded-jboss/lib/jboss-embedded-tomcat-bootstrap.jar">
<fileset dir="${build.classes}">
<include name="org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.class"/>
+ <include name="org/jboss/embedded/tomcat/TomcatWebinfScanner.class"/>
+ <include name="org/jboss/embedded/tomcat/security/*.class"/>
</fileset>
</jar>
@@ -331,6 +333,8 @@
<fileset dir="${build.classes}">
<include name="org/jboss/**"/>
<exclude name="org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.class"/>
+ <exclude name="org/jboss/embedded/tomcat/TomcatWebinfScanner.class"/>
+ <exclude name="org/jboss/embedded/tomcat/security/*.class"/>
</fileset>
<fileset dir="../ejb3/src/resources">
<include name="META-INF/persistence.properties"/>
Modified: trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroup.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroup.java 2007-02-07 21:45:54 UTC (rev 60406)
+++ trunk/embedded/src/main/java/org/jboss/embedded/DeploymentGroup.java 2007-02-07 21:57:48 UTC (rev 60407)
@@ -373,6 +373,12 @@
addVirtualFiles(getDeployerDirUrls(filter, directory, recurse));
}
+
+ public ArrayList<DeploymentContext> getDeployments()
+ {
+ return deployments;
+ }
+
public static List<VirtualFile> getDeployerDirUrlsFromResource(VirtualFileFilter filter, ClassLoader loader, String resource, boolean recurse)
throws DeploymentException, IOException
{
Modified: trunk/embedded/src/main/java/org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.java 2007-02-07 21:45:54 UTC (rev 60406)
+++ trunk/embedded/src/main/java/org/jboss/embedded/tomcat/EmbeddedJBossBootstrapListener.java 2007-02-07 21:57:48 UTC (rev 60407)
@@ -54,7 +54,7 @@
{
innerStart();
}
- else if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType()))
+ else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType()))
{
innerStop();
}
Added: trunk/embedded/src/main/java/org/jboss/embedded/tomcat/TomcatWebinfScanner.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/tomcat/TomcatWebinfScanner.java (rev 0)
+++ trunk/embedded/src/main/java/org/jboss/embedded/tomcat/TomcatWebinfScanner.java 2007-02-07 21:57:48 UTC (rev 60407)
@@ -0,0 +1,118 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.embedded.tomcat;
+
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.Container;
+import org.apache.catalina.Pipeline;
+import org.apache.catalina.core.StandardContext;
+import org.jboss.embedded.tomcat.security.SecurityAssociationValve;
+import org.jboss.embedded.Bootstrap;
+import org.jboss.embedded.DeploymentGroup;
+import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+
+import javax.naming.directory.DirContext;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.File;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Searches for WAR's WEB-INF directory and deploys that directory.
+ * A JBoss DeploymentContext is created and the StandardContext is added as an attachment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class TomcatWebinfScanner implements LifecycleListener
+{
+ private DeploymentGroup group;
+
+ public void lifecycleEvent(LifecycleEvent event)
+ {
+ if (event.getType().equals(Lifecycle.BEFORE_START_EVENT))
+ {
+ if (!(event.getSource() instanceof Container)) return;
+
+ StandardContext container = (StandardContext)event.getSource();
+ Method getBasePath = getBasePathMethod();
+ String basePath;
+ try
+ {
+ basePath = (String)getBasePath.invoke(container);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ File baseDir = new File(basePath, "WEB-INF");
+ DeploymentContext deployment;
+ group = Bootstrap.getInstance().createDeploymentGroup();
+ try
+ {
+ group.add(baseDir.toURL());
+ deployment = group.getDeployments().get(0);
+ deployment.getTransientAttachments().addAttachment(StandardContext.class, container);
+ group.process();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ else if (event.getType().equals(Lifecycle.AFTER_STOP_EVENT))
+ {
+ try
+ {
+ group.undeploy();
+ }
+ catch (DeploymentException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ }
+
+ private static Method basePathMethod;
+
+ private static synchronized Method getBasePathMethod()
+ {
+ if (basePathMethod != null) return basePathMethod;
+ try
+ {
+ basePathMethod = StandardContext.class.getDeclaredMethod("getBasePath");
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ basePathMethod.setAccessible(true);
+ return basePathMethod;
+ }
+}
Added: trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/SecurityAssociationValve.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/SecurityAssociationValve.java (rev 0)
+++ trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/SecurityAssociationValve.java 2007-02-07 21:57:48 UTC (rev 60407)
@@ -0,0 +1,97 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.embedded.tomcat.security;
+
+import org.apache.catalina.valves.ValveBase;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.apache.catalina.Session;
+import org.apache.catalina.Manager;
+import org.apache.catalina.Wrapper;
+import org.apache.catalina.Container;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.security.Principal;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class SecurityAssociationValve extends ValveBase
+{
+
+
+ public SecurityAssociationValve()
+ {
+ }
+
+ public SecurityAssociationValve(Container container)
+ {
+ this.setContainer(container);
+ }
+
+ public void invoke(Request request, Response response) throws IOException, ServletException
+ {
+ Principal caller = request.getPrincipal();
+ System.out.println("******* caller principal: " + caller);
+
+ Principal userPrincipal = request.getUserPrincipal();
+ System.out.println("******* user principal: " + userPrincipal);
+
+ HttpSession hsession = request.getSession(false);
+ Session session = null;
+
+ // If there is a session, get the tomcat session for the principal
+ Manager manager = container.getManager();
+ if (manager != null && hsession != null)
+ {
+ try
+ {
+ session = manager.findSession(hsession.getId());
+ }
+ catch (IOException ignore)
+ {
+ }
+ }
+
+ if (session != null)
+ {
+ System.out.println("***** principal from session: " + session.getPrincipal());
+ }
+ else
+ {
+ System.out.println("Session was null");
+ }
+ Wrapper servlet = request.getWrapper();
+ System.out.println("RUNAS: " + servlet.getRunAs());
+ if (servlet.getRealm() == null) System.out.println("Servlet realm was null");
+ getNext().invoke(request, response);
+
+
+
+
+ }
+}
Added: trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/SecuritySetupListener.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/SecuritySetupListener.java (rev 0)
+++ trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/SecuritySetupListener.java 2007-02-07 21:57:48 UTC (rev 60407)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.embedded.tomcat.security;
+
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Contained;
+import org.apache.catalina.Container;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.Pipeline;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class SecuritySetupListener implements LifecycleListener
+{
+ public void lifecycleEvent(LifecycleEvent event)
+ {
+ if (event.getType().equals(Lifecycle.AFTER_START_EVENT))
+ {
+ if (!(event.getSource() instanceof Container)) return;
+
+ Container container = (Container)event.getSource();
+ Pipeline pipe = container.getPipeline();
+ if (pipe == null)
+ {
+ System.out.println("******** pipe was null");
+ }
+ else container.getPipeline().addValve(new SecurityAssociationValve(container));
+ }
+
+ }
+}
Added: trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/TomcatLoginModule.java
===================================================================
--- trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/TomcatLoginModule.java (rev 0)
+++ trunk/embedded/src/main/java/org/jboss/embedded/tomcat/security/TomcatLoginModule.java 2007-02-07 21:57:48 UTC (rev 60407)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.embedded.tomcat.security;
+
+import org.jboss.security.auth.spi.AbstractServerLoginModule;
+
+import javax.security.auth.login.LoginException;
+import javax.servlet.http.HttpServletRequest;
+import java.security.Principal;
+import java.security.acl.Group;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class TomcatLoginModule extends AbstractServerLoginModule
+{
+ static ThreadLocal<HttpServletRequest> request = new ThreadLocal<HttpServletRequest>();
+ @Override
+ public boolean login() throws LoginException
+ {
+ return super.login(); //To change body of overridden methods use File | Settings | File Templates.
+ }
+
+ protected Principal getIdentity()
+ {
+ return request.get().getUserPrincipal();
+ }
+
+ protected Group[] getRoleSets() throws LoginException
+ {
+ return new Group[0];
+ }
+
+}
Added: trunk/embedded/src/test/resources/war-security/Test.jsp
===================================================================
--- trunk/embedded/src/test/resources/war-security/Test.jsp (rev 0)
+++ trunk/embedded/src/test/resources/war-security/Test.jsp 2007-02-07 21:57:48 UTC (rev 60407)
@@ -0,0 +1,2 @@
+<h1>Hello JSP principal: <%=request.getUserPrincipal()%></h1>
+
Added: trunk/embedded/src/test/resources/war-security/WEB-INF/web.xml
===================================================================
--- trunk/embedded/src/test/resources/war-security/WEB-INF/web.xml (rev 0)
+++ trunk/embedded/src/test/resources/war-security/WEB-INF/web.xml 2007-02-07 21:57:48 UTC (rev 60407)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app>
+ <description>Embedded Security Test</description>
+
+ <!-- ### Security -->
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>Restricted</web-resource-name>
+ <description>Declarative security tests</description>
+ <url-pattern>/*</url-pattern>
+ <http-method>HEAD</http-method>
+ <http-method>GET</http-method>
+ <http-method>POST</http-method>
+ <http-method>PUT</http-method>
+ <http-method>DELETE</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <description>Only authenticated users can access secure content</description>
+ <role-name>tomcat</role-name>
+ </auth-constraint>
+
+ <user-data-constraint>
+ <transport-guarantee>NONE</transport-guarantee>
+ </user-data-constraint>
+ </security-constraint>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>Blah blah</realm-name>
+ </login-config>
+
+ <security-role>
+ <description>A user validated by an X-MyAuthentication</description>
+ <role-name>tomcat</role-name>
+ </security-role>
+
+
+
+</web-app>
Added: trunk/embedded/src/test/resources/war-security/hello.html
===================================================================
--- trunk/embedded/src/test/resources/war-security/hello.html (rev 0)
+++ trunk/embedded/src/test/resources/war-security/hello.html 2007-02-07 21:57:48 UTC (rev 60407)
@@ -0,0 +1 @@
+<h1>Hello World</h1>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list