Search in sources :

Example 6 with Person

use of edu.hawaii.its.api.type.Person in project uhgroupings by uhawaii-system-its-ti-iam.

the class MemberAttributeServiceTest method isMemberTest.

@Test
public void isMemberTest() {
    // test with username
    Person person2 = users.get(2);
    Person person5 = users.get(5);
    assertFalse(memberAttributeService.isMember(GROUPING_0_PATH, person2));
    assertTrue(memberAttributeService.isMember(GROUPING_0_PATH, person5));
    // test with uuid
    person2.setUsername(null);
    person5.setUsername(null);
    assertFalse(memberAttributeService.isMember(GROUPING_0_PATH, person2));
    assertTrue(memberAttributeService.isMember(GROUPING_0_PATH, person5));
}
Also used : Person(edu.hawaii.its.api.type.Person) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with Person

use of edu.hawaii.its.api.type.Person in project uhgroupings by uhawaii-system-its-ti-iam.

the class MemberAttributeServiceTest method checkSelfOptedTest.

@Test
public void checkSelfOptedTest() {
    // user is not in group
    boolean selfOpted = memberAttributeService.isSelfOpted(GROUPING_0_INCLUDE_PATH, users.get(2).getUsername());
    assertFalse(selfOpted);
    // user has not self opted
    selfOpted = memberAttributeService.isSelfOpted(GROUPING_0_INCLUDE_PATH, users.get(5).getUsername());
    assertFalse(selfOpted);
    // user has self opted
    Person person = personRepository.findByUsername(users.get(5).getUsername());
    Group group = groupRepository.findByPath(GROUPING_0_INCLUDE_PATH);
    Membership membership = membershipRepository.findByPersonAndGroup(person, group);
    membership.setSelfOpted(true);
    membershipRepository.save(membership);
    selfOpted = memberAttributeService.isSelfOpted(GROUPING_0_INCLUDE_PATH, users.get(5).getUsername());
    assertTrue(selfOpted);
}
Also used : Group(edu.hawaii.its.api.type.Group) Membership(edu.hawaii.its.api.type.Membership) Person(edu.hawaii.its.api.type.Person) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with Person

use of edu.hawaii.its.api.type.Person in project uhgroupings by uhawaii-system-its-ti-iam.

the class MemberAttributeServiceTest method assignOwnershipTest.

@Test
public void assignOwnershipTest() {
    // expect this to fail
    GroupingsServiceResult randomUserAdds;
    Person randomUser = personRepository.findByUsername(users.get(1).getUsername());
    Grouping grouping = groupingRepository.findByPath(GROUPING_0_PATH);
    assertFalse(grouping.getOwners().getMembers().contains(randomUser));
    assertFalse(grouping.getOwners().isMember(randomUser));
    try {
        randomUserAdds = memberAttributeService.assignOwnership(GROUPING_0_PATH, randomUser.getUsername(), randomUser.getUsername());
    } catch (GroupingsServiceResultException gsre) {
        randomUserAdds = gsre.getGsr();
    }
    grouping = groupingRepository.findByPath(GROUPING_0_PATH);
    assertFalse(grouping.getOwners().getMembers().contains(randomUser));
    assertFalse(grouping.getOwners().isMember(randomUser));
    assertNotEquals(randomUserAdds.getResultCode(), SUCCESS);
    GroupingsServiceResult ownerAdds = memberAttributeService.assignOwnership(GROUPING_0_PATH, users.get(0).getUsername(), randomUser.getUsername());
    grouping = groupingRepository.findByPath(GROUPING_0_PATH);
    assertTrue(grouping.getOwners().getMembers().contains(randomUser));
    assertTrue(grouping.getOwners().isMember(randomUser));
    assertEquals(ownerAdds.getResultCode(), SUCCESS);
    GroupingsServiceResult adminAdds = memberAttributeService.assignOwnership(GROUPING_0_PATH, ADMIN_USER, randomUser.getUsername());
    grouping = groupingRepository.findByPath(GROUPING_0_PATH);
    assertTrue(grouping.getOwners().getMembers().contains(randomUser));
    assertTrue(grouping.getOwners().isMember(randomUser));
    assertEquals(SUCCESS, adminAdds.getResultCode());
}
Also used : GroupingsServiceResultException(edu.hawaii.its.api.type.GroupingsServiceResultException) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Grouping(edu.hawaii.its.api.type.Grouping) Person(edu.hawaii.its.api.type.Person) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with Person

use of edu.hawaii.its.api.type.Person in project uhgroupings by uhawaii-system-its-ti-iam.

the class MembershipServiceTest method addMembersByUsername.

