• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Tomcat programmed authentication

How can I programmatically set a user in the Tomcat container?  My scenario is that I want to send a 1024-bit key to a user.  That user will give that key to a specific servlet.  That servlet will take that key and lookup user information.   I want to then let Tomcat know who the user is so that request.getRemoteUser() will work on subsequent page loads.

1 Solution
There's no way to programmatically set the user (e.g. request.setRemoteUser), but if you need to, you can just use a session variable to let yourself know that this user is "ok."
For a servlet container, with Tomcat 3.2.1  It
provides the ability to create custom "request interceptors" which allow you
to substitute your own security model into the servlet framework.   Tomcat
comes with two pre-built request interceptors already:

SimpleRealm -- which uses a tomcat-users.xml file found in
<tomcat-root>/conf to statically load users, groups, and roles upon Tomcat

JDBCRealm -- which works in a similar fashion but uses a JDBC data source as
a back-end.
mjschehlAuthor Commented:

How would I set the Remote User in a filter when I use custom "request interceptor"?  

I actually already programmed my own realm, so that would be great if I can just update it to set the remote user programmatically.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

mjschehlAuthor Commented:


I looked at that pdf.  I couldn't find anything that applies to my question, though.  What page or section does it say how to programmatically login a user into Tomcat?

mjschehlAuthor Commented:

Well, I found out how to do it by asking on the Tomcat User mailing list.  The answer is to use a Tomcat Valve.

No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:

    PAQ - refund

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer
PAQed, with points refunded (500)

Community Support Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now