So I think the issue is that the group copy method in the API doesn’t handle changing the group id/extension. So instead the UI issues the copy and then it renames the group afterwards. But the hook fires first. So the solution may be for the API to
handle the new group id/extension directly. If that sounds right, I’ll create a patch.
Thanks!
- Shilen
From: John Gasper <>
Date: Thursday, May 14, 2015 at 7:16 PM
To: "" <>
Subject: Re: [grouper-dev] Hooks and Copy Group
Following with perhaps a simpler question: What does the Group object provided by the HooksGroupBean represent. The new state, the old state, undetermined? Creating and Updating existing groups appears to work as expected. The Copy and Move UI functions
don’t seem to return objects with future/requested state.
Thanks for any insight.
--
John Gasper
IAM Consultant
Unicon, Inc.
PGP/GPG Key: 0xbafee3ef
From: John Gasper <>
Date: Monday, May 11, 2015 at 5:22 PM
To: "" <>
Subject: Re: [grouper-dev] Hooks and Copy Group
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
|