Skip to Content.
Sympa Menu

grouper-users - [grouper-users] RE: need help fo hooks

Subject: Grouper Users - Open Discussion List

List archive

[grouper-users] RE: need help fo hooks


Chronological Thread 
  • From: "Hyzer, Chris" <>
  • To: Celine Dusset <>, "" <>
  • Subject: [grouper-users] RE: need help fo hooks
  • Date: Thu, 23 Mar 2017 14:36:06 +0000
  • Accept-language: en-US
  • Authentication-results: unice.fr; dkim=none (message not signed) header.d=none;unice.fr; dmarc=none action=none header.from=isc.upenn.edu;
  • Ironport-phdr: 9a23:MahEDh3A20swVFUasmDT+DRfVm0co7zxezQtwd8ZseMSKvad9pjvdHbS+e9qxAeQG96KtrQb0KGI7ujJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fdbghMhDexe7F/IRu5oQjQtsQdnJdvJLs2xhbVuHVDZv5YxXlvJVKdnhb84tm/8Zt++ClOuPwv6tBNX7zic6s3UbJXAjImM3so5MLwrhnMURGP5noHXWoIlBdDHhXI4wv7Xpf1tSv6q/Z91SyHNsD4Ubw4RTKv5LpwRRT2lCkIKSI28GDPisxxkq1bpg6hpwdiyILQeY2ZKeZycr/Ycd4cWGFPXNteVzZZD428cYUBEvYBM+hboYnzpVQOrAexCga3Cez11jNEmmX70bEm3+g8FwzNwQwuH8gJsHTRtNj5OqUcUOC0zabW1zXPd+5d1Cn96IjScxAhuv+AVq93fMrU1UYvFwPEj1SOpoz/JD6V1/8NvHSB4+p9TeKglWgnqwdrrjex28gsl5DEi4QIwV7H7SV02Jg5KcC5RUJhb9OoDoFcuzyZOodrWM8uXmJltSkixrEbt5O3YDIGxZA6yxLFdfCLboyF7gj+WOuTIDp1gm9udqiliBao60egz/XxVsmq31ZOqSpIisHCu2wK2RDP98SLU+Zw8UW/1TqW0ADc8f9LLVozlarGN54u2bkwlocVsUveBCP2gF/2jKiKdko65ueo9+XnYrLgppOGMI90lx3+MqApmsy4AuQ0KBQBX2+e+eik1b3j+1P2QKlSg/Eoj6XUsYrWKMoFqqKjHgNY0Zsv5wyiAzql39kUhXwHI0hEeBKDgYjpIVbOIPXgAPe6n1uskDdqxvHYMb37GZjNL2PDn6v7cbZg805T1gwzzdZF651KF74BPer/WlXtu9zAEh85Lwu0zv7oCNVn0YMeRHqPDbGDMK/LrF+I/fwgI/OXZIIOvDb9KuMl5+L1jXMng1MdfK+p3YcJZ3CiGPRpPVmZbWT2jtgfDGgKo1l2cOu/o1CGUDheL1qvRLkx+nlvI4+iDIHOAKyQu4es4A+mGJxdayZIEAbIWT3nbYKZQ/oWLT+JL9V6uj0CSbW7TYI9j1ejuBKwg+5oNO3J4iAC8I/42cJuz+zViRwo8zFoVYKQ33zbHE9umWZdDR8nzq1l5QRWyk2CyuIw1/lTFc1B6ulhUxwxc4PEwup8Td3+R1SSLZ+yVF+6T4D+UnkKRdUrzopLOh4lFg==
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:99

Please explain with as much detail as possible exactly what you want this hook to do.

 

Thanks

Chris

 

From: [mailto:] On Behalf Of Celine Dusset
Sent: Thursday, March 23, 2017 10:24 AM
To:
Subject: [grouper-users] need help fo hooks

 

Hello,

 

I'm on grouper 2.2.2. I want to write a hook that put an uuid on created groups. The value of the uuid is stored in a table in grouper.

 

I'm not good on java coding, I've written the code inspired by "Getting started with hooks2" and the "LDAPProvisioningHook" code.

 

I'm getting errors of course and it is not compiled. (I compile using ant from the api binary).

 

Thank you everyone for any help.

 

 

**************

Céline Dusset

Université de Nice Sophia-Antipolis

DSI  - Service Transverse

Pôle Référentiels, outils de pilotage et de fiabilisation

 

**************

 

Part of the errors (the first):

"

