Search in sources :

Example 16 with AuditEvent

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

the class urn_perun_facility_attribute_def_virt_voShortNames method resolveVirtualAttributeValueChange.

@Override
public List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl sess, AuditEvent message) throws AttributeNotExistsException, WrongAttributeAssignmentException {
    List<AuditEvent> resolvingMessages = new ArrayList<>();
    if (message == null)
        return resolvingMessages;
    if (message instanceof ResourceCreated) {
        try {
            Facility facility = sess.getPerunBl().getFacilitiesManagerBl().getFacilityById(sess, ((ResourceCreated) message).getResource().getFacilityId());
            resolvingMessages.addAll(resolveEvent(sess, facility));
        } catch (FacilityNotExistsException e) {
            throw new ConsistencyErrorException("Facility for created Resource doesn't exists when resolving messages.", e);
        }
    } else if (message instanceof ResourceDeleted) {
        resolvingMessages.addAll(resolveEvent(sess, ((ResourceDeleted) message).getFacility()));
    }
    return resolvingMessages;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) ResourceCreated(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceCreated) ArrayList(java.util.ArrayList) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) AttributeChangedForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForFacility) AttributeSetForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacility) AttributeRemovedForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacility) Facility(cz.metacentrum.perun.core.api.Facility) ResourceDeleted(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceDeleted)

Example 17 with AuditEvent

use of cz.metacentrum.perun.audit.events.AuditEvent 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 18 with AuditEvent

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

the class AuditMessagesManagerImpl method pollConsumerEvents.

@Override
public List<AuditEvent> pollConsumerEvents(PerunSession perunSession, String consumerName) {
    checkAuditerConsumerExists(perunSession, consumerName);
    try {
        List<AuditEvent> eventList = new ArrayList<>();
        int lastProcessedId = getLastProcessedId(consumerName);
        int maxId = getLastMessageId(perunSession);
        if (maxId > lastProcessedId) {
            // get events
            eventList = jdbc.query("select " + auditMessageMappingSelectQuery + " from auditer_log where id > ? and id <= ? order by id", AUDIT_EVENT_MAPPER, lastProcessedId, maxId);
            // update counter
            setLastProcessedId(perunSession, consumerName, maxId);
        }
        return eventList;
    } catch (Exception ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : ArrayList(java.util.ArrayList) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) SQLException(java.sql.SQLException) IOException(java.io.IOException) PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException)

Example 19 with AuditEvent

use of cz.metacentrum.perun.audit.events.AuditEvent 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 20 with AuditEvent

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

the class urn_perun_user_attribute_def_virt_loa method resolveVirtualAttributeValueChange.

@Override
public List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl sess, AuditEvent message) throws AttributeNotExistsException, WrongAttributeAssignmentException {
    List<AuditEvent> resolvingMessages = new ArrayList<>();
    if (message == null)
        return resolvingMessages;
    User user = null;
    try {
        if (message instanceof UserExtSourceAddedToUser) {
            user = ((UserExtSourceAddedToUser) message).getUser();
            sess.getPerunBl().getUsersManagerBl().checkUserExists(sess, user);
            resolvingMessages.add(resolveEvent(sess, user));
        } else if (message instanceof UserExtSourceRemovedFromUser) {
            user = ((UserExtSourceRemovedFromUser) message).getUser();
            sess.getPerunBl().getUsersManagerBl().checkUserExists(sess, user);
            resolvingMessages.add(resolveEvent(sess, user));
        } else if (message instanceof UserExtSourceUpdated) {
            resolvingMessages.add(resolveEvent(sess, sess.getPerunBl().getUsersManagerBl().getUserById(sess, ((UserExtSourceUpdated) message).getUserExtSource().getUserId())));
        }
    } catch (UserNotExistsException e) {
        log.warn("User {} associated with event {} no longer exists while resolving virtual attribute value change for LoA.", user, message.getName());
    }
    return resolvingMessages;
}
Also used : UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser) User(cz.metacentrum.perun.core.api.User) UserExtSourceRemovedFromUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser) UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) UserExtSourceUpdated(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceUpdated) ArrayList(java.util.ArrayList) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) UserExtSourceRemovedFromUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser)

Aggregations

AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)33 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)11 Attribute (cz.metacentrum.perun.core.api.Attribute)9 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)9 AttributeSetForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser)8 AttributeRemovedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUser)7 User (cz.metacentrum.perun.core.api.User)7 AttributeChangedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser)5 AllAttributesRemovedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser)4 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)4 EnrichedSponsorship (cz.metacentrum.perun.core.api.EnrichedSponsorship)3 Facility (cz.metacentrum.perun.core.api.Facility)3 Member (cz.metacentrum.perun.core.api.Member)3 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 AttributeChangedForFacility (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForFacility)2 AttributeChangedForResourceAndMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForResourceAndMember)2