views:

44

answers:

2

I read most of the documentation, I only see the use of @RolesAllowed or @DeclareRoles, how can I add user or delete user. I have a table of users with username and password in my database, how can I make my web app to authenticate those user? How can I map these user (principal) to a particular roles. Samples code would be greatly appreciated. Thank you very much

+1  A: 

JavaEE doesn't define the management of users and roles, only how the application interacts with them.

It is up to the specific server implementations to define that functionality as they see fit.

skaffman
+3  A: 

A JAAS Login module is required to authenticate the user, establish the principals, that can enable the mapping of users/principals existing in the database to roles defined in the source code.

Assuming that you are using Glassfish v3 for JEE6, you need to create and configure a JDBC realm in Glassfish for this purpose. Be forewarned that the realm configuration might not have a one-to-one mapping with the user table in your database, in which case you either need to modify the table definition, or extend the login module to create your own scheme.

Despite setting up the database realm, you would still need to map the JEE roles defined in your source code, to the actual roles in the realm. That is accomplished using the application server specific deployment descriptors.

Vineet Reynolds
I know it would be too much to ask for samples code. But do you know any tutorial for this kind of things?
Harry Pham
Well you're in luck. Have a look at the blog entry titled "Mort learns JDBC Realm authentication": http://blogs.sun.com/foo/entry/mort_learns_jdbc_realm_authenticationIt shows how to configure a JDBC realm based of tables created by the author, and then shows how to use the users and roles in a very simple web application. Notice the mapping between the JEE role and the JDBC role in sun-web.xml
Vineet Reynolds
Great. Reading it now. I appreciated your help very much. Will let u know if I have any question. Once again. Thanks!
Harry Pham
I got it working. Thank you very much :D
Harry Pham
Glad to be of help :-).
Vineet Reynolds