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

  • SEARCH
  • Home
  • 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 8578667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:26:37+00:00 2026-06-11T20:26:37+00:00

I have been stuck on this one for a while. I am trying to

  • 0

I have been stuck on this one for a while. I am trying to access the ContainerServlet I implemented using HttpClient with Tomcat 7. I keep getting the error message “Restricted(ContainerServlet)”. I have added Basic Authentication and tried to set it up just like the built in Host-Manager application with no luck.

My HostManagerServlet starts with:

public class HostManagerServlet
extends HttpServlet implements ContainerServlet {...

My web.xml contains:

<servlet>
            <servlet-name>virtualHostCreator</servlet-name>
            <servlet-class>com.eatmyfish.servlets.HostManagerServlet</servlet-class>
          </servlet>
          <servlet-mapping>
            <servlet-name>virtualHostCreator</servlet-name>
            <url-pattern>/virtualhostcreator/*</url-pattern>
          </servlet-mapping>
    <security-constraint>
        <web-resource-collection>
          <web-resource-name>HostManager commands</web-resource-name>
          <url-pattern>/virtualhostcreator/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
           <!-- NOTE:  This role is not present in the default users file -->
           <role-name>admin-script</role-name>
        </auth-constraint>
      </security-constraint>
      <security-constraint>
        <web-resource-collection>
          <web-resource-name>HTMLHostManager commands</web-resource-name>
          <url-pattern>/virtualhostcreator/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
           <!-- NOTE:  This role is not present in the default users file -->
           <role-name>admin-gui</role-name>
        </auth-constraint>
      </security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
  </login-config>
<security-role>
    <description>
      The role that is required to log in to the Host Manager Application HTML
      interface
    </description>
    <role-name>admin-gui</role-name>
  </security-role>
  <security-role>
    <description>
      The role that is required to log in to the Host Manager Application text
      interface
    </description>
    <role-name>admin-script</role-name>
  </security-role>

My tomcat-users.xml contains:

.
.
.
<role rolename="admin-gui"/>
  <role rolename="admin-script"/>
  <role rolename="manager-gui"/>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat,admin-gui,admin-script,manager-gui"/>
.
.
.

The code that makes the HttpClient call (I’ve tried a few different approaches):

Approach One –

String url = environment.getProperty("baseurl");
        url += "virtualhostcreator/createVirualHost?name="+group.getGroupName();
        HttpClient httpclient = new DefaultHttpClient();

        HttpGet httpget = new HttpGet(url);
        httpget.addHeader(BasicScheme.authenticate(
                 new UsernamePasswordCredentials("tomcat", "tomcat"),
                 "UTF-8", false));
        HttpResponse response = httpclient.execute(httpget);

Approach Two –

String url = environment.getProperty("baseurl");
        url += "virtualhostcreator/createVirualHost?name="+group.getGroupName();
        DefaultHttpClient httpclient = new DefaultHttpClient();
        httpclient.getCredentialsProvider().setCredentials(
                new AuthScope("localhost", 8080),
                new UsernamePasswordCredentials("tomcat", "tomcat"));
        // Create AuthCache instance
        AuthCache authCache = new BasicAuthCache();
        // Generate BASIC scheme object and add it to the local
        // auth cache
        HttpHost targetHost = new HttpHost("localhost", 8080, "http");
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(targetHost, basicAuth);

        // Add AuthCache to the execution context
        BasicHttpContext localcontext = new BasicHttpContext();
        localcontext.setAttribute("http.auth.auth-cache", authCache);

        HttpGet httpget = new HttpGet(url);

        HttpResponse response = httpclient.execute(targetHost, httpget,localcontext);

The error’s stacktrace:

SEVERE: Allocate exception for servlet virtualHostCreator
java.lang.SecurityException: Restricted (ContainerServlet) class com.eatmyfish.servlets.HostManagerServlet
    at org.apache.catalina.core.DefaultInstanceManager.checkAccess(DefaultInstanceManager.java:536)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:124)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

Any ideas what I am doing wrong? I cannot get past the Restricted(ContainerServlet) error.

  • 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-06-11T20:26:38+00:00Added an answer on June 11, 2026 at 8:26 pm

    I had a similar problem in Tomcat 7 and was able to work around it by editing the top-level element in ./conf/context.xml to look like

    <Context privileged="true">
    

    What I can’t figure out is how Tomcat’s own manager servlets are able to load without this configuration. Anybody have any clues?

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

Sidebar

Related Questions

I have been stuck on this one for a while, I'm not an expert
I have been stuck on this one for a while - I couldn't figure
I have been stuck on this for a while now and I cannot seem
I have been stuck on this for a while. i have tried and I
Been kind of stuck on this one for a while now, so any help
Could use some help. I am utterly stuck, been trying to fix this one
I've been stuck on this one for a while and any advice would be
I've been stuck on this one for a while, so any help is greatly
I've been stuck on this issue for a while. What I have here is
I have been scratching my head on this one for a while, so I

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.