[Opensource] primary group as new User field?
larry hamel
expresso at codeguild.com
Wed Jan 15 20:32:17 PST 2003
Here's a proposal to add a field to USERTABLE for the "primary group" for a given user:
I have an application that would benefit from a "primary/default" group, like that available in a unix environment.
For example, we'd like to support groups of people (classes of students) who have identical settings for file roots, etc. It would be convenient for us to create, within our application only, some GroupPreferences for such settings. But a user may belong to many groups, so we need an indication of primary/default group.
To accommodate a similar need last summer, I added a static method User.getPrimaryGroup() to Expresso, used in RowPermissions/RowSecuredDBObject to set the default group permissions. However, the implementation is dumb right now:
/**
* @todo provide means to
* actively indicate primary group for a user.
* @returns primary group or null in none found
*/
public static String getPrimaryGroup(User user) throws DBException {
if (user == null) throw new DBException("unexpected null user");
String result = null;
/**
* @todo fix this lame manner of determining primary group
*/
List grps = user.getGroupsList();
if (grps.size() > 0) {
result = (String) grps.get(0);
}
return result;
}
Instead, I'm proposing the addition of a field in DefaultUserInfo/USERTABLE like
addField("PrimaryGroup", "char", 10, true, "primaryGroup");
which would have a foreign key in UserGroup/USERROLE
The implementation for getPrimaryGroup() would have to be implemented by all UserInfo classes. For situations where UserInfo implementers didn't care/didn't know, a null is fine, as explained in javadoc of UserInfo:
/**
* @return name of the primary group of this user; null if no group is primary
*/
public UserGroup getPrimaryGroup()
throws DBException {
return null;
}
In the DefaultUserInfo case, the answer is a lookup based on the new field in USERROLE:
/**
* the primary group of this user is appropriate for unix-like purposes,
* such as setting the group for a file permission
* @return name of the primary group of this user; null if no group is primary
*
*/
public UserGroup getPrimaryGroup()
throws DBException {
UserGroup primary = null;
String grpName = this.getField("PrimaryGroup");
if ( grpName == null || grpName.length() == 0 ) {
// use first group if none marked as primary
Vector groups = this.getGroups();
primary = (UserGroup) groups.get(0);
} else {
primary = new UserGroup();
primary.setDBName(getDBName());
primary.setField(UserGroup.GROUP_NAME_FIELD, grpName);
if ( !primary.find() ) {
// unexpected
throw new DBException("cannot locate primary group: "
+ grpName + " which is specified for user: "
+ this.getLoginName());
}
}
return primary;
}
Since getPrimaryGroup() already exists, I think this field addition and implementation are appropriate for the Expresso framework.
Comments/corrections? This is intended to go into 5.1 (cvs head, but not 5.0.x releases) unless you spot serious flaws.
larry
More information about the Opensource
mailing list