I have been busy setting up authentication, a JDBC realm in particular, on GlassFish 3.1. I have been operating under the assumption that:
- The “User” table contains the login name (“email_address”) and the password (“password”)
- The “Group” table contains a list of group names (“name”)
- A “User_Group” table matches users and groups up.
Nowhere was I able to configure the “User_Group” table however so I was left wondering how the server would ever be able to match users up to groups. Needless to say it did not work. Closer inspection however suggests that:
- The “User” table contains the login name (“email_address”) and the password (“password”)
- The “Group” table contains the login name (“email_address”) as primary key, and a comma-separated list of group names (“Administrator,User”) in a single column (“groups”)
Is this correct and, if so, why go through the trouble of creating a separate “Group” table? Since it seems you can have only one grouplist per login (“email_address”) wouldn’t it be just as easy as to simply add a column called “groups” to the “User” table and discard the “Group” table altogether?
Thanks!
I’m not sure what material you’ve followed to configure the JDBC realm, but it appear to be incomplete or incorrect. Following is a description of the configuration I’ve used to configure the JDBC realm.
The database structure (as DDL statements):
The USERS table
The GROUPS table
The USERS_GROUPS join table
The Glassfish JDBCRealm configuration snippet from
domain.xml:Note, the
group-name-columnattribute having a value ofGROUPID, which maps to theGROUPIDcolumn of the join tableUSERS_GROUPSand not the group tableGROUPS. This is because the JDBCRealm issues the following SQL statements (if you decompile thecom.sun.enterprise.security.auth.realm.jdbc.JDBCRealmclass):The password query, with the user Id being the parameter that is passed from the DigestLoginModule:
The group query, with the user Id being passed as the parameter:
When you consider the second query’s structure, it is quite obvious that the group Table must either contain the user Id mapped to a group Id (which leads to duplication of group data for users mapped to multiple groups), or that the group Table must be the join table that maps users to groups.