Home » geronimo-2.2-source-release » org.apache.geronimo.concurrent.impl.handlers » [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.concurrent.impl.handlers;
   18   
   19   import java.util.Map;
   20   
   21   import javax.security.jacc.PolicyContext;
   22   
   23   import org.apache.commons.logging.Log;
   24   import org.apache.commons.logging.LogFactory;
   25   import org.apache.geronimo.concurrent.ManagedContextHandler;
   26   import org.apache.geronimo.security.Callers;
   27   import org.apache.geronimo.security.ContextManager;
   28   
   29   /*
   30    * Security context handler.
   31    */
   32   public class SecurityContextHandler implements ManagedContextHandler {
   33   
   34       private final static Log LOG = LogFactory.getLog(SecurityContextHandler.class);
   35       
   36       private final static String OLD_CALLERS = 
   37           SecurityContextHandler.class.getName() + ".oldCallers";
   38       
   39       private final static String OLD_CONTEXT_ID = 
   40           SecurityContextHandler.class.getName() + ".oldContextId";
   41       
   42       private final static String NEW_CALLERS = 
   43           SecurityContextHandler.class.getName() + ".newCallers";
   44       
   45       private final static String NEW_CONTEXT_ID = 
   46           SecurityContextHandler.class.getName() + ".newContextId";
   47               
   48       public void saveContext(Map<String, Object> context) {
   49           LOG.debug("saveContext");
   50           
   51           context.put(NEW_CONTEXT_ID, 
   52                       PolicyContext.getContextID());
   53           context.put(NEW_CALLERS, 
   54                       ContextManager.getCallers());
   55       }
   56   
   57       public void setContext(Map<String, Object> threadContext) {
   58           LOG.debug("setContext");
   59           
   60           // save existing security info
   61           threadContext.put(OLD_CONTEXT_ID, 
   62                             PolicyContext.getContextID());
   63           threadContext.put(OLD_CALLERS, 
   64                             ContextManager.getCallers());
   65       
   66           // set new security info
   67           String contextId = (String)threadContext.get(NEW_CONTEXT_ID);
   68           Callers callers = (Callers)threadContext.get(NEW_CALLERS);
   69           
   70           PolicyContext.setContextID(contextId);
   71           ContextManager.popCallers(callers); // works like setCallers()
   72       }
   73   
   74       public void unsetContext(Map<String, Object> threadContext) {
   75           LOG.debug("unsetContext");
   76           
   77           // restore old security info
   78           String contextId = (String)threadContext.get(OLD_CONTEXT_ID);
   79           Callers callers = (Callers)threadContext.get(OLD_CALLERS);
   80           
   81           PolicyContext.setContextID(contextId);
   82           ContextManager.popCallers(callers); // works like setCallers()
   83       }
   84     
   85   }

Home » geronimo-2.2-source-release » org.apache.geronimo.concurrent.impl.handlers » [javadoc | source]