How do I set the remote user in Tomcat?

10,431

Getting a value from HttpServletRequest.getRemoteUser() in Tomcat without modifying application - This answer contains a Valve which does exactly this. It works with Tomcat, tested with Tomcat 6 and Tomcat 7.

Getting a value from HttpServletRequest.getRemoteUser() in Tomcat without modifying application - This another answer also could be useful. It's about a file based realm which also requires some Tomcat server configuration but without any coding.

Share:
10,431
Mr. Lance E Sloan
Author by

Mr. Lance E Sloan

˙ɯǝɥʇ ʇnoqɐ ʎɹǝʇsʎɯ ɟo ɹᴉɐ uɐ dǝǝʞ oʇ sɹǝɟǝɹd ɹǝsn sᴉɥʇ 'ʎlʇuǝɹɐdd∀ I like the way Stack Overflow formats the <kbd> element: shift + ⌘ + Q

Updated on June 04, 2022

Comments

  • Mr. Lance E Sloan
    Mr. Lance E Sloan almost 2 years

    Possible Duplicate:
    Getting a value from HttpServletRequest.getRemoteUser() in Tomcat without modifying application

    Short version: How can I configure Tomcat to use a specific name (say, "johndoe") as the remote user name?

    The details: I'm working on a Java web application that will be deployed to production using Tomcat. The production server is configured to prompt the user for authentication before they ever reach this application, so the app will only need to use something like the javax.servlet.http.HttpServletRequest method getRemoteUser() to get the user's name. This works very well, in fact. It's already been tested.

    The problem is that it's not practical (for various reasons) to install this authentication process on my development machine. I'd also like to avoid adding special-purpose code in the application just to accommodate my local testing. I thought that it would be best if I could just force the username I want to test with into Tomcat's configuration. Then the getRemoteUser() would return "johndoe" every time. Of course, in production, that username wouldn't be forced into the environment, the actual authentication process would run instead.

    I can't figure out how to configure that username into Tomcat, though. Any suggestions?

  • Cratylus
    Cratylus over 12 years
    Sorry, what is your point exactly?
  • Mr. Lance E Sloan
    Mr. Lance E Sloan over 12 years
    Thanks for the response. I'll give these a try.
  • Mr. Lance E Sloan
    Mr. Lance E Sloan over 12 years
    This worked out great. I have a question, though. Do you think it's possible to pass parameters from server.xml to the RemoteUserValve? For example, I imagine something like: <Valve className="remoteuservalve.RemoteUserValve"><Parameter key="name" value="myUser"></Valve>
  • palacsint
    palacsint over 12 years
    Yes, it's possible. You just need a setter method. Check the source of any existing Valve, for example AccessLogVale. You can find a sample usage in the default server.xml.
  • Mr. Lance E Sloan
    Mr. Lance E Sloan over 12 years
    Thanks for the great pointers. I've implemented the valve for my development environment so that it will use the "user.name" system property for the user name it will return unless a "name" attribute is specified in the server.xml. Works perfect.