1 17 package org.apache.geronimo.tomcat.valve; 18 19 import java.io.IOException ; 20 21 import javax.servlet.ServletException ; 22 import javax.security.auth.Subject ; 23 24 import org.apache.catalina.valves.ValveBase; 25 import org.apache.catalina.connector.Request; 26 import org.apache.catalina.connector.Response; 27 import org.apache.geronimo.security.ContextManager; 28 import org.apache.geronimo.security.Callers; 29 30 33 public class DefaultSubjectValve extends ValveBase { 34 35 private final Subject defaultSubject; 36 37 public DefaultSubjectValve(Subject defaultSubject) { 38 this.defaultSubject = defaultSubject; 39 } 40 41 public void invoke(Request request, Response response) throws IOException , ServletException { 42 Callers oldCallers = null; 43 boolean setSubject = false; 44 if (defaultSubject != null) { 45 oldCallers = ContextManager.getCallers(); 46 setSubject = oldCallers == null || oldCallers.getCurrentCaller() == null; 47 } 48 if (setSubject) { 49 ContextManager.setCallers(defaultSubject, defaultSubject); 50 try { 51 getNext().invoke(request, response); 52 } finally { 53 ContextManager.popCallers(oldCallers); 54 } 55 } else { 56 getNext().invoke(request, response); 57 } 58 59 } 60 } 61 | Popular Tags |