Search in sources :

Example 6 with MemberGroupStatus

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

the class urn_perun_member_resource_attribute_def_virt_groupStatus method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Member member, Resource resource, AttributeDefinition attributeDefinition) {
    Attribute attribute = new Attribute(attributeDefinition);
    MemberGroupStatus result = sess.getPerunBl().getMembersManagerBl().getUnifiedMemberGroupStatus(sess, member, resource);
    attribute.setValue((result != null) ? result.toString() : null);
    return attribute;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus)

Example 7 with MemberGroupStatus

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

the class ExpirationNotifSchedulerTest method checkMembersGroupStateShouldExpireTodayDoesNotAffectOthers.

@Test
public void checkMembersGroupStateShouldExpireTodayDoesNotAffectOthers() throws Exception {
    System.out.println(CLASS_NAME + "checkMembersGroupStateShouldExpireToday");
    // setup expiration date to today
    String today = LocalDate.now().toString();
    // set up member in group
    // set up member in group
    Member member1 = setUpMember();
    Member member2 = setUpMember();
    Group group = setUpGroup();
    perun.getGroupsManagerBl().addMember(session, group, member1);
    perun.getGroupsManagerBl().addMember(session, group, member2);
    // set group expiration for today
    Attribute m1Expiration = new Attribute(perun.getAttributesManager().getAttributeDefinition(session, GROUP_EXPIRATION_URN));
    m1Expiration.setValue(today);
    perun.getAttributesManager().setAttribute(session, member1, group, m1Expiration);
    // set group expiration for tomorrow
    String tomorrow = LocalDate.now().plusDays(1).toString();
    Attribute m2Expiration = new Attribute(perun.getAttributesManager().getAttributeDefinition(session, GROUP_EXPIRATION_URN));
    m1Expiration.setValue(tomorrow);
    perun.getAttributesManager().setAttribute(session, member2, group, m2Expiration);
    scheduler.checkMembersState();
    MemberGroupStatus memberGroupStatus = perun.getGroupsManagerBl().getDirectMemberGroupStatus(session, member2, group);
    assertEquals("Member should not be expired!", MemberGroupStatus.VALID, memberGroupStatus);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) Attribute(cz.metacentrum.perun.core.api.Attribute) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) Test(org.junit.Test)

Example 8 with MemberGroupStatus

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

the class GroupsManagerBlImpl method recalculateMemberGroupStatusRecursively.

/**
 * Calculates the state of given member in given group and if
 * it differs from given 'previousState' calls this method recursively
 * for all parent groups.
 *
 * @param member member
 * @param group group
 * @param previousStatus previousStatus
 * @throws InternalErrorException internal error
 */
@Override
public void recalculateMemberGroupStatusRecursively(PerunSession sess, Member member, Group group, Map<Integer, Map<Integer, MemberGroupStatus>> previousStatus) {
    if (member == null) {
        throw new InternalErrorException("Member, which should be checked, can not be null.");
    }
    if (group == null) {
        throw new InternalErrorException("Group, where members status should be recalculated, can not be null.");
    }
    // skip members group where all members are valid all the time
    if (group.getName().equals(VosManager.MEMBERS_GROUP)) {
        return;
    }
    MemberGroupStatus newStatus = getTotalMemberGroupStatus(sess, member, group);
    boolean saveStatuses = true;
    // but we can not save statuses because the relations should be already removed
    if (newStatus == null) {
        saveStatuses = false;
    }
    // get all possibly affected groups and member's statuses for them
    List<Group> affectedGroups = new ArrayList<>(groupsManagerImpl.getResultGroups(sess, group.getId()));
    // if the new status is not null, update statuses received from the group to other groups
    if (saveStatuses) {
        groupsManagerImpl.setIndirectGroupStatus(sess, member, group, newStatus);
        if (previousStatus.get(group.getId()) == null || previousStatus.get(group.getId()).isEmpty() || !newStatus.equals(previousStatus.get(group.getId()).get(member.getId()))) {
            if (newStatus.equals(MemberGroupStatus.EXPIRED)) {
                getPerunBl().getAuditer().log(sess, new MemberExpiredInGroup(member, group));
            } else if (newStatus.equals(MemberGroupStatus.VALID)) {
                getPerunBl().getAuditer().log(sess, new MemberValidatedInGroup(member, group));
            }
        }
    }
    // check recursively all parent groups
    for (Group affectedGroup : affectedGroups) {
        recalculateMemberGroupStatusRecursively(sess, member, affectedGroup, previousStatus);
    }
}
Also used : EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) ArrayList(java.util.ArrayList) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus)

