You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2010/03/13 20:19:35 UTC

svn commit: r922653 - in /openwebbeans/trunk/webbeans-tomcat: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/webbeans/ src/main/java/org/apache/webbeans/web/ src/main/java/org/apache/webbeans/web/...

Author: gerdogdu
Date: Sat Mar 13 19:19:34 2010
New Revision: 922653

URL: http://svn.apache.org/viewvc?rev=922653&view=rev
Log:
[OWB-324] Add Tomcat Plugin

Added:
    openwebbeans/trunk/webbeans-tomcat/pom.xml   (with props)
    openwebbeans/trunk/webbeans-tomcat/src/
    openwebbeans/trunk/webbeans-tomcat/src/main/
    openwebbeans/trunk/webbeans-tomcat/src/main/java/
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/ContextLifecycleListener.java   (with props)
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatInstanceListener.java   (with props)
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityListener.java   (with props)
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityService.java   (with props)
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatUtil.java   (with props)
    openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatWebPlugin.java   (with props)
    openwebbeans/trunk/webbeans-tomcat/src/main/resources/
    openwebbeans/trunk/webbeans-tomcat/src/main/resources/META-INF/
    openwebbeans/trunk/webbeans-tomcat/src/main/resources/META-INF/services/
    openwebbeans/trunk/webbeans-tomcat/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin
    openwebbeans/trunk/webbeans-tomcat/src/test/
    openwebbeans/trunk/webbeans-tomcat/src/test/java/
Modified:
    openwebbeans/trunk/webbeans-tomcat/   (props changed)

Propchange: openwebbeans/trunk/webbeans-tomcat/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Mar 13 19:19:34 2010
@@ -0,0 +1,5 @@
+.settings
+target
+.classpath
+.project
+asdas.jardesc

Added: openwebbeans/trunk/webbeans-tomcat/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat/pom.xml?rev=922653&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-tomcat/pom.xml (added)
+++ openwebbeans/trunk/webbeans-tomcat/pom.xml Sat Mar 13 19:19:34 2010
@@ -0,0 +1,59 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<!--
+
+    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.
+-->
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.openwebbeans</groupId>
+        <artifactId>openwebbeans</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>openwebbeans-tomcat</artifactId>
+    <name>Apache OpenWebBeans :: Apache Tomcat Web Profile</name>
+    <packaging>jar</packaging>
+    <description>OpenWebBeans Apache Tomcat Web Profile</description>
+
+    <dependencies>
+
+
+	 <dependency>
+	      <groupId>org.apache.tomcat</groupId>
+	      <artifactId>catalina</artifactId>
+	      <version>6.0.26</version>
+	      <scope>provided</scope>
+	    </dependency>
+	 <dependency>
+	 	<groupId>org.apache.openwebbeans</groupId>
+	 	<artifactId>openwebbeans-spi</artifactId>
+	 	<version>${project.version}</version>
+	 	<scope>provided</scope>
+	 </dependency>
+	 <dependency>
+	 	<groupId>org.apache.geronimo.specs</groupId>
+	 	<artifactId>geronimo-jcdi_1.0_spec</artifactId>
+	 	<version>1.0-SNAPSHOT</version>
+	 	<scope>provided</scope>
+	 </dependency>
+	 <dependency>
+	 	<groupId>org.apache.geronimo.specs</groupId>
+	 	<artifactId>geronimo-atinject_1.0_spec</artifactId>
+	 	<version>1.0-SNAPSHOT</version>
+	 	<scope>provided</scope>
+	 </dependency>      
+    </dependencies>
+</project>

Propchange: openwebbeans/trunk/webbeans-tomcat/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/ContextLifecycleListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/ContextLifecycleListener.java?rev=922653&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/ContextLifecycleListener.java (added)
+++ openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/ContextLifecycleListener.java Sat Mar 13 19:19:34 2010
@@ -0,0 +1,405 @@
+/**
+ *
+ * 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.webbeans.web.tomcat;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.ContainerListener;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Service;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.core.ContainerBase;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardEngine;
+import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.core.StandardServer;
+import org.apache.naming.ContextAccessController;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+
+/**
+ * Context lifecycle listener. Adapted from
+ * OpenEJB Tomcat and updated.
+ * 
+ * @version $Rev$ $Date$
+ *
+ */
+public class ContextLifecycleListener implements PropertyChangeListener, LifecycleListener, ContainerListener
+{
+
+    private StandardServer standardServer;
+
+    public ContextLifecycleListener()
+    {
+    }
+
+    public void lifecycleEvent(LifecycleEvent event)
+    {
+        try
+        {
+            if (event.getSource() instanceof StandardServer)
+            {
+                if (event.getType().equals(Lifecycle.START_EVENT))
+                {
+                    this.standardServer = (StandardServer) event.getSource();
+                    start();
+                }
+            }
+            else if (event.getSource() instanceof StandardContext)
+            {
+                StandardContext context = (StandardContext) event.getSource();
+                
+                if (event.getType().equals(Lifecycle.START_EVENT))
+                {
+                    ServletContext scontext = context.getServletContext();
+                    URL url = scontext.getResource("/WEB-INF/beans.xml");
+                    if (url != null)
+                    {
+                        String[] oldListeners = context.findApplicationListeners();
+                        LinkedList<String> listeners = new LinkedList<String>();
+                        listeners.addFirst("org.apache.webbeans.servlet.WebBeansConfigurationListener");
+                        for(String listener : oldListeners)
+                        {
+                            listeners.add(listener);
+                            context.removeApplicationListener(listener);
+                        }
+                        
+                        for(String listener : listeners)
+                        {
+                            context.addApplicationListener(listener);
+                        }                        
+                        
+                        context.addApplicationListener(TomcatSecurityListener.class.getName());
+                        context.addInstanceListener(TomcatInstanceListener.class.getName());                        
+                    }
+                }
+            }                        
+        }catch(Exception e)
+        {
+            e.printStackTrace();
+        }        
+    }
+
+    @Override
+    public void containerEvent(ContainerEvent event)
+    {
+        StandardContext context = null;
+        
+        try
+        {
+            if(event.getSource() instanceof StandardContext)
+            {               
+                context = (StandardContext)event.getSource();
+                
+                if(event.getType().equals("beforeContextInitialized"))
+                {
+                    ClassLoader loader = context.getLoader().getClassLoader();
+                    Object listener = event.getData();
+                    
+                    if(listener.getClass().getName().equals("org.apache.webbeans.servlet.WebBeansConfigurationListener"))
+                    {
+                       ContextAccessController.setWritable(context.getNamingContextListener().getName(), context);                       
+                       return;
+                    }
+                    else
+                    {
+                        URL url = context.getServletContext().getResource("/WEB-INF/beans.xml");
+                        if(url != null)
+                        {
+                            TomcatUtil.inject(listener, loader);   
+                        }
+                    }
+                    
+                }
+                else if(event.getType().equals("afterContextInitialized"))
+                {
+                    ClassLoader loader = context.getLoader().getClassLoader();
+                    Object listener = event.getData();
+                    
+                    if(listener.getClass().getName().equals("org.apache.webbeans.servlet.WebBeansConfigurationListener"))
+                    {   
+                        ContextAccessController.setReadOnly(context.getNamingContextListener().getName());
+                        
+                        URL url = context.getServletContext().getResource("/WEB-INF/beans.xml");
+                        if(url != null)
+                        {
+                            Object[] listeners = context.getApplicationEventListeners();
+                            for(Object instance : listeners)
+                            {
+                                if(!instance.getClass().getName().equals("org.apache.webbeans.servlet.WebBeansConfigurationListener"))
+                                {                                
+                                    TomcatUtil.inject(instance, loader);   
+                                }
+                            }                                                                                    
+                        }                        
+                    }                                
+                }
+                else if(event.getType().equals("beforeContextDestroyed"))
+                {
+                    Object listener = event.getData();
+                    if(listener.getClass().getName().equals("org.apache.webbeans.servlet.WebBeansConfigurationListener"))
+                    {
+                        ContextAccessController.setWritable(context.getNamingContextListener().getName(),context);   
+                    }
+                }
+            }        
+            
+        }catch(Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+    
+    public void start()
+    {
+        // hook the hosts so we get notified before contexts are started
+        standardServer.addPropertyChangeListener(this);
+        standardServer.addLifecycleListener(this);
+        for (Service service : standardServer.findServices())
+        {
+            serviceAdded(service);
+        }
+    }
+
+    public void stop()
+    {
+        standardServer.removePropertyChangeListener(this);
+    }
+
+    private void serviceAdded(Service service)
+    {
+        Container container = service.getContainer();
+        if (container instanceof StandardEngine)
+        {
+            StandardEngine engine = (StandardEngine) container;
+            engineAdded(engine);
+        }
+    }
+
+    private void serviceRemoved(Service service)
+    {
+        Container container = service.getContainer();
+        if (container instanceof StandardEngine)
+        {
+            StandardEngine engine = (StandardEngine) container;
+            engineRemoved(engine);
+        }
+    }
+
+    private void engineAdded(StandardEngine engine)
+    {
+        addContextListener(engine);
+        for (Container child : engine.findChildren())
+        {
+            if (child instanceof StandardHost)
+            {
+                StandardHost host = (StandardHost) child;
+                hostAdded(host);
+            }
+        }
+    }
+
+    private void engineRemoved(StandardEngine engine)
+    {
+        for (Container child : engine.findChildren())
+        {
+            if (child instanceof StandardHost)
+            {
+                StandardHost host = (StandardHost) child;
+                hostRemoved(host);
+            }
+        }
+    }
+
+    private void hostAdded(StandardHost host)
+    {
+        addContextListener(host);
+        host.addLifecycleListener(this);
+        for (Container child : host.findChildren())
+        {
+            if (child instanceof StandardContext)
+            {
+                StandardContext context = (StandardContext) child;
+                contextAdded(context);
+            }
+        }
+    }
+
+    private void hostRemoved(StandardHost host)
+    {
+        for (Container child : host.findChildren())
+        {
+            if (child instanceof StandardContext)
+            {
+                StandardContext context = (StandardContext) child;
+                contextRemoved(context);
+            }
+        }
+    }
+
+    private void contextAdded(StandardContext context)
+    {
+        // put this class as the first listener so we can process the
+        // application before any classes are loaded
+        forceFirstLifecycleListener(context);
+    }
+
+    private void forceFirstLifecycleListener(StandardContext context)
+    {
+        LifecycleListener[] listeners = context.findLifecycleListeners();
+
+        // if we are already first return
+        if (listeners.length > 0 && listeners[0] == this)
+        {
+            return;
+        }
+
+        // remove all of the current listeners
+        for (LifecycleListener listener : listeners)
+        {
+            context.removeLifecycleListener(listener);
+        }
+
+        // add this class (as first)
+        context.addLifecycleListener(this);
+        context.addContainerListener(this);
+
+        // add back all listeners
+        for (LifecycleListener listener : listeners)
+        {
+            if (listener != this)
+            {
+                context.addLifecycleListener(listener);
+            }
+        }
+    }
+
+    private void contextRemoved(StandardContext context)
+    {
+        
+    }
+
+    public void propertyChange(PropertyChangeEvent event)
+    {
+        if ("service".equals(event.getPropertyName()))
+        {
+            Object oldValue = event.getOldValue();
+            Object newValue = event.getNewValue();
+            if (oldValue == null && newValue instanceof Service)
+            {
+                serviceAdded((Service) newValue);
+            }
+            if (oldValue instanceof Service && newValue == null)
+            {
+                serviceRemoved((Service) oldValue);
+            }
+        }
+        if ("children".equals(event.getPropertyName()))
+        {
+            Object source = event.getSource();
+            Object oldValue = event.getOldValue();
+            Object newValue = event.getNewValue();
+            if (source instanceof StandardEngine)
+            {
+                if (oldValue == null && newValue instanceof StandardHost)
+                {
+                    hostAdded((StandardHost) newValue);
+                }
+                if (oldValue instanceof StandardHost && newValue == null)
+                {
+                    hostRemoved((StandardHost) oldValue);
+                }
+            }
+            if (source instanceof StandardHost)
+            {
+                if (oldValue == null && newValue instanceof StandardContext)
+                {
+                    contextAdded((StandardContext) newValue);
+                }
+                if (oldValue instanceof StandardContext && newValue == null)
+                {
+                    contextRemoved((StandardContext) oldValue);
+                }
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void addContextListener(ContainerBase containerBase)
+    {
+        try
+        {
+            Field field = ContainerBase.class.getDeclaredField("children");
+            field.setAccessible(true);
+            Map<Object,Object> children = (Map<Object,Object>) field.get(containerBase);
+            if (children instanceof ContextLifecycleListener.MoniterableHashMap)
+            {
+                return;
+            }
+            children = new ContextLifecycleListener.MoniterableHashMap(children, containerBase, "children", this);
+            field.set(containerBase, children);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+
+    }
+
+    public static class MoniterableHashMap extends HashMap<Object,Object>
+    {
+        private static final long serialVersionUID = 1L;
+
+        private final Object source;
+        private final String propertyName;
+        private final PropertyChangeListener listener;
+
+        public MoniterableHashMap(Map<Object,Object> m, Object source, String propertyName, PropertyChangeListener listener)
+        {
+            super(m);
+            this.source = source;
+            this.propertyName = propertyName;
+            this.listener = listener;
+        }
+
+        public Object put(Object key, Object value)
+        {
+            Object oldValue = super.put(key, value);
+            PropertyChangeEvent event = new PropertyChangeEvent(source, propertyName, null, value);
+            listener.propertyChange(event);
+            return oldValue;
+        }
+
+        public Object remove(Object key)
+        {
+            Object value = super.remove(key);
+            PropertyChangeEvent event = new PropertyChangeEvent(source, propertyName, value, null);
+            listener.propertyChange(event);
+            return value;
+        }
+    }
+}

Propchange: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/ContextLifecycleListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatInstanceListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatInstanceListener.java?rev=922653&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatInstanceListener.java (added)
+++ openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatInstanceListener.java Sat Mar 13 19:19:34 2010
@@ -0,0 +1,74 @@
+/*
+ * 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.webbeans.web.tomcat;
+
+import java.net.URL;
+
+import org.apache.catalina.InstanceEvent;
+import org.apache.catalina.InstanceListener;
+import org.apache.catalina.Wrapper;
+import org.apache.catalina.core.StandardContext;
+
+public class TomcatInstanceListener implements InstanceListener
+{
+    public TomcatInstanceListener()
+    {
+    }
+
+    @Override
+    public void instanceEvent(InstanceEvent event)
+    {
+        String type = event.getType();
+        
+        if(type.equals(InstanceEvent.BEFORE_INIT_EVENT) ||
+                type.equals(InstanceEvent.BEFORE_FILTER_EVENT))
+        {
+            Wrapper wrapper = event.getWrapper();
+            StandardContext context = (StandardContext) wrapper.getParent();
+
+            try
+            {
+                URL url =  context.getServletContext().getResource("/WEB-INF/beans.xml");
+                
+                if(url == null)
+                {
+                    return;
+                }
+                
+                Object object = event.getServlet();
+                if(object == null)
+                {
+                    object = event.getFilter();
+                }
+                
+                if(object != null)
+                {
+                    ClassLoader loader = wrapper.getLoader().getClassLoader();
+                    TomcatUtil.inject(object, loader);
+                }
+                
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }            
+        }
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatInstanceListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityListener.java?rev=922653&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityListener.java (added)
+++ openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityListener.java Sat Mar 13 19:19:34 2010
@@ -0,0 +1,61 @@
+/*
+ * 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.webbeans.web.tomcat;
+
+import java.security.Principal;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+import javax.servlet.http.HttpServletRequest;
+
+public class TomcatSecurityListener implements ServletRequestListener
+{
+    public static ThreadLocal<Principal> principal = new ThreadLocal<Principal>();
+    
+    public TomcatSecurityListener()
+    {
+        
+    }
+    
+    @Override
+    public void requestDestroyed(ServletRequestEvent event)
+    {
+        if(principal.get() != null)
+        {
+            principal.remove();   
+        }
+    }
+
+    @Override
+    public void requestInitialized(ServletRequestEvent event)
+    {
+        ServletRequest request = event.getServletRequest();
+        if(request instanceof HttpServletRequest)
+        {
+            Principal p = ((HttpServletRequest)request).getUserPrincipal();
+            if(p != null)
+            {
+                principal.set(p);
+            }
+        }
+        
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityService.java?rev=922653&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityService.java (added)
+++ openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityService.java Sat Mar 13 19:19:34 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.webbeans.web.tomcat;
+
+import java.security.Principal;
+
+import org.apache.webbeans.spi.SecurityService;
+
+public class TomcatSecurityService implements SecurityService
+{
+
+    @Override
+    public Principal getCurrentPrincipal()
+    {
+        return TomcatSecurityListener.principal.get();
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatSecurityService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatUtil.java?rev=922653&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatUtil.java (added)
+++ openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatUtil.java Sat Mar 13 19:19:34 2010
@@ -0,0 +1,31 @@
+/*
+ * 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.webbeans.web.tomcat;
+
+import java.lang.reflect.Method;
+
+public class TomcatUtil
+{
+    public static void inject(Object object, ClassLoader loader) throws Exception
+    {
+        Class<?> injector = loader.loadClass("org.apache.webbeans.inject.OWBInjector");
+        Method method = injector.getDeclaredMethod("inject", new Class<?>[]{Object.class});
+        method.invoke(null, new Object[]{object});        
+    }
+}

Propchange: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatWebPlugin.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatWebPlugin.java?rev=922653&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatWebPlugin.java (added)
+++ openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatWebPlugin.java Sat Mar 13 19:19:34 2010
@@ -0,0 +1,95 @@
+/*
+ * 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.webbeans.web.tomcat;
+
+import javax.servlet.Filter;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletRequestAttributeListener;
+import javax.servlet.ServletRequestListener;
+import javax.servlet.http.HttpSessionActivationListener;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingListener;
+import javax.servlet.http.HttpSessionListener;
+
+import org.apache.webbeans.plugins.AbstractOwbPlugin;
+import org.apache.webbeans.plugins.OpenWebBeansWebPlugin;
+import org.apache.webbeans.spi.SecurityService;
+
+public class TomcatWebPlugin extends AbstractOwbPlugin implements OpenWebBeansWebPlugin
+{
+    private final TomcatSecurityService securityService = new TomcatSecurityService();
+    
+    public TomcatWebPlugin()
+    {
+        
+    }
+    
+    
+
+    /* (non-Javadoc)
+     * @see org.apache.webbeans.plugins.AbstractOwbPlugin#getSupportedService(java.lang.Class)
+     */
+    @Override
+    public <T> T getSupportedService(Class<T> serviceClass)
+    {
+        if(serviceClass.equals(SecurityService.class))
+        {
+            return serviceClass.cast(this.securityService);
+        }
+        
+        return null;
+    }
+
+
+
+    @Override
+    public void isManagedBean(Class<?> clazz) throws Exception
+    {
+        if(Servlet.class.isAssignableFrom(clazz) ||
+                Filter.class.isAssignableFrom(clazz) ||
+                ServletContextListener.class.isAssignableFrom(clazz) ||
+                ServletContextAttributeListener.class.isAssignableFrom(clazz) ||
+                HttpSessionActivationListener.class.isAssignableFrom(clazz) ||
+                HttpSessionAttributeListener.class.isAssignableFrom(clazz) ||
+                HttpSessionBindingListener.class.isAssignableFrom(clazz) ||
+                HttpSessionListener.class.isAssignableFrom(clazz) ||
+                ServletRequestListener.class.isAssignableFrom(clazz) ||
+                ServletRequestAttributeListener.class.isAssignableFrom(clazz) )
+        {
+            throw new Exception("Given class is not contextual");
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.webbeans.plugins.AbstractOwbPlugin#supportService(java.lang.Class)
+     */
+    @Override
+    public boolean supportService(Class<?> serviceClass)
+    {
+        if(serviceClass.equals(SecurityService.class))
+        {
+            return true;
+        }
+        
+        return false;
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-tomcat/src/main/java/org/apache/webbeans/web/tomcat/TomcatWebPlugin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-tomcat/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin?rev=922653&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-tomcat/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin (added)
+++ openwebbeans/trunk/webbeans-tomcat/src/main/resources/META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin Sat Mar 13 19:19:34 2010
@@ -0,0 +1,17 @@
+#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.
+org.apache.webbeans.web.tomcat.TomcatWebPlugin
\ No newline at end of file