Search in sources :

Example 1 with AttributeChangedForUser

use of cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser in project perun by CESNET.

the class urn_perun_user_attribute_def_virt_eduPersonScopedAffiliations method resolveVirtualAttributeValueChange.

@Override
public List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, AuditEvent message) throws WrongReferenceAttributeValueException, AttributeNotExistsException, WrongAttributeAssignmentException {
    // generic handling
    List<AuditEvent> resolvingMessages = super.resolveVirtualAttributeValueChange(perunSession, message);
    if (message instanceof AttributeSetForUser && ((AttributeSetForUser) message).getAttribute().getFriendlyName().equals(getSecondarySourceAttributeFriendlyName())) {
        AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName());
        resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), ((AttributeSetForUser) message).getUser()));
    } else if (message instanceof AttributeRemovedForUser && ((AttributeRemovedForUser) message).getAttribute().getFriendlyName().equals(getSecondarySourceAttributeFriendlyName())) {
        AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName());
        resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), ((AttributeRemovedForUser) message).getUser()));
    } else if (message instanceof AllAttributesRemovedForUser) {
        boolean skip = false;
        try {
            AttributeDefinition sourceExists = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getSecondarySourceAttributeName());
            User user = perunSession.getPerunBl().getUsersManagerBl().getUserById(perunSession, ((AllAttributesRemovedForUser) message).getUser().getId());
        } catch (AttributeNotExistsException | UserNotExistsException ex) {
            // silently skip this event, since source attribute couldn't be between deleted
            // or user no longer exist
            skip = true;
        }
        if (!skip) {
            AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName());
            resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), ((AllAttributesRemovedForUser) message).getUser()));
        }
    }
    if (message instanceof AttributeSetForGroup && !VosManager.MEMBERS_GROUP.equals(((AttributeSetForGroup) message).getGroup().getName()) && ((AttributeSetForGroup) message).getAttribute().getName().equals(getTertiarySourceAttributeName())) {
        AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName());
        // TODO - get only active group users, since expired are not affected by current group affiliations
        List<User> users = perunSession.getPerunBl().getGroupsManagerBl().getGroupUsers(perunSession, ((AttributeSetForGroup) message).getGroup());
        for (User user : users) {
            resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), user));
        }
    } else if (message instanceof AttributeRemovedForGroup && !VosManager.MEMBERS_GROUP.equals(((AttributeRemovedForGroup) message).getGroup().getName()) && ((AttributeRemovedForGroup) message).getAttribute().getName().equals(getTertiarySourceAttributeName())) {
        AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName());
        // TODO - get only active group users, since expired are not affected by current group affiliations
        List<User> users = perunSession.getPerunBl().getGroupsManagerBl().getGroupUsers(perunSession, ((AttributeRemovedForGroup) message).getGroup());
        for (User user : users) {
            resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), user));
        }
    } else if (message instanceof AllAttributesRemovedForGroup && !VosManager.MEMBERS_GROUP.equals(((AllAttributesRemovedForGroup) message).getGroup().getName())) {
        boolean skip = false;
        try {
            AttributeDefinition sourceExists = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getTertiarySourceAttributeName());
            Group group = perunSession.getPerunBl().getGroupsManagerBl().getGroupById(perunSession, ((AllAttributesRemovedForGroup) message).getGroup().getId());
        } catch (AttributeNotExistsException | GroupNotExistsException ex) {
            // silently skip this event, since source attribute couldn't be between deleted
            // or group no longer exist.
            skip = true;
        }
        if (!skip) {
            AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName());
            // TODO - get only active group users, since expired are not affected by current group affiliations
            List<User> users = perunSession.getPerunBl().getGroupsManagerBl().getGroupUsers(perunSession, ((AllAttributesRemovedForGroup) message).getGroup());
            for (User user : users) {
                resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), user));
            }
        }
    }
    return resolvingMessages;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) AttributeRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForGroup) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) AllAttributesRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) AttributeSetForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForGroup) AttributeSetForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForGroup) AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser) AttributeRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUser) User(cz.metacentrum.perun.core.api.User) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser) AllAttributesRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) Attribute(cz.metacentrum.perun.core.api.Attribute) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AttributeRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUser) AllAttributesRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForGroup) AllAttributesRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) ArrayList(java.util.ArrayList) List(java.util.List) AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser) AttributeRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForGroup)

Example 2 with AttributeChangedForUser

use of cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser in project perun by CESNET.

the class UserVirtualAttributeCollectedFromUserExtSource method resolveVirtualAttributeValueChange.

