Home » geronimo-2.2-source-release » org.apache.geronimo.tomcat.interceptor » [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.interceptor;
   18   
   19   import javax.security.jacc.PolicyContext;
   20   import javax.security.auth.Subject;
   21   import javax.servlet.ServletRequest;
   22   import javax.servlet.ServletResponse;
   23   
   24   import org.apache.geronimo.security.Callers;
   25   import org.apache.geronimo.security.ContextManager;
   26   
   27   public class PolicyContextBeforeAfter implements BeforeAfter{
   28   
   29       public static final String DEFAULT_SUBJECT = "~DEFAULT_SUBJECT";
   30   
   31       private final BeforeAfter next;
   32       private final String policyContextID;
   33       private final int policyContextIDIndex;
   34       private final int callersIndex;
   35       private final int defaultSubjectIndex;
   36       private final Subject defaultSubject;
   37   
   38       public PolicyContextBeforeAfter(BeforeAfter next, int policyContextIDIndex, int callersIndex, int defaultSubjectIndex, String policyContextID, Subject defaultSubject) {
   39           this.next = next;
   40           this.policyContextIDIndex = policyContextIDIndex;
   41           this.callersIndex = callersIndex;
   42           this.defaultSubjectIndex = defaultSubjectIndex;
   43           this.policyContextID = policyContextID;
   44           this.defaultSubject = defaultSubject;
   45       }
   46   
   47       public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse, int dispatch) {
   48   
   49           //Save the old
   50   
   51   //        context[policyContextIDIndex] = PolicyContext.getContextID();
   52           context[callersIndex] = ContextManager.getCallers();
   53   
   54           //Set the new
   55   //        PolicyContext.setContextID(policyContextID);
   56   //        PolicyContext.setHandlerData(httpRequest);
   57           if (httpRequest != null){
   58               context[defaultSubjectIndex] = httpRequest.getAttribute(DEFAULT_SUBJECT);
   59               httpRequest.setAttribute(DEFAULT_SUBJECT, defaultSubject);
   60           }
   61   
   62   
   63           if (next != null) {
   64               next.before(context, httpRequest, httpResponse, dispatch);
   65           }
   66       }
   67   
   68       public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse, int dispatch) {
   69           if (next != null) {
   70               next.after(context, httpRequest, httpResponse, dispatch);
   71           }
   72   
   73           //Replace the old
   74   //        PolicyContext.setContextID((String)context[policyContextIDIndex]);
   75           // Must unset handler data from thread - see GERONIMO-4574
   76   //        PolicyContext.setHandlerData(null);
   77           ContextManager.popCallers((Callers) context[callersIndex]);
   78           if (httpRequest != null)
   79               httpRequest.setAttribute(DEFAULT_SUBJECT, context[defaultSubjectIndex]);
   80   
   81       }
   82   
   83   }
   84   

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