Servlet servlet = event.getServlet();
ServletConfig config = servlet.getServletConfig();
String servletName = config.getServletName();
Subject runAsSubject = context.getRoleDesignate(servletName);
if (runAsSubject != null) {
Callers oldCallers = ContextManager.getCallers();
ContextManager.registerSubject(runAsSubject);
ContextManager.pushNextCaller(runAsSubject);
threadLocal.set(oldCallers);
}
}
}
else if (event.getType().equals(InstanceEvent.AFTER_SERVICE_EVENT)) {
Callers oldCallers = threadLocal.get();
if (oldCallers!=null) {
ContextManager.popCallers(oldCallers);
}
}
}