@Override
public List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, AuditEvent message) throws WrongReferenceAttributeValueException, AttributeNotExistsException, WrongAttributeAssignmentException {
    List<AuditEvent> resolvingMessages = new ArrayList<>();
    if (message == null)
        return resolvingMessages;
    List<AttributeHandleIdentifier> list = getHandleIdentifiers();
    for (AttributeHandleIdentifier attributeHandleIdenfier : list) {
        Integer userId = attributeHandleIdenfier.shouldBeEventHandled(message);
        if (userId != null) {
            try {
                User user = perunSession.getPerunBl().getUsersManagerBl().getUserById(perunSession, userId);
                AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, getDestinationAttributeName());
                resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), user));
            } catch (UserNotExistsException e) {
                log.warn("User from UserExtSource doesn't exist in Perun. This occurred while parsing message: {}.", message);
            }
        }
    }
    return resolvingMessages;
}
Also used : AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser)

Example 3 with AttributeChangedForUser

use of cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser in project perun by CESNET.

the class urn_perun_user_attribute_def_virt_groupNames method resolveEvent.

private AuditEvent resolveEvent(PerunSessionImpl sess, Member member) throws AttributeNotExistsException {
    User user = sess.getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
    AttributeDefinition attributeDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, A_U_V_GROUP_NAMES);
    return new AttributeChangedForUser(new Attribute(attributeDefinition), user);
}
Also used : AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser)

Example 4 with AttributeChangedForUser

use of cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser in project perun by CESNET.

the class urn_perun_user_attribute_def_virt_institutionsCountries method resolveEvent.

private List<AuditEvent> resolveEvent(PerunSessionImpl sess, String key) throws WrongAttributeAssignmentException, AttributeNotExistsException {
    List<AuditEvent> resolvingMessages = new ArrayList<>();
    List<String> longerDomains = new ArrayList<>();
    AttributesManagerBl am = sess.getPerunBl().getAttributesManagerBl();
    for (String dnsDomain : am.getEntitylessStringAttributeMapping(sess, DNS_STATE_MAPPING_ATTR.getName()).keySet()) {
        if (dnsDomain.endsWith(key) && dnsDomain.length() > key.length()) {
            longerDomains.add(dnsDomain);
        }
    }
    log.debug("DNS domain '{}' changed, found longer domains: {}", key, longerDomains);
    // find users that are affected by the change - have schacHomeOrganization value ending in key but not ending with longerDomains
    List<User> affectedUsers = sess.getPerunBl().getUsersManagerBl().findUsersWithExtSourceAttributeValueEnding(sess, getSourceAttributeName(), key, longerDomains);
    for (User user : affectedUsers) {
        AttributeDefinition attributeDefinition = am.getAttributeDefinition(sess, getDestinationAttributeName());
        resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), user));
    }
    return resolvingMessages;
}
Also used : AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl)

Example 5 with AttributeChangedForUser

use of cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser in project perun by CESNET.

the class urn_perun_user_attribute_def_virt_tcsMails_mu method resolveVirtualAttributeValueChange.

@Override
public List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, AuditEvent message) throws AttributeNotExistsException {
    List<AuditEvent> resolvingMessages = new ArrayList<>();
    // handle source user attributes changes
    if (message instanceof AttributeSetForUser && isAffectedAttribute(((AttributeSetForUser) message).getAttribute().getFriendlyName())) {
        AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, this.getAttributeDefinition().getName());
        resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), ((AttributeSetForUser) message).getUser()));
    } else if (message instanceof AttributeRemovedForUser && isAffectedAttribute(((AttributeRemovedForUser) message).getAttribute().getFriendlyName())) {
        AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, this.getAttributeDefinition().getName());
        resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), ((AttributeRemovedForUser) message).getUser()));
    } else if (message instanceof AllAttributesRemovedForUser) {
        AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, this.getAttributeDefinition().getName());
        resolvingMessages.add(new AttributeChangedForUser(new Attribute(attributeDefinition), ((AllAttributesRemovedForUser) message).getUser()));
    }
    return resolvingMessages;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AllAttributesRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser) AttributeRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUser) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser)

Aggregations

AttributeChangedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser)5 Attribute (cz.metacentrum.perun.core.api.Attribute)5 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5 AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)4 User (cz.metacentrum.perun.core.api.User)4 ArrayList (java.util.ArrayList)4 AllAttributesRemovedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser)2 AttributeRemovedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUser)2 AttributeSetForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser)2 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)2 AllAttributesRemovedForGroup (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForGroup)1 AttributeRemovedForGroup (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForGroup)1 AttributeSetForGroup (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForGroup)1 DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)1 IndirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup)1 MemberExpiredInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup)1 MemberValidatedInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup)1 Group (cz.metacentrum.perun.core.api.Group)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)1