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: Celine Dusset <>
  • To: "Hyzer, Chris" <>, "" <>
  • Subject: [grouper-users] RE: need help fo hooks
  • Date: Fri, 24 Mar 2017 13:59:22 +0000
  • Accept-language: fr-FR, en-US
  • Authentication-results: isc.upenn.edu; dkim=none (message not signed) header.d=none;isc.upenn.edu; dmarc=none action=none header.from=unice.fr;
  • Ironport-phdr: 9a23:UjgrNRSTD3eaoz+AErJsUIYGZtpsv+yvbD5Q0YIujvd0So/mwa6zZh2N2/xhgRfzUJnB7Loc0qyN4v2mBjFLvMvJmUtBWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYdFRrlKAV6OPn+FJLMgMSrzeCy/IDYbxlViDanb75/KBW7oR/Tu8QWjodvKqY8wQbVr3VVfOhb2XlmLk+JkRbm4cew8p9j8yBOtP8k6sVNT6b0cbkmQLJBFDgpPHw768PttRnYUAuA/WAcXXkMkhpJGAfK8hf3VYrsvyTgt+p93C6aPdDqTb0xRD+v4btnRAPuhSwaMTMy7WPZhdFqjK9DoByvuQFxw5Labo+WOvpxfKLdcs8VSmdaRMZdSzBND5mgY4cTEuYMO/tToYnnp1sJqBuzHRehC/3ryj9JgH/5w7Ax3eo8EQHdxwwvAc4Ou2nTodjrKqgSVeG1zK/WwjnZYf1Z1yrz5pXHfB4/uvyMQLRwccvNxkYxDQ/FgE+QpJXjMjiI1eoNq3CW4/R6Wu6zlmIqrhx9riWyysophInEiZ4ZxkzB+CV33ok5Oce3RUt+bNOlHpZcqjmWO5V2T884Xm1luSg3xqcItJKhcyUHzoksyQTFZPydaYeI5wruVOaPLjd8g3JoYL2xiBiu/0S8xODwT8e63UtKoyZcldnDrW4C2wbU6siaVvty5UCh2SuJ1w/O8O1EOVo0la3HK5E/3rEwipsTsUPFHiPsn0X2kbOWdkEj+uiv6OTreKnpppiZN4NsiwH+NLohmtCnDOgmKAcCQ3WX9OGh2LH+4EH0RbtKg/IqnqXFtZ3aK9oUqrKjDAJQ14su6hiyAyq+3NQdh3YHLVZFeBydj4juPlHDOO71Aum7g1Stljdk2erKMLPvDZvQM3bNn6nvcK1g605ayQo80c5Q64haCrEbOP7zQFP+tMTEDh8lNAy52+nnCM961oMDQWKAHLWZPLrPsV+T+O0vOfKMaZQRuDb8MPgl++XugWEjlV8ce6mpwYUYaGq+Hvt4P0WVf2DgjckcHmcX7UICS7mgqEyQXCQXL12yRaMnrHlvDYmmHJXOXKism7fHwT+2GJsQa2xbXBTEW3jycJicVu1JdTmfONRJkzoYWKKnRpN7kxyiqUWyn7V9KffM9zddqInuzsNd5uvPmAs0+CAuScmRzjfeYXtzmzYjSjs32q03jVFm0VqfmfxTjvhZE9EVy85yaSoGHYPazud3Td7oDFGSNuyVQUqrF431SQo6Scg8locD
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:99

I have institutional groups hierarchy created by loader.


 stem1:astem1:agroup1

 stem2:astem2:agroup2


Each stem correspond to an institutional structure which is identified by an uuid in ower structure referential. Path-name hierarchy and uuids are stored in a tables/views in the grouper db for the loader. ex.: view uns_org_v



What i want to do is to store the uuid value in an attribute for each group created.

I have to publish this attribute in ower ldap with psp. If a stem is renamed or is moving in the hierarchy, a new stem is created but the uuid is the same.


Hope it is quite clear and detailed.


Céline


De : Hyzer, Chris <>
Envoyé : jeudi 23 mars 2017 15:36
À : Celine Dusset;
Objet : RE: need help fo hooks
 

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