Skip to Content.
Sympa Menu

grouper-dev - Re: [grouper-dev] Hooks and Copy Group

Subject: Grouper Developers Forum

List archive

Re: [grouper-dev] Hooks and Copy Group


Chronological Thread 
  • From: John Gasper <>
  • To: "" <>
  • Subject: Re: [grouper-dev] Hooks and Copy Group
  • Date: Mon, 11 May 2015 17:22:25 -0700

Sorry, got hasty on the send… 

Is there an easy way to confirm that this is a Grouper API bug and not my code?

My code is pretty simplistic:

@Override
public void groupPreInsert(final HooksContext hooksContext, final HooksGroupBean preInsertBean) {
checkForDups(preInsertBean.getGroup().getName());
}

/*
* @see edu.internet2.middleware.grouper.hooks.GroupHooks#groupPreUpdate(HooksContext, HooksGroupBean)
*/
@Override
public void groupPreUpdate(HooksContext hooksContext, HooksGroupBean preUpdateBean) {
checkForDups(preUpdateBean.getGroup().getName());
}

/**
* Will invoke a check to see if the requested name already exists
* @param groupName fully qualified groupName
*/
public void checkForDups(final String groupName) {
final String shortName = removePathFromGroupName(groupName);
logger.info("Trying to add {} ({}) as a new group, checking to see if the desired name exists anywhere else", groupName, shortName);

//Do ldap first since sAMAccountName should be indexed, and in Grouper we have to do a full table scan with LIKE
//checkLdapForDuplicates(groupName, shortName);
checkGrouperForDuplicates(groupName, shortName);
}

/**
* Checks the Grouper system for duplicates
* @param longName the fully qualified (with path) group name
* @param shortName the group name (without path)
*/
protected void checkGrouperForDuplicates(final String longName, final String shortName) {
final Set<Group> list = GrouperDAOFactory.getFactory().getGroup().findAllByApproximateName(shortName);
for (Group group : list) {
final String groupName = group.getName();

if (!longName.equalsIgnoreCase(groupName) && shortName.equalsIgnoreCase(removePathFromGroupName(group.getName()))) {
logger.info("Found duplicate ({}) in grouper when adding '{}' ({})", new Object[] {groupName, shortName, longName});
throw new HookVeto("hook.veto.group.name.grouper.duplicate", String.format("The desired group name (%s) already exists in Grouper as %s.", longName, group.getName()));
} else {
//This could happen when updating itself
logger.debug("Found ({}) in Grouper when adding/updating {} ({}); allowing it", new Object[]{groupName, shortName, longName});
}
}
}
/**
 * Removes path from a fully qualified group name
* @param groupName a fully qualified group name
* @return the last node
*/
protected String removePathFromGroupName(final String groupName) {
final String[] namePath = groupName.split(":");
return namePath[namePath.length-1];
}
Thanks,
John

-- 
John Gasper
IAM Consultant
Unicon, Inc.
PGP/GPG Key: 0xbafee3ef


From: John Gasper <>
Date: Monday, May 11, 2015 at 5:15 PM
To: "" <>
Subject: [grouper-dev] Hooks and Copy Group

I’m seeing interesting behavior related to the Grouper Hooks and Copy Group function. I’ve written a hook that prevents a duplicate Group Id from being re-used anywhere else in the system. Works great on create and insert. However, when it is called using Copy Group (in the UI ), it has some interesting behavior… It seems that if the ID matches something (triggering the hook), when I change the group Id to something unique the old id still gets passed to the hook. 

-- 
John Gasper
IAM Consultant
Unicon, Inc.
PGP/GPG Key: 0xbafee3ef




Archive powered by MHonArc 2.6.16.

Top of Page