Search in sources :

Example 1 with AttributeSetForUser

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

the class AttributesManagerBlImpl method setAttributeWithoutCheck.

@Override
public boolean setAttributeWithoutCheck(PerunSession sess, User user, Attribute attribute) throws WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_USER_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed;
    if (isVirtAttribute(sess, attribute)) {
        return getAttributesManagerImpl().setVirtualAttribute(sess, user, attribute);
    } else {
        changed = getAttributesManagerImpl().setAttribute(sess, user, attribute);
    }
    if (changed) {
        getPerunBl().getAuditer().log(sess, new AttributeSetForUser(attribute, user));
        getAttributesManagerImpl().changedAttributeHook(sess, user, attribute);
    }
    return changed;
}
Also used : WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser)

Example 2 with AttributeSetForUser

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

the class urn_perun_user_attribute_def_virt_eduPersonScopedAffiliationsTest method resolveAttributeValueChangeTest.

@Test
public void resolveAttributeValueChangeTest() throws Exception {
    when(session.getPerunBl().getUsersManagerBl().getUserById(session, 1)).thenReturn(user);
    AuditEvent event = new AllAttributesRemovedForUserExtSource(ues1);
    List<AuditEvent> auditEvents = classInstance.resolveVirtualAttributeValueChange(session, event);
    assertEquals(auditEvents.get(0).getClass(), AttributeChangedForUser.class);
    event = new AllAttributesRemovedForUser(user);
    auditEvents = classInstance.resolveVirtualAttributeValueChange(session, event);
    assertEquals(auditEvents.get(0).getClass(), AttributeChangedForUser.class);
    Attribute attribute = new Attribute();
    attribute.setFriendlyName("eduPersonScopedAffiliationsManuallyAssigned");
    event = new AttributeSetForUser(attribute, user);
    auditEvents = classInstance.resolveVirtualAttributeValueChange(session, event);
    assertEquals(auditEvents.get(0).getClass(), AttributeChangedForUser.class);
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, AttributesManager.NS_USER_ATTR_VIRT + ":" + "eduPersonScopedAffiliations")).thenReturn(attribute);
    auditEvents = classInstance.resolveVirtualAttributeValueChange(session, event);
    assertEquals(auditEvents.get(0).getClass(), AttributeChangedForUser.class);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AllAttributesRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) AllAttributesRemovedForUserExtSource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUserExtSource) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser) Test(org.junit.Test)

Example 3 with AttributeSetForUser

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

the class urn_perun_user_attribute_def_virt_tcsMails_muTest method resolveVirtualAttributeValueChangeSet1.

@Test
public void resolveVirtualAttributeValueChangeSet1() throws Exception {
    AuditEvent userSet = new AttributeSetForUser(preferredMailAttr, user);
    List<AuditEvent> msgs = classInstance.resolveVirtualAttributeValueChange(sess, userSet);
    assertTrue("audit should contain change of tcsMails", msgs.get(0).getMessage().contains(expectedTestOfMessage));
}
Also used : AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser) Test(org.junit.Test)

Example 4 with AttributeSetForUser

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

the class urn_perun_user_attribute_def_virt_tcsMails_muTest method resolveVirtualAttributeValueChangeSet3.

@Test
public void resolveVirtualAttributeValueChangeSet3() throws Exception {
    AuditEvent userSet = new AttributeSetForUser(publicMailsAttr, user);
    List<AuditEvent> msgs = classInstance.resolveVirtualAttributeValueChange(sess, userSet);
    assertTrue("audit should contain change of tcsMails", msgs.get(0).getMessage().contains(expectedTestOfMessage));
}
Also used : AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser) Test(org.junit.Test)

Example 5 with AttributeSetForUser

use of cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser 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)

Aggregations

AttributeSetForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser)9 AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)8 Test (org.junit.Test)6 AllAttributesRemovedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser)3 Attribute (cz.metacentrum.perun.core.api.Attribute)3 AttributeChangedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser)2 AttributeRemovedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUser)2 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)2 ArrayList (java.util.ArrayList)2 AllAttributesRemovedForGroup (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForGroup)1 AllAttributesRemovedForUserExtSource (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUserExtSource)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 User (cz.metacentrum.perun.core.api.User)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1