[Opensource] primary group as new User field?
Peter A. Pilgrim
peterp at xenonsoft.demon.co.uk
Mon Jan 20 17:07:39 PST 2003
larry hamel wrote:
> 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
>
+1
This is very UNIX like. When you type at the command line "id" and
"groups"
peterp at orchard [210] > id
uid=500(peterp) gid=100(users)
groups=100(users),14(uucp),16(dialout),17(audio),33(video),102(cdwriter),103(xcdwrite)
peterp at orchard [211] > groups
users uucp dialout audio video cdwriter xcdwrite
Here my UNIX primary group is "users(100)"
--
Peter Pilgrim
ServerSide Java Specialist / Indepedent Contractor
Expresso committer ---------------------------------------------+
| `` http://www.xenonsoft.demon.co.uk/no-it-striker.html '' |
+-------------------------------------------------------------+
More information about the Opensource
mailing list