wood burning stoves 2.0*
The moose likes Tomcat and the fly likes How to pass remoteuser in Tomcat 4 from command prompt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to pass remoteuser in Tomcat 4 from command prompt" Watch "How to pass remoteuser in Tomcat 4 from command prompt" New topic
Author

How to pass remoteuser in Tomcat 4 from command prompt

Sundar Var
Greenhorn

Joined: Jun 23, 2005
Posts: 3
Hi,
With Tomcat3 I generally start my tomcat passing the remoteuser name in the command prompt as tomcat.sh start [username]. In our servlets we take the username with request.getRemoteUser().

I have upgraded to Tomcat4 and when I give startup.sh start [username] im getting the following error
usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -debug ] [ -nonaming ] { start | stop }

Could you please guide me how to pass the username while starting Tomcat 4 so that my servlet will return me the remote username when I use request.getRemoteUser().

Your help is appreciated.

Regards,
Sundar.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
I am totally mystified by this question.
The HttpServletRequest method getRemoteUser is supposed to return the login name of the user making the request if authentication is turned on, or null.
I can't see that this has any connection with startup parameters handed to Tomcat.
Bill
Sundar Var
Greenhorn

Joined: Jun 23, 2005
Posts: 3
Bill,
Could you please tell me how to turn the authentication to ON for a specific webapplication in Tomcat 4 so that i will get the remoteuser properly in my servlet?

FYI, Tomcat3 startup class Tomcat.java has the following piece of code
ContextManager contextmanager;
if(remoteUser != null)
contextmanager = new ContextManager(remoteUser);
else
contextmanager = new ContextManager();
remoteUser in ContextManager() constructor, is the value which will be passed in the command prompt within [] as tomcat.sh start [username]. So Tomcat3 starts with this username and any servlet which calls reqest.getRemoteUserName() will get the name of the user which was used to start the tomcat.
If you have the source code of Tomcat.java kindly have a look at it.

Regards,
Sundar.
[ June 24, 2005: Message edited by: Sundar Var ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
There is nothing like that Tomcat 3 code in Tomcat 4. Not surprising - there was a major redesign between the two.
If you want to force a username in Tomcat 4 I think you will have to use a filter and a custom class derived from HttpServletRequestWrapper. This custom class would provide a method of getRemoteUser but pass all other method calls through to the wrapped request.
If you want to actually force users to provide a username and password, that would involve configuring security-constraint entries in web.xml.
Bill
Sundar Var
Greenhorn

Joined: Jun 23, 2005
Posts: 3
Bill,
I have even changed the web.xml of my webapp, to have the following entry
<login-config>
<auth-method>BASIC</auth-method>
</login-config>

But its not prompting me for the userid dialog?
To add once again, my requirement is to get the username whoever is accessing the application via the servlets request.getRemoteUser(). I dont mind if the user enters the password or not. How can I do this?

Regards,
Sundar.
[ June 24, 2005: Message edited by: Sundar Var ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
As I recall, your web.xml also has to have a <security-constraint> section - the tomcat-docs that get installed with a typical Tomcat installation should have a discussion.
The ultimate reference for web.xml is the servlet API which you should be able to download from Sun here.
Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to pass remoteuser in Tomcat 4 from command prompt
 
Similar Threads
Accesing request.getRemoteUser() using EL expressions
System.out.println messages
Apache and orion communication
clear screen applet
System.out.println - where?