Search in sources :

Example 21 with AuditEvent

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

Example 22 with AuditEvent

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

the class ExpirationNotifSchedulerTest method testSponsorshipExpirationIsAuditedInDays.

/**
 * Performs test of sponsorship expiration being audited n days before its expiration.
 *
 * @param days number of days before the expiration
 */
private void testSponsorshipExpirationIsAuditedInDays(int days) throws Exception {
    LocalDate today = LocalDate.of(2020, 2, 2);
    when(spyScheduler.getCurrentLocalDate()).thenReturn(today);
    Member member = setUpMember();
    User sponsor = perun.getUsersManagerBl().getUserByMember(session, setUpMember());
    AuthzResolverBlImpl.setRole(session, sponsor, vo, Role.SPONSOR);
    LocalDate nextDay = today.plusDays(days);
    perun.getMembersManagerBl().setSponsorshipForMember(session, member, sponsor, nextDay);
    ReflectionTestUtils.invokeMethod(spyScheduler, "auditSponsorshipExpirations");
    EnrichedSponsorship es = new EnrichedSponsorship();
    es.setSponsoredMember(perun.getMembersManagerBl().getMemberById(session, member.getId()));
    es.setSponsor(perun.getUsersManagerBl().getUserById(session, sponsor.getId()));
    AuditEvent expectedEvent = new SponsorshipExpirationInDays(es, days);
    verify(auditerMock).log(any(), eq(expectedEvent));
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) EnrichedSponsorship(cz.metacentrum.perun.core.api.EnrichedSponsorship) SponsorshipExpirationInDays(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpirationInDays) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) LocalDate(java.time.LocalDate) Member(cz.metacentrum.perun.core.api.Member)

Example 23 with AuditEvent

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

the class EventServiceResolverTest method parseEventTest.

@Test
public void parseEventTest() throws ServiceNotExistsException, InvalidEventMessageException, PrivilegeException {
    System.out.println("EventServiceResolver.parseEventTest()");
    AuditEvent auditEvent = new DirectMemberAddedToGroup(member1, group1);
    Event event = new Event();
    event.setTimeStamp(System.currentTimeMillis());
    event.setHeader("portishead");
    event.setData(auditEvent);
    Map<Facility, Set<Service>> resolvedServices = eventServiceResolver.resolveEvent(event.getData());
    Assert.assertTrue("We should resolved only one facility-service", resolvedServices.size() == 1);
    Set<Service> resolved = resolvedServices.get(facility1);
    Assert.assertTrue("We should have 2 service", resolved.size() == 2);
    Assert.assertTrue("Our Service 1 is missing", resolved.contains(service1));
    Assert.assertTrue("Our Service 2 is missing", resolved.contains(service2));
}
Also used : DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) Set(java.util.Set) Event(cz.metacentrum.perun.dispatcher.model.Event) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) Service(cz.metacentrum.perun.core.api.Service) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) Facility(cz.metacentrum.perun.core.api.Facility) AbstractDispatcherTest(cz.metacentrum.perun.dispatcher.AbstractDispatcherTest) Test(org.junit.Test)

Example 24 with AuditEvent

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

the class AuditerListener method run.

// ----- methods -------------------------------------
@Override
public void run() {
    boolean whichOfTwoRules = false;
    try {
        try {
            if (sess == null) {
                sess = perun.getPerunSession(new PerunPrincipal(dispatcherProperties.getProperty("perun.principal.name"), dispatcherProperties.getProperty("perun.principal.extSourceName"), dispatcherProperties.getProperty("perun.principal.extSourceType")), new PerunClient());
            }
        } catch (InternalErrorException e1) {
            log.error("Error establishing perun session in AuditerListener.", e1);
            // we can't continue without session
            stop();
        }
        while (!shouldStop()) {
            try {
                for (AuditEvent message : perun.getAuditMessagesManager().pollConsumerEvents(sess, "dispatcher")) {
                    // create event for each message
                    Event event = new Event();
                    event.setTimeStamp(System.currentTimeMillis());
                    if (whichOfTwoRules) {
                        event.setHeader("portishead");
                        whichOfTwoRules = false;
                    } else {
                        event.setHeader("clockworkorange");
                        whichOfTwoRules = true;
                    }
                    event.setData(message);
                    // pass event to queue for further processing
                    eventQueue.put(event);
                }
                Thread.sleep(1000);
            } catch (InternalErrorException | PrivilegeException ex) {
                log.error("AuditerListener couldn't get AuditEvents.", ex);
                Thread.sleep(1000);
            }
        }
        log.debug("AuditerListener has stopped.");
    } catch (InterruptedException e) {
        log.error("Error in AuditerListener: {}" + e);
        throw new RuntimeException("Somebody has interrupted us...", e);
    }
}
Also used : PerunClient(cz.metacentrum.perun.core.api.PerunClient) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) Event(cz.metacentrum.perun.dispatcher.model.Event) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 25 with AuditEvent

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

the class urn_perun_member_resource_attribute_def_virt_isBanned method resolveBanChangedForResource.

private List<AuditEvent> resolveBanChangedForResource(PerunSessionImpl perunSession, int memberId, int resourceId) throws AttributeNotExistsException {
    List<AuditEvent> resolvingMessages = new ArrayList<>();
    try {
        Member member = perunSession.getPerunBl().getMembersManagerBl().getMemberById(perunSession, memberId);
        Resource resource = perunSession.getPerunBl().getResourcesManagerBl().getResourceById(perunSession, resourceId);
        AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, A_MR_V_isBanned);
        resolvingMessages.add(new AttributeChangedForResourceAndMember(new Attribute(attributeDefinition), resource, member));
    } catch (MemberNotExistsException | ResourceNotExistsException e) {
        log.error("Can't resolve virtual attribute value change for " + this.getClass().getSimpleName() + " module because of exception.", e);
    }
    return resolvingMessages;
}
Also used : AttributeChangedForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForResourceAndMember) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) BanSetForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource) BanUpdatedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanUpdatedForResource) BanRemovedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanRemovedForResource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) AttributeChangedForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForResourceAndMember) Member(cz.metacentrum.perun.core.api.Member)

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