@Test
public void addMembersByUsername() {
    // add all usernames
    List<String> usernames = new ArrayList<>();
    for (Person user : users) {
        usernames.add(user.getUsername());
    }
    Grouping grouping = groupingRepository.findByPath(GROUPING_3_PATH);
    // check how many members are in the basis
    int numberOfBasisMembers = grouping.getBasis().getMembers().size();
    // try to put all users into exclude group
    membershipService.addGroupMembersByUsername(users.get(0).getUsername(), GROUPING_3_EXCLUDE_PATH, usernames);
    grouping = groupingRepository.findByPath(GROUPING_3_PATH);
    // there should be no real members in composite, but it should still have the 'grouperAll' member
    assertEquals(1, grouping.getComposite().getMembers().size());
    // only the users in the basis should have been added to the exclude group
    assertEquals(numberOfBasisMembers, grouping.getExclude().getMembers().size());
    // try to put all users into the include group
    membershipService.addGroupMembersByUsername(users.get(0).getUsername(), GROUPING_3_INCLUDE_PATH, usernames);
    grouping = groupingRepository.findByPath(GROUPING_3_PATH);
    // all members should be in the group ( - 1 for 'grouperAll' in composite);
    assertEquals(usernames.size(), grouping.getComposite().getMembers().size() - 1);
    // members in basis should not have been added to the include group ( + 2 for 'grouperAll' in both groups)
    assertEquals(usernames.size() - numberOfBasisMembers + 2, grouping.getInclude().getMembers().size());
}
Also used : ArrayList(java.util.ArrayList) Grouping(edu.hawaii.its.api.type.Grouping) Person(edu.hawaii.its.api.type.Person) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with Person

use of edu.hawaii.its.api.type.Person in project uhgroupings by uhawaii-system-its-ti-iam.

the class GrouperFactoryServiceImplLocal method makeWsAddMemberResults.

@Override
public WsAddMemberResults makeWsAddMemberResults(String group, WsSubjectLookup lookup, Person personToAdd) {
    Person newGroupMember;
    WsAddMemberResults wsAddMemberResults = new WsAddMemberResults();
    WsResultMeta wsResultMeta = new WsResultMeta();
    wsResultMeta.setResultCode(SUCCESS);
    wsAddMemberResults.setResultMetadata(wsResultMeta);
    Grouping grouping = groupingRepository.findByIncludePathOrExcludePathOrCompositePathOrOwnersPath(group, group, group, group);
    if (personToAdd.getUsername() != null) {
        newGroupMember = personRepository.findByUsername(personToAdd.getUsername());
    } else {
        newGroupMember = personRepository.findByUuid(personToAdd.getUuid());
    }
    if (grouping == null) {
        Group groupToAddTo = groupRepository.findByPath(group);
        addMember(groupToAddTo, newGroupMember);
    } else {
        boolean inBasis = grouping.getBasis().isMember(newGroupMember);
        boolean inExclude = grouping.getExclude().isMember(newGroupMember);
        boolean inInclude = grouping.getInclude().isMember(newGroupMember);
        if (group.endsWith(OWNERS)) {
            addMember(grouping.getOwners(), newGroupMember);
        } else if (group.endsWith(EXCLUDE)) {
            if (inBasis) {
                addMember(grouping.getExclude(), newGroupMember);
            } else if (inInclude) {
                deleteMember(grouping.getInclude(), newGroupMember);
            }
        } else if (group.endsWith(INCLUDE)) {
            if (inExclude) {
                deleteMember(grouping.getExclude(), newGroupMember);
            } else if (!inBasis) {
                addMember(grouping.getInclude(), newGroupMember);
            }
        }
        grouping = groupingRepository.findByPath(grouping.getPath());
        Group composite = buildComposite(grouping.getInclude(), grouping.getExclude(), grouping.getBasis(), grouping.getPath());
        groupRepository.save(composite);
    }
    return wsAddMemberResults;
}
Also used : WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) Group(edu.hawaii.its.api.type.Group) WsResultMeta(edu.internet2.middleware.grouperClient.ws.beans.WsResultMeta) Grouping(edu.hawaii.its.api.type.Grouping) Person(edu.hawaii.its.api.type.Person) WsAddMemberResults(edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)

Aggregations

Person (edu.hawaii.its.api.type.Person)32 Group (edu.hawaii.its.api.type.Group)20 WsGroup (edu.internet2.middleware.grouperClient.ws.beans.WsGroup)9 WsSubjectLookup (edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup)8 Before (org.junit.Before)8 Grouping (edu.hawaii.its.api.type.Grouping)7 ArrayList (java.util.ArrayList)7 WsResultMeta (edu.internet2.middleware.grouperClient.ws.beans.WsResultMeta)6 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Membership (edu.hawaii.its.api.type.Membership)5 GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)3 WsMembership (edu.internet2.middleware.grouperClient.ws.beans.WsMembership)3 WsSubject (edu.internet2.middleware.grouperClient.ws.beans.WsSubject)2 GroupingsServiceResultException (edu.hawaii.its.api.type.GroupingsServiceResultException)1 WsAddMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)1 WsAssignAttributesResults (edu.internet2.middleware.grouperClient.ws.beans.WsAssignAttributesResults)1 WsAssignGrouperPrivilegesLiteResult (edu.internet2.middleware.grouperClient.ws.beans.WsAssignGrouperPrivilegesLiteResult)1 WsDeleteMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsDeleteMemberResults)1 WsGetGrouperPrivilegesLiteResult (edu.internet2.middleware.grouperClient.ws.beans.WsGetGrouperPrivilegesLiteResult)1