Example 9 with MemberGroupStatus

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

the class GroupsManagerBlImpl method getGroupMembersCountsByGroupStatus.

@Override
public Map<MemberGroupStatus, Integer> getGroupMembersCountsByGroupStatus(PerunSession sess, Group group) {
    List<Member> members = this.getGroupMembers(sess, group);
    Map<MemberGroupStatus, Integer> counts = new HashMap<>();
    for (MemberGroupStatus status : MemberGroupStatus.values()) {
        counts.put(status, 0);
    }
    members.forEach(member -> counts.computeIfPresent(member.getGroupStatus(), (key, value) -> value + 1));
    return counts;
}
Also used : Pair(cz.metacentrum.perun.core.api.Pair) Arrays(java.util.Arrays) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) GroupSynchronizationAlreadyRunningException(cz.metacentrum.perun.core.api.exceptions.GroupSynchronizationAlreadyRunningException) Vo(cz.metacentrum.perun.core.api.Vo) GroupSyncStarted(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupSyncStarted) GroupExistsException(cz.metacentrum.perun.core.api.exceptions.GroupExistsException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) Matcher(java.util.regex.Matcher) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) Collections.reverseOrder(java.util.Collections.reverseOrder) Map(java.util.Map) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) ExtSourceApi(cz.metacentrum.perun.core.implApi.ExtSourceApi) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) GroupResourceStatus(cz.metacentrum.perun.core.api.GroupResourceStatus) GroupRelationCannotBeRemoved(cz.metacentrum.perun.core.api.exceptions.GroupRelationCannotBeRemoved) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) ParserException(cz.metacentrum.perun.core.api.exceptions.ParserException) BeansUtils(cz.metacentrum.perun.core.api.BeansUtils) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) GroupMoveNotAllowedException(cz.metacentrum.perun.core.api.exceptions.GroupMoveNotAllowedException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Set(java.util.Set) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) User(cz.metacentrum.perun.core.api.User) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) RichMember(cz.metacentrum.perun.core.api.RichMember) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) GroupSyncFinished(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupSyncFinished) ExtSourceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotAssignedException) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) SynchronizationPool(cz.metacentrum.perun.core.impl.SynchronizationPool) GroupCreatedAsSubgroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedAsSubgroup) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) GroupSyncFinishedWithErrors(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupSyncFinishedWithErrors) GroupNotAllowedToAutoRegistrationException(cz.metacentrum.perun.core.api.exceptions.GroupNotAllowedToAutoRegistrationException) LocalDateTime(java.time.LocalDateTime) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) ExtSourceAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceAlreadyAssignedException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) GroupsManagerImplApi(cz.metacentrum.perun.core.implApi.GroupsManagerImplApi) GroupRelationDoesNotExist(cz.metacentrum.perun.core.api.exceptions.GroupRelationDoesNotExist) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) GroupCreatedInVo(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedInVo) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) ExtSourceSimpleApi(cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi) RichUser(cz.metacentrum.perun.core.api.RichUser) GroupStructureSynchronizationAlreadyRunningException(cz.metacentrum.perun.core.api.exceptions.GroupStructureSynchronizationAlreadyRunningException) Member(cz.metacentrum.perun.core.api.Member) GroupUpdated(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupUpdated) RichGroup(cz.metacentrum.perun.core.api.RichGroup) AbstractMembershipExpirationRulesModule(cz.metacentrum.perun.core.implApi.modules.attributes.AbstractMembershipExpirationRulesModule) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) ExtendMembershipException(cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) ChronoUnit(java.time.temporal.ChronoUnit) TreeMap(java.util.TreeMap) Utils(cz.metacentrum.perun.core.impl.Utils) MDC(org.slf4j.MDC) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) GroupsPageQuery(cz.metacentrum.perun.core.api.GroupsPageQuery) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Candidate(cz.metacentrum.perun.core.api.Candidate) AuthzResolver(cz.metacentrum.perun.core.api.AuthzResolver) Date(java.util.Date) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) LoggerFactory(org.slf4j.LoggerFactory) MemberRemovedFromGroupTotally(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberRemovedFromGroupTotally) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) ExtSourcesManager(cz.metacentrum.perun.core.api.ExtSourcesManager) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) Role(cz.metacentrum.perun.core.api.Role) ParseException(java.text.ParseException) GroupsManager(cz.metacentrum.perun.core.api.GroupsManager) GroupRelationNotAllowed(cz.metacentrum.perun.core.api.exceptions.GroupRelationNotAllowed) MemberNotValidYetException(cz.metacentrum.perun.core.api.exceptions.MemberNotValidYetException) ImmutableSet(com.google.common.collect.ImmutableSet) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Objects(java.util.Objects) VosManager(cz.metacentrum.perun.core.api.VosManager) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) List(java.util.List) LocalDate(java.time.LocalDate) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) GroupMoved(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupMoved) Resource(cz.metacentrum.perun.core.api.Resource) PerunSession(cz.metacentrum.perun.core.api.PerunSession) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) TemporalUnit(java.time.temporal.TemporalUnit) Paginated(cz.metacentrum.perun.core.api.Paginated) HashMap(java.util.HashMap) GroupStructureSyncFailed(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupStructureSyncFailed) Group(cz.metacentrum.perun.core.api.Group) GroupSynchronizationNotEnabledException(cz.metacentrum.perun.core.api.exceptions.GroupSynchronizationNotEnabledException) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) HashSet(java.util.HashSet) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) GroupStructureSyncFinishedWithErrors(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupStructureSyncFinishedWithErrors) GroupAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedException) GroupDeleted(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupDeleted) PerunLocksUtils.lockGroupMembership(cz.metacentrum.perun.core.impl.PerunLocksUtils.lockGroupMembership) NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) Comparator.comparingInt(java.util.Comparator.comparingInt) GroupRelationAlreadyExists(cz.metacentrum.perun.core.api.exceptions.GroupRelationAlreadyExists) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) GroupSyncFailed(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupSyncFailed) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ActionType(cz.metacentrum.perun.core.api.ActionType) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) MembershipType(cz.metacentrum.perun.core.api.MembershipType) Host(cz.metacentrum.perun.core.api.Host) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) Collectors.toList(java.util.stream.Collectors.toList) PerunClient(cz.metacentrum.perun.core.api.PerunClient) DateTimeFormatter(java.time.format.DateTimeFormatter) ExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceAlreadyRemovedException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) Comparator(java.util.Comparator) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus)

Example 10 with MemberGroupStatus

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

the class GroupsManagerBlImpl method expireMemberInGroup.

@Override
public void expireMemberInGroup(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 expire member in members group.");
    }
    if (member == null) {
        throw new InternalErrorException("Member to expire can not be null");
    }
    MemberGroupStatus previousStatus = getDirectMemberGroupStatus(sess, member, group);
    if (MemberGroupStatus.EXPIRED.equals(previousStatus)) {
        log.warn("Expiring member in group where is already expired. Member: {}, Group: {}", member, group);
    }
    Map<Integer, Map<Integer, MemberGroupStatus>> previousIndirectStatuses = getPreviousStatuses(sess, group, List.of(member));
    // expire in given group
    groupsManagerImpl.setDirectGroupStatus(sess, member, group, MemberGroupStatus.EXPIRED);
    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)

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