Child pages
  • Grouper rules use case - Veto if too many members
Skip to end of metadata
Go to start of metadata

Grouper rules

This is available in Grouper 2.5.23+

If a group has a membership limit, then veto additions to the group.  You might want to configure a subject source so that group members do not count (since they wont be provisioned anyways.  You can link this rule to a different group.  e.g. if a group has two groups as members, then add this rule to all three groups, and point the count to happen at the parent group, and you will not be able to add members to child groups because the parent group is full.

Java example

    GrouperSession grouperSession = GrouperSession.startRootSession();
    Group maxGroup = new GroupSave(grouperSession).assignName("stem:maxGroup").assignCreateParentStemsIfNotExist(true).save();
    Group memberGroup = new GroupSave(grouperSession).assignName("stem:memberGroup").assignCreateParentStemsIfNotExist(true).save();

    //add rule on a group that checks a membership count and vetos if at limit already
    AttributeAssign attributeAssign = memberGroup
    AttributeValueDelegate attributeValueDelegate = attributeAssign.getAttributeValueDelegate();
        RuleUtils.ruleActAsSubjectSourceIdName(), "g:isa");
        RuleUtils.ruleActAsSubjectIdName(), "GrouperSystem");

    //subject use means membership add, privilege assign, permission assign, etc.


    // if you are not checking the group with the rule on it, identify that group to check here
        RuleUtils.ruleIfOwnerNameName(), maxGroup.getName());

        RuleUtils.ruleIfConditionEnumArg0Name(), "1");
    // if checking subject sources, put them here comma separated (the sourceIds)
        RuleUtils.ruleIfConditionEnumArg1Name(), "jdbc");

    //key which would be used in UI messages file if applicable
        RuleUtils.ruleThenEnumArg0Name(), "");
    //error message (if key in UI messages file not there)
        RuleUtils.ruleThenEnumArg1Name(), "Group has too many members");
    //should be valid
    String isValidString = attributeValueDelegate.retrieveValueString(
    if (!StringUtils.equals("T", isValidString)) {
      throw new RuntimeException(isValidString);

GSH shorthand method

// get a Subject object for the shorthand method
actAsSubject = findSubject("grouperSystem") ; // or any subjectIdentifier you want to use

// get a group object for the shorthand method ( can also be used for the memberGroup object if needed )
maxGroup = GroupFinder.findByName("groupname", true)

// check one group for member count
RuleApi.vetoMembershipIfTooManyMembers(actAsSubject, maxGroup, null, 1, null, "", "Group has too many members");

// check another group for member count 
RuleApi.vetoMembershipIfTooManyMembers(actAsSubject, memberGroup, maxGroup, 1, "jdbc", "", "Group has too many members");

  • No labels