Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7598867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:31:05+00:00 2026-05-30T22:31:05+00:00

I was reading through the Tomcat source code, trying to figure out how the

  • 0

I was reading through the Tomcat source code, trying to figure out how
the tomcat internals are protected against unauthorized access from servlets.
One thing I noticed was the fact that the servlets gain access to the StandardContext through the ApplicationContextFacade, which seems to act as a broker for the ApplicationContext, rather than allowing servlets to have direct access to the ApplicationContext.

I was wondering why the ApplicationContextFacade is passed to the servlet rather than the ApplicationContext.
I suspect this has something to do with security (as the facade is hardly a simplification of the interface, so not really a typical facade pattern).
I looked at the code and saw that it basically forwards requests (as expected), but conditioned on some security settings (such as Globals.IS_SECURITY_ENABLED and SecurityUtil.isPackageProtectionEnabled()) it seems to use java reflection to pass the request.
I know that the permissions change when using reflection, but I’m not entirely sure how this would enforce some security policy in the ApplicationContextFacade?

It would be great if somebody could clarify this for me!

Thank you in advance for your help.

link to javadoc
http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/core/ApplicationContextFacade.html

link to tomcat source:
http://tomcat.apache.org/download-70.cgi

example of the facade code:

public String getMimeType(String file) {
        if (SecurityUtil.isPackageProtectionEnabled()) {
            return (String)doPrivileged("getMimeType", new Object[]{file});
        } else {
            return context.getMimeType(file);
        }
    }

where context is the associated ApplicationContext object
and doPrivileged is defined as follows:

 private Object doPrivileged(final String methodName, final Object[] params){
        try{
            return invokeMethod(context, methodName, params);
        }catch(Throwable t){
            throw new RuntimeException(t.getMessage(), t);
        }
    }

and finally invokeMethod

private Object invokeMethod(ApplicationContext appContext,
                                final String methodName, 
                                Object[] params) 
        throws Throwable{

        try{
            Method method = (Method)objectCache.get(methodName);
            if (method == null){
                method = appContext.getClass()
                    .getMethod(methodName, (Class[])classCache.get(methodName));
                objectCache.put(methodName, method);
            }

            return executeMethod(method,appContext,params);
        } catch (Exception ex){
            handleException(ex, methodName);
            return null;
        } finally {
            params = null;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:31:06+00:00Added an answer on May 30, 2026 at 10:31 pm

    I think you needed to visit one more method:

    ApplicationContextFacade.executeMethod

    468 private Object executeMethod(final Method method, 
    469                              final ApplicationContext context,
    470                              final Object[] params) 
    471         throws PrivilegedActionException, 
    472                IllegalAccessException,
    473                InvocationTargetException {
    474                                  
    475     if (SecurityUtil.isPackageProtectionEnabled()){
    476        return AccessController.doPrivileged(new PrivilegedExceptionAction(){
    477             public Object run() throws IllegalAccessException, InvocationTargetException{
    478                 return method.invoke(context,  params);
    479             }
    480         });
    481     } else {
    482         return method.invoke(context, params);
    483     }        
    484 }
    

    I would take a look at that in combination with this answer – When should AccessController.doPrivileged() be used?.

    I think that the untrusted code/classloader (the webapp) might not be allowed to do certain things, so the trusted code (Tomcat) can invoke a doPrivileged in order to temporarily override the webapp’s more restricted privileges.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whilst reading through the DirectWrite source code I came across the following struct: ///
Reading through the Backbone.js source code, I saw this: validObj[attr] = void 0; What
Reading through the documentation for powershells add-type it seems you can add JScript code
I'm reading through Apple's documentation on CA, and I was trying to do a
Reading through more SICP and I'm stuck on exercise 1.3.8 . My code works
Reading through wikipedia I came across the concept of Sprints in Agile development. From
Reading through the documentation on Apache Tomcat, when I deploy a webapp it copies
I'm reading through some MSDN example code on Composite controls and finding that there
When reading through parfib.hs code on github, I saw this comment about memory allocation
After reading through many code examples for Google Guice, I see a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.