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;
}
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));
}
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));
}
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);
}
}
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;
}
Aggregations