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 6637999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:22:57+00:00 2026-05-25T23:22:57+00:00

(Using Java 6 and Tomcat 6.) Is there a way for me to get

  • 0

(Using Java 6 and Tomcat 6.)

Is there a way for me to get HttpServletRequest.getRemoteUser() to return a value in my development environment (i.e. localhost) without needing to modify my application’s web.xml file?

The reason I ask is that the authentication implementation when the app is deployed to a remote environment is handled by a web server and plugged-in tool. Running locally I obviously do not have the plugged-in tool or a separate web server; I just have Tomcat 6. I am trying to avoid adding code to my application merely to support development on my localhost.

I am hoping there is a modification I can make to the context.xml or server.xml files that will let me set the remote user ID or that will try to pull it from a HTTP header or something.

  • 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-25T23:22:58+00:00Added an answer on May 25, 2026 at 11:22 pm

    Here is a proof of concept Valve implementation which does it:

    import java.io.IOException;
    import java.security.Principal;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.servlet.ServletException;
    
    import org.apache.catalina.connector.Request;
    import org.apache.catalina.connector.Response;
    import org.apache.catalina.realm.GenericPrincipal;
    import org.apache.catalina.valves.ValveBase;
    
    public class RemoteUserValve extends ValveBase {
    
        public RemoteUserValve() {
        }
    
        @Override
        public void invoke(final Request request, final Response response)
                throws IOException, ServletException {
            final String username = "myUser";
            final String credentials = "credentials";
            final List<String> roles = new ArrayList<String>();
    
                // Tomcat 7 version
            final Principal principal = new GenericPrincipal(username, 
                                credentials, roles);
                // Tomcat 6 version:
                // final Principal principal = new GenericPrincipal(null, 
                //              username, credentials, roles);
    
    
            request.setUserPrincipal(principal);
    
            getNext().invoke(request, response);
        }
    
    }
    

    (Tested with Tomcat 7.0.21.)

    Compile it, put it inside a jar and copy the jar to the apache-tomcat-7.0.21/lib folder. You need to modify the server.xml:

    <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">
    
        <Valve className="remoteuservalve.RemoteUserValve" />
    ...
    

    I suppose it works inside the Engine and Context containers too.

    More information:

    • The Valve Component
    • Valve javadoc
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to retrieve the absolute path of url (http://localhost:8080/myApp) in java.
Is there a way to load files stored inside JARs using getResourceAsStream from Tomcat
I am using Java 6 64-bit and STANDALONE Tomcat 6.0.18 on Vista 64-bit. I
We have an application running on Tomcat 6.0.32 and using JSSE (Java 1.6.0_26) for
We have tried to create sample webservices helloworld in Java using Jersey and Tomcat
How to create simple webserver in Java using Eclipse, Tomcat and Jersey i.e steps
I am using Tomcat server for my java based Application . My question is
I am working on Java web service using TOMCAT server over secured connection(SSL). Client
I am developing a java web application using eclipse and tomcat server. Application consists
I am working on the Java web service and using Tomcat server. Since this

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.