Search in sources :

Example 1 with MemberGroupStatus

use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.

the class GroupsManagerEntryIntegrationTest method getTotalGroupStatusForMembers_notMembersOfGroup.

@Test
public void getTotalGroupStatusForMembers_notMembersOfGroup() throws Exception {
    System.out.println(CLASS_NAME + "getTotalGroupStatusForMembers_notMembersOfGroup");
    // set up member in group and vo
    Vo vo = setUpVo();
    Member member = setUpMember(vo);
    groupsManagerBl.createGroup(sess, vo, group);
    groupsManagerBl.createGroup(sess, vo, group2);
    groupsManagerBl.addMember(sess, group, member);
    Map<Integer, MemberGroupStatus> map = groupsManagerBl.getTotalGroupStatusForMembers(sess, group2, List.of(member));
    assertTrue("There should be no relation between the group and the member", map.isEmpty());
}
Also used : Vo(cz.metacentrum.perun.core.api.Vo) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 2 with MemberGroupStatus

use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.

the class GroupsManagerEntryIntegrationTest method getTotalGroupStatusForMembers.

@Test
public void getTotalGroupStatusForMembers() throws Exception {
    System.out.println(CLASS_NAME + "getTotalGroupStatusForMembers");
    // set up member in group and vo
    Vo vo = setUpVo();
    Member member = setUpMemberWithDifferentParam(vo, 111);
    Member member2 = setUpMemberWithDifferentParam(vo, 222);
    Member member3 = setUpMemberWithDifferentParam(vo, 333);
    Member member4 = setUpMemberWithDifferentParam(vo, 444);
    groupsManagerBl.createGroup(sess, vo, group);
    groupsManagerBl.addMember(sess, group, member);
    groupsManagerBl.addMember(sess, group, member2);
    groupsManagerBl.addMember(sess, group, member3);
    groupsManagerBl.addMember(sess, group, member4);
    groupsManagerBl.expireMemberInGroup(sess, member, group);
    groupsManagerBl.expireMemberInGroup(sess, member2, group);
    Map<Integer, MemberGroupStatus> map = groupsManagerBl.getTotalGroupStatusForMembers(sess, group, List.of(member, member2, member3, member4));
    assertEquals("Member's group status is not EXPIRED", MemberGroupStatus.EXPIRED, map.get(member.getId()));
    assertEquals("Member's group status is not EXPIRED", MemberGroupStatus.EXPIRED, map.get(member2.getId()));
    assertEquals("Member's group status is not VALID", MemberGroupStatus.VALID, map.get(member3.getId()));
    assertEquals("Member's group status is not VALID", MemberGroupStatus.VALID, map.get(member4.getId()));
}
Also used : Vo(cz.metacentrum.perun.core.api.Vo) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 3 with MemberGroupStatus

use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.

the class GroupsManagerBlImpl method validateMemberInGroup.

@Override
public void validateMemberInGroup(PerunSession sess, Member member, Group group) {
    if (group == null) {
        throw new InternalErrorException("Group can not be null.");
    }
    if (VosManager.MEMBERS_GROUP.equals(group.getName())) {
        throw new InternalErrorException("Can not validate member in members group.");
    }
    if (member == null) {
        throw new InternalErrorException("Member to validate can not be null");
    }
    MemberGroupStatus previousStatus = getDirectMemberGroupStatus(sess, member, group);
    if (MemberGroupStatus.VALID.equals(previousStatus)) {
        log.warn("Validating member in group where is already validated. Member: {}, Group: {}", member, group);
    }
    Map<Integer, Map<Integer, MemberGroupStatus>> previousIndirectStatuses = getPreviousStatuses(sess, group, List.of(member));
    // validate member in given group
    groupsManagerImpl.setDirectGroupStatus(sess, member, group, MemberGroupStatus.VALID);
    recalculateMemberGroupStatusRecursively(sess, member, group, previousIndirectStatuses);
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus)

Example 4 with MemberGroupStatus

use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.

the class GroupsManagerEntryIntegrationTest method getTotalGroupStatusForMembers_memberValidThroughSubgroup.

@Test
public void getTotalGroupStatusForMembers_memberValidThroughSubgroup() throws Exception {
    System.out.println(CLASS_NAME + "getTotalGroupStatusForMembers_memberValidThroughSubgroup");
    // set up member in group and vo
    Vo vo = setUpVo();
    Member member = setUpMember(vo);
    groupsManagerBl.createGroup(sess, vo, group);
    groupsManagerBl.createGroup(sess, group, group2);
    groupsManagerBl.addMember(sess, group, member);
    groupsManagerBl.addMember(sess, group2, member);
    groupsManagerBl.expireMemberInGroup(sess, member, group);
    Map<Integer, MemberGroupStatus> map = groupsManagerBl.getTotalGroupStatusForMembers(sess, group, List.of(member));
    assertEquals("Member's group status is not EXPIRED", MemberGroupStatus.VALID, map.get(member.getId()));
}
Also used : Vo(cz.metacentrum.perun.core.api.Vo) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 5 with MemberGroupStatus

use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.

the class urn_perun_member_group_attribute_def_def_groupMembershipExpiration method changedAttributeHook.

@Override
public void changedAttributeHook(PerunSessionImpl session, Member member, Group group, Attribute attribute) {
    String value = null;
    if (attribute.getValue() != null)
        value = (String) attribute.getValue();
    // If there is some value and member is in status expired or disabled
    // find out members status in given group
    MemberGroupStatus status = session.getPerunBl().getGroupsManagerBl().getDirectMemberGroupStatus(session, member, group);
    // status is null if member is not direct at the time -> changing value doesn't affect indirect membership
    if (value != null && MemberGroupStatus.EXPIRED.equals(status)) {
        Date expirationDate;
        try {
            expirationDate = BeansUtils.getDateFormatterWithoutTime().parse(value);
        } catch (ParseException ex) {
            throw new InternalErrorException("Date parsing failed in setHook, even if parsing in checkMethod was correct.", ex);
        }
        Date date = new Date();
        if (expirationDate.compareTo(date) > 0) {
            session.getPerunBl().getGroupsManagerBl().validateMemberInGroup(session, member, group);
        }
    }
}
Also used : ParseException(java.text.ParseException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) Date(java.util.Date)

Aggregations

MemberGroupStatus (cz.metacentrum.perun.core.api.MemberGroupStatus)19 Member (cz.metacentrum.perun.core.api.Member)12 Attribute (cz.metacentrum.perun.core.api.Attribute)8 Test (org.junit.Test)8 Group (cz.metacentrum.perun.core.api.Group)6 RichMember (cz.metacentrum.perun.core.api.RichMember)6 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 HashMap (java.util.HashMap)5 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)4 LinkedHashMap (java.util.LinkedHashMap)4 Vo (cz.metacentrum.perun.core.api.Vo)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)2 DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)2 IndirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup)2 IndirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup)2 MemberExpiredInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup)2 MemberValidatedInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup)2