[javac] /opt/grouperInstaller/grouper.api-2.2.2/src/grouper/edu/internet2/middleware/grouper/hooks/examples/MysupannRefIdGroupHook.java:62: error: cannot find symbol
    [javac]                             if (groupType == null) {
    [javac]                                 ^
    [javac]   symbol: variable groupType

"

 

the code is here :

 

package edu.internet2.middleware.grouper.hooks.examples;

import edu.internet2.middleware.grouper.Group;
import edu.internet2.middleware.grouper.GroupType;
import edu.internet2.middleware.grouper.GroupTypeFinder;
import edu.internet2.middleware.grouper.GrouperSession;
import edu.internet2.middleware.grouper.SubjectFinder;
import edu.internet2.middleware.grouper.cfg.GrouperConfig;
import edu.internet2.middleware.grouper.exception.GrouperSessionException;
import edu.internet2.middleware.grouper.hooks.GroupHooks;
import edu.internet2.middleware.grouper.hooks.beans.HooksContext;
import edu.internet2.middleware.grouper.hooks.beans.HooksGroupBean;
import edu.internet2.middleware.grouper.misc.GrouperSessionHandler;
import edu.internet2.middleware.grouper.privs.AttributeDefPrivilege;

/**
 * add a type after a group insert
 */
public class MysupannRefIdGroupHook extends GroupHooks {
   /**
   *
   * @see edu.internet2.middleware.grouper.hooks.GroupHooks#groupPostInsert(edu.internet2.middleware.grouper.hooks.beans.HooksContext, edu.internet2.middleware.grouper.hooks.beans.HooksGroupBean)
   */
//  @SuppressWarnings("unchecked")
 
@SuppressWarnings("deprecation")
  @Override
  public void groupPostInsert(HooksContext hooksContext, HooksGroupBean postInsertBean) {
      
          final Group group = postInsertBean.getGroup();
          String name = group.getName();
          
          
          boolean includeMatches = false;
          int count = 0;
          
          // definition des branches ou le hook doit fonctionner
          while (true) {
          String property = "MysupannRefIdGroupHook.include.regex." + count;
          String regex = GrouperConfig.retrieveConfig().propertyValueString(property);
          if (regex == null) {
            break;
          }

          if (name.matches(regex)) {
            includeMatches = true;
            break;
          }

          count++;
    }
          
if (includeMatches) {
        GrouperSession.callbackGrouperSession(GrouperSession.staticGrouperSession().internal_getRootSession(), new GrouperSessionHandler() {

        @Override
        public Object callback(GrouperSession grouperSession)
            throws GrouperSessionException {
                if (groupType == null) {
                    groupType = GroupType.createType(grouperSession, "uns_uuid");
                    groupType.addAttribute(grouperSession, "supannRefId");
                    groupType.getAttributeDefName().getAttributeDef().getPrivilegeDelegate().grantPriv(SubjectFinder.findAllSubject(), AttributeDefPrivilege.ATTR_READ, false);
                    groupType.getAttributeDefName().getAttributeDef().getPrivilegeDelegate().grantPriv(SubjectFinder.findAllSubject(), AttributeDefPrivilege.ATTR_UPDATE, false);
                    groupType.internal_getAttributeDefForAttributes().getPrivilegeDelegate().grantPriv(SubjectFinder.findAllSubject(), AttributeDefPrivilege.ATTR_READ, false);
                    groupType.internal_getAttributeDefForAttributes().getPrivilegeDelegate().grantPriv(SubjectFinder.findAllSubject(), AttributeDefPrivilege.ATTR_UPDATE, false);
                }

          group.addType(groupType);
 
          //its possible this is already there (e.g. from import or something)
          //select by list since if not by list it must be there
        List<String> gidList = new ArrayList<String>();          
        gidList = HibernateSession.bySqlStatic().listSelect(String.class,"select uns_structures_v.uuid from grouper_groups_v grp_v, uns_structures_v where uns_structures_v.path_name = substr(grp_v.parent_stem_name,5) and grouper_groups_v.name = ?", HibUtils.listObject(group.getName()));
 
          if (GrouperUtil.length(gidList) == 0) {
            throw new RuntimeException("Pb avec l'uuid de  " + name);
          }
 
          String gid = gidList.get(0);
          if (StringUtils.isBlank(gid)) {
            throw new RuntimeException("UUID blanc pour " + name);
          }
          
          group.setAttribute("supannRefId", gid);
 
          return null;
        }
      });
 
    }
  }




Archive powered by MHonArc 2.6.19.

Top of Page