Skip to Content.
Sympa Menu

grouper-dev - RE: [grouper-dev] Locating Stems and Groups with an Attribute Assigned

Subject: Grouper Developers Forum

List archive

RE: [grouper-dev] Locating Stems and Groups with an Attribute Assigned


Chronological Thread 
  • From: Chris Hyzer <>
  • To: Chris Hyzer <>, David Langenberg <>
  • Cc: John Gasper <>, "" <>
  • Subject: RE: [grouper-dev] Locating Stems and Groups with an Attribute Assigned
  • Date: Fri, 19 Sep 2014 16:27:31 +0000
  • Accept-language: en-US

I added this to StemFinder too, I marked the jira as resolved, if you need something else let me know J

 

Thanks,

Chris

 

From: Chris Hyzer
Sent: Friday, September 19, 2014 7:32 AM
To: 'David Langenberg'
Cc: John Gasper;
Subject: RE: [grouper-dev] Locating Stems and Groups with an Attribute Assigned

 

I added an option to GroupFinder to find by attribute or by attribute and value, I can add that to StemFinder too.  Ok?

 

https://github.com/Internet2/grouper/commit/be249b299ebfe47f1616f020a3fa98d41f1845d4

 

https://bugs.internet2.edu/jira/browse/GRP-1042

 

Here is the test case:

 

 

  /**

   *

   */

  public void testFindByAttributeDefName() {

 

    GrouperSession grouperSession = GrouperSession.startRootSession();

   

    AttributeDef attributeDef = new AttributeDefSave(grouperSession).assignAttributeDefNameToEdit("test:attrDef")

        .assignAttributeDefType(AttributeDefType.attr).assignCreateParentStemsIfNotExist(true)

        .assignToGroup(true)

        .assignValueType(AttributeDefValueType.string).save();

   

    AttributeDefName attributeDefName = new AttributeDefNameSave(grouperSession, attributeDef)

      .assignAttributeDefNameNameToEdit("test:attrDefName").assignCreateParentStemsIfNotExist(true).save();

 

    Group group0 = new GroupSave(grouperSession).assignName("test:group0").assignCreateParentStemsIfNotExist(true).save();

    Group group1 = new GroupSave(grouperSession).assignName("test:group1").assignCreateParentStemsIfNotExist(true).save();

    Group group2 = new GroupSave(grouperSession).assignName("test:group2").assignCreateParentStemsIfNotExist(true).save();

    Group group3 = new GroupSave(grouperSession).assignName("test:group3").assignCreateParentStemsIfNotExist(true).save();

    Group group4 = new GroupSave(grouperSession).assignName("test:group4").assignCreateParentStemsIfNotExist(true).save();

 

    group0.getAttributeValueDelegate().assignValue(attributeDefName.getName(), "abc");

    group1.getAttributeValueDelegate().assignValue(attributeDefName.getName(), "xyz");

    group3.getAttributeValueDelegate().assignValue(attributeDefName.getName(), "abc");

    group4.getAttributeValueDelegate().assignValue(attributeDefName.getName(), "abc");

   

    attributeDef.getPrivilegeDelegate().grantPriv(SubjectTestHelper.SUBJ0, AttributeDefPrivilege.ATTR_READ, false);

    attributeDef.getPrivilegeDelegate().grantPriv(SubjectTestHelper.SUBJ1, AttributeDefPrivilege.ATTR_READ, false);

   

    group0.grantPriv(SubjectTestHelper.SUBJ0, AccessPrivilege.GROUP_ATTR_READ);

    group1.grantPriv(SubjectTestHelper.SUBJ0, AccessPrivilege.GROUP_ATTR_READ);

    group2.grantPriv(SubjectTestHelper.SUBJ0, AccessPrivilege.GROUP_ATTR_READ);

    group3.grantPriv(SubjectTestHelper.SUBJ0, AccessPrivilege.GROUP_ATTR_READ);

   

    group0.grantPriv(SubjectTestHelper.SUBJ2, AccessPrivilege.GROUP_ATTR_READ);

    group1.grantPriv(SubjectTestHelper.SUBJ2, AccessPrivilege.GROUP_ATTR_READ);

    group2.grantPriv(SubjectTestHelper.SUBJ2, AccessPrivilege.GROUP_ATTR_READ);

    group3.grantPriv(SubjectTestHelper.SUBJ2, AccessPrivilege.GROUP_ATTR_READ);

    group4.grantPriv(SubjectTestHelper.SUBJ2, AccessPrivilege.GROUP_ATTR_READ);

   

    //subj0 can read most of both

    //subj1 can read the attr

    //subj2 can read the group attrs

   

    GrouperSession.stopQuietly(grouperSession);

 

    grouperSession = GrouperSession.start(SubjectTestHelper.SUBJ0);

   

    List<Group> groups = new ArrayList<Group>(new GroupFinder().assignNameOfAttributeDefName(attributeDefName.getName())

        .assignPrivileges(AccessPrivilege.ATTRIBUTE_READ_PRIVILEGES).findGroups());

   

    assertEquals(3, GrouperUtil.length(groups));

    assertEquals("test:group0", groups.get(0).getName());

    assertEquals("test:group1", groups.get(1).getName());

    assertEquals("test:group3", groups.get(2).getName());

   

    groups = new ArrayList<Group>(new GroupFinder().assignNameOfAttributeDefName(attributeDefName.getName())

        .assignPrivileges(AccessPrivilege.ATTRIBUTE_READ_PRIVILEGES).assignAttributeValue("abc").findGroups());

   

    assertEquals(2, GrouperUtil.length(groups));

    assertEquals("test:group0", groups.get(0).getName());

    assertEquals("test:group3", groups.get(1).getName());

   

    GrouperSession.stopQuietly(grouperSession);

   

 

    // #####################

   

    grouperSession = GrouperSession.start(SubjectTestHelper.SUBJ1);

 

    groups = new ArrayList<Group>(new GroupFinder().assignNameOfAttributeDefName(attributeDefName.getName())

        .assignPrivileges(AccessPrivilege.ATTRIBUTE_READ_PRIVILEGES).findGroups());

   

    assertEquals(0, GrouperUtil.length(groups));

   

    groups = new ArrayList<Group>(new GroupFinder().assignNameOfAttributeDefName(attributeDefName.getName())

        .assignPrivileges(AccessPrivilege.ATTRIBUTE_READ_PRIVILEGES).assignAttributeValue("abc").findGroups());

   

    assertEquals(0, GrouperUtil.length(groups));

   

    GrouperSession.stopQuietly(grouperSession);

   

    // #####################

   

    grouperSession = GrouperSession.start(SubjectTestHelper.SUBJ2);

 

    try {

      groups = new ArrayList<Group>(new GroupFinder().assignNameOfAttributeDefName(attributeDefName.getName())

          .assignPrivileges(AccessPrivilege.ATTRIBUTE_READ_PRIVILEGES).findGroups());

      fail("Cant find attribute");

    } catch (Exception e) {

      //good

    }

   

    groups = new ArrayList<Group>(new GroupFinder().assignIdOfAttributeDefName(attributeDefName.getId())

        .assignPrivileges(AccessPrivilege.ATTRIBUTE_READ_PRIVILEGES).findGroups());

   

    assertEquals(0, GrouperUtil.length(groups));

   

    groups = new ArrayList<Group>(new GroupFinder().assignIdOfAttributeDefName(attributeDefName.getId())

        .assignPrivileges(AccessPrivilege.ATTRIBUTE_READ_PRIVILEGES).assignAttributeValue("abc").findGroups());

   

    assertEquals(0, GrouperUtil.length(groups));

 

   

    GrouperSession.stopQuietly(grouperSession);

   

    

  }

 

 

 

From: David Langenberg []
Sent: Thursday, September 18, 2014 9:52 AM
To: Chris Hyzer
Cc: John Gasper;
Subject: Re: [grouper-dev] Locating Stems and Groups with an Attribute Assigned

 

Yipes!  Seems we need a simple AttributeFinder class that will just find the things an attribute is assigned to similiar to how we have SubjectFinder or GroupFinder.  In our Grouper here @ Chicago we're particularly fond of the TypeFinder.


Dave

 

On Wed, Sep 17, 2014 at 11:57 PM, Chris Hyzer <> wrote:

We probably need more straightforward ways to query this… anyways, e.g. for stems you can do this:

 

    Set<AttributeAssign> attributeAssigns = GrouperDAOFactory.getFactory()

      .getAttributeAssign().findStemAttributeAssignments(null, null, GrouperUtil.toSet(attributeDefName.getId()), null, null, true, false);


Then from there, collate all the stemIds from the attribute assign objects, and do a quey to get those (I think StemFinder chaining can do that)

 

Let me know if you need more info or an example J

 

Thanks,

Chris

 

From: [mailto:] On Behalf Of John Gasper
Sent: Wednesday, September 17, 2014 5:57 PM
To:
Subject: [grouper-dev] Locating Stems and Groups with an Attribute Assigned

 

Hi all,

Using the API (via ChangeLog Consumer) in 2.2, I'm trying to locate stems and groups that have a particular AttributeName assigned to them. After inspecting both the AttributeDef and the AttributeDefName objects in a debugger, few promising methods/properties return sets that have zero entries even though I know I have assigned an attribute assigned to a stem and group.

Surely, I don't need to recursively walk the tree to find them all?!?

Please point me in the correct direction.

Thanks,
John

---
John Gasper
IAM Consultant
Unicon, Inc.
PGP/GPG Key: 0xbafee3ef



 

--
David Langenberg

Identity & Access Management

The University of Chicago




Archive powered by MHonArc 2.6.16.

Top of Page