Skip to Content.
Sympa Menu

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

Subject: Grouper Users - Open Discussion List

List archive

[grouper-users] need help fo hooks


Chronological Thread 
  • From: Celine Dusset <>
  • To: "" <>
  • Subject: [grouper-users] need help fo hooks
  • Date: Thu, 23 Mar 2017 14:23:38 +0000
  • Accept-language: fr-FR, en-US
  • Authentication-results: internet2.edu; dkim=none (message not signed) header.d=none;internet2.edu; dmarc=none action=none header.from=unice.fr;
  • Ironport-phdr: 9a23:Jm9ZsBwtknuaHDLXCy+O+j09IxM/srCxBDY+r6Qd2+IRIJqq85mqBkHD//Il1AaPBtSGra0fwLSM+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZPebgFIiTanY75/Ihq6oATPusILnYZsN6E9xwfTrHBVYepW32RoJVySnxb4+Mi9+YNo/jpTtfw86cNOSL32cKskQ7NWCjQmKH0169bwtRbfVwuP52ATXXsQnxFVHgXK9hD6XpP2sivnqupw3TSRMMPqQbwoXzmp8qFmQwLqhigaLT406GHZhNJtgqJHrhyvpB1/zJLbb4yOLvVyYr/RcMkGSWZdQ8pcUTFKDIOmb4sICuoMJfhVoJf5p1sPqxuxGxSnCu3yyj9TnX/5w7E62PkmHAzYwgMgG9MOsHLKo9nvOqkdX/27wrTHwzvddP5WxDH96InUfR8/u/2MU6hwfNPXxEIyFA3Flk2dpZL/MD+Jy+gAtnWX4/d9We+qhW4qpB19riSqy8cilIbFmoMYx1XB+Ch4zos5OMW0RFB7bNK+DZddtTyWO5F1T84mWW1ltyA3waAct5GhZigF0pEnygbfa/OZd4iI5QruWumfLjlkmH5pZquziBm9/0S90+H8UdK730hQoipCj9nMqmsC1xvO6siBV/Rx5F+h2SyI1wDP9O5LPVw0lavcK54n2LIwkYcTsVjHHi/xn0X2j7WaeVkj+uit8+jnY7PmqYGAN4JslA3xKLgiltG6DOglLwQCQm2W+eqz2bH/4UH0RbtKgeMqnqTYtZ3XIMUWq6CkDwNN14Ys8Re/DzOo0NQCmnkHKUpIdQyZgIjtOlHOJu73Ae2xjVuijTll2v/IMKP6D5XQKHjDkavucqhn505S0go/1cpf6I5MCrEdPPLzXVf8tNPCDh8+Lgy02/joCM9k2oMDQmKAHLWZMLjJvF+M5+IvOPWMZJQLtDrnKvgl4eLugmEjmV8bY6apwYUbZGqmEft7PkXKKUbr150OC2AXpgckCfHxhUeZeT9Ve3uoWa8gvHc2BJ/sRdPMXIewmLGbmTqgE4dNTmFAFl2WF3r0LcOJV+paOwyIJco0uTEAVL6sA6M8zgqjqEeu4LdjL+zZvAEljqnO6PBo4ezYmFc872onXIymz2iRQjQszSszTDgs0fUnrA==
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:99

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