File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Declarative security : mapping user to security roles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Declarative security : mapping user to security roles" Watch "Declarative security : mapping user to security roles" New topic
Author

Declarative security : mapping user to security roles

Pushker Chaubey
Ranch Hand

Joined: Dec 06, 2006
Posts: 53
I am using tomcat 5.0 for hosting my application. I want to use declarative security for my application. I want my users to be stored in database. I can not store users in tomcat-users.xml as I want to be able to register new users from a screen. In database I will have table which will map these users to a set of roles (which have same name as the declared roles).
But, how can I associate users to the declared roles defined in web.xml)?

I suppose container will only recognize roles defined in web.xml. How the "user to Db roles mapping " will get transformed to container's "user to security role mapping" so that when I invoke request.IsUserInRole("RoleName") it performs the required check on associated role.


Thanks in advance!
[ November 25, 2008: Message edited by: Pushker Chaubey ]

Regards,<br />Pushker<br /> <br />SCBCD 5.0 90%<br />SCWCD 5.0 89%<br />SCJP 5.0 90%
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Tomcat implements container managed security by connecting to a realm and using the data stored there to authenticate users. In this case your database table will contain the realm definition (user names, passwords, and roles) that you defined in tomcat-users.xml

You will probably need two tables. One that will have the logon ID and passwords, and another one to have the logon ID and roles for that ID.


Then you just configure tomcat to use the realm. I am sure if you search the web you can find more detailed information.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Pushker Chaubey
Ranch Hand

Joined: Dec 06, 2006
Posts: 53
Thanks Bosun!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Declarative security : mapping user to security roles