Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass remoteuser in Tomcat 4 from command prompt

 
Sundar Var
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic