Search code examples
javatomcatbasic-authentication

How do I set the remote user in Tomcat?


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?


Solution

  • 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.