Home » geronimo-2.2-source-release » org.apache.geronimo.tomcat.listener » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.geronimo.tomcat.listener;
   18   
   19   import java.util.Stack;
   20   
   21   import javax.security.auth.Subject;
   22   import org.apache.catalina.Container;
   23   import org.apache.catalina.InstanceEvent;
   24   import org.apache.catalina.InstanceListener;
   25   import org.apache.catalina.Wrapper;
   26   import org.apache.geronimo.security.Callers;
   27   import org.apache.geronimo.security.ContextManager;
   28   import org.apache.geronimo.tomcat.GeronimoStandardContext;
   29   
   30   public class RunAsInstanceListener implements InstanceListener {
   31   
   32       private static final ThreadLocal<Stack<Callers>> threadLocal = new ThreadLocal<Stack<Callers>>() {
   33           protected Stack<Callers> initialValue() {
   34               return new Stack<Callers>();
   35           }
   36       };
   37   
   38       public void instanceEvent(InstanceEvent event) {
   39   
   40           if (event.getType().equals(InstanceEvent.BEFORE_SERVICE_EVENT)) {
   41               Container parent = event.getWrapper().getParent();
   42               if (parent instanceof GeronimoStandardContext) {
   43                   Stack<Callers> callersStack = threadLocal.get();
   44                   GeronimoStandardContext context = (GeronimoStandardContext) parent;
   45                   Wrapper wrapper = event.getWrapper();
   46                   String runAsRole = wrapper.getRunAs();
   47                   Subject runAsSubject = context.getSubjectForRole(runAsRole);
   48                   Callers oldCallers = ContextManager.pushNextCaller(runAsSubject);
   49                   callersStack.push(oldCallers);
   50               }
   51           } else if (event.getType().equals(InstanceEvent.AFTER_SERVICE_EVENT)) {
   52               Container parent = event.getWrapper().getParent();
   53               if (parent instanceof GeronimoStandardContext) {
   54                   Stack<Callers> callersStack = threadLocal.get();
   55                   Callers oldCallers = callersStack.pop();
   56                   ContextManager.popCallers(oldCallers);
   57               }
   58           }
   59       }
   60   }

Home » geronimo-2.2-source-release » org.apache.geronimo.tomcat.listener » [javadoc | source]