Search in sources :

Example 1 with EventCategoryTO

use of org.apache.syncope.common.lib.log.EventCategoryTO in project syncope by apache.

the class LoggerITCase method listAuditEvents.

@Test
public void listAuditEvents() {
    final List<EventCategoryTO> events = loggerService.events();
    boolean found = false;
    for (EventCategoryTO eventCategoryTO : events) {
        if (UserLogic.class.getSimpleName().equals(eventCategoryTO.getCategory())) {
            assertEquals(EventCategoryType.LOGIC, eventCategoryTO.getType());
            assertTrue(eventCategoryTO.getEvents().contains("create"));
            assertTrue(eventCategoryTO.getEvents().contains("search"));
            assertFalse(eventCategoryTO.getEvents().contains("doCreate"));
            assertFalse(eventCategoryTO.getEvents().contains("setStatusOnWfAdapter"));
            assertFalse(eventCategoryTO.getEvents().contains("resolveReference"));
            found = true;
        }
    }
    assertTrue(found);
    found = false;
    for (EventCategoryTO eventCategoryTO : events) {
        if (GroupLogic.class.getSimpleName().equals(eventCategoryTO.getCategory())) {
            assertEquals(EventCategoryType.LOGIC, eventCategoryTO.getType());
            assertTrue(eventCategoryTO.getEvents().contains("create"));
            assertTrue(eventCategoryTO.getEvents().contains("search"));
            assertFalse(eventCategoryTO.getEvents().contains("resolveReference"));
            found = true;
        }
    }
    assertTrue(found);
    found = false;
    for (EventCategoryTO eventCategoryTO : events) {
        if (ResourceLogic.class.getSimpleName().equals(eventCategoryTO.getCategory())) {
            assertEquals(EventCategoryType.LOGIC, eventCategoryTO.getType());
            assertTrue(eventCategoryTO.getEvents().contains("create"));
            assertTrue(eventCategoryTO.getEvents().contains("read"));
            assertTrue(eventCategoryTO.getEvents().contains("delete"));
            assertFalse(eventCategoryTO.getEvents().contains("resolveReference"));
            found = true;
        }
    }
    assertTrue(found);
    found = false;
    for (EventCategoryTO eventCategoryTO : events) {
        if (AnyTypeKind.USER.name().toLowerCase().equals(eventCategoryTO.getCategory())) {
            if (RESOURCE_NAME_LDAP.equals(eventCategoryTO.getSubcategory()) && EventCategoryType.PULL == eventCategoryTO.getType()) {
                assertTrue(eventCategoryTO.getEvents().contains(ResourceOperation.DELETE.name().toLowerCase()));
                found = true;
            }
        }
    }
    assertTrue(found);
    found = false;
    for (EventCategoryTO eventCategoryTO : events) {
        if (AnyTypeKind.USER.name().toLowerCase().equals(eventCategoryTO.getCategory())) {
            if (RESOURCE_NAME_CSV.equals(eventCategoryTO.getSubcategory()) && EventCategoryType.PROPAGATION == eventCategoryTO.getType()) {
                assertTrue(eventCategoryTO.getEvents().contains(ResourceOperation.CREATE.name().toLowerCase()));
                assertTrue(eventCategoryTO.getEvents().contains(ResourceOperation.UPDATE.name().toLowerCase()));
                assertTrue(eventCategoryTO.getEvents().contains(ResourceOperation.DELETE.name().toLowerCase()));
                found = true;
            }
        }
    }
    assertTrue(found);
    found = false;
    for (EventCategoryTO eventCategoryTO : events) {
        if (EventCategoryType.TASK == eventCategoryTO.getType() && "PullJobDelegate".equals(eventCategoryTO.getCategory())) {
            found = true;
        }
    }
    assertTrue(found);
}
Also used : UserLogic(org.apache.syncope.core.logic.UserLogic) ResourceLogic(org.apache.syncope.core.logic.ResourceLogic) GroupLogic(org.apache.syncope.core.logic.GroupLogic) EventCategoryTO(org.apache.syncope.common.lib.log.EventCategoryTO) Test(org.junit.jupiter.api.Test)

Example 2 with EventCategoryTO

use of org.apache.syncope.common.lib.log.EventCategoryTO in project syncope by apache.

the class AuditLoggerName method parseEventCategory.

public static Pair<EventCategoryTO, Result> parseEventCategory(final String event) {
    EventCategoryTO eventCategoryTO = new EventCategoryTO();
    Result condition = null;
    if (StringUtils.isNotEmpty(event)) {
        final String[] elements = event.substring(1, event.length() - 1).split("\\]:\\[");
        if (elements.length == 1) {
            eventCategoryTO.setType(EventCategoryType.CUSTOM);
            condition = Result.SUCCESS;
            eventCategoryTO.getEvents().add(event);
        } else {
            EventCategoryType type;
            if (EventCategoryType.PROPAGATION.toString().equals(elements[0])) {
                type = EventCategoryType.PROPAGATION;
            } else if (EventCategoryType.PULL.toString().equals(elements[0])) {
                type = EventCategoryType.PULL;
            } else if (EventCategoryType.PUSH.toString().equals(elements[0])) {
                type = EventCategoryType.PUSH;
            } else {
                try {
                    type = EventCategoryType.valueOf(elements[0]);
                } catch (Exception e) {
                    type = EventCategoryType.CUSTOM;
                }
            }
            eventCategoryTO.setType(type);
            eventCategoryTO.setCategory(StringUtils.isNotEmpty(elements[1]) ? elements[1] : null);
            eventCategoryTO.setSubcategory(StringUtils.isNotEmpty(elements[2]) ? elements[2] : null);
            if (elements.length > 3 && StringUtils.isNotEmpty(elements[3])) {
                eventCategoryTO.getEvents().add(elements[3]);
            }
            if (elements.length > 4) {
                condition = Result.valueOf(elements[4].toUpperCase());
            }
        }
    }
    return Pair.of(eventCategoryTO, condition);
}
Also used : EventCategoryType(org.apache.syncope.common.lib.types.AuditElements.EventCategoryType) EventCategoryTO(org.apache.syncope.common.lib.log.EventCategoryTO) ParseException(java.text.ParseException) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

Example 3 with EventCategoryTO

use of org.apache.syncope.common.lib.log.EventCategoryTO in project syncope by apache.

the class LoggerLogic method listAuditEvents.

@PreAuthorize("hasRole('" + StandardEntitlement.AUDIT_LIST + "') or hasRole('" + StandardEntitlement.NOTIFICATION_LIST + "')")
public List<EventCategoryTO> listAuditEvents() {
    // use set to avoid duplications or null elements
    Set<EventCategoryTO> events = new HashSet<>();
    try {
        ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
        MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
        String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(SystemPropertyUtils.resolvePlaceholders(this.getClass().getPackage().getName())) + "/**/*.class";
        Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
        for (Resource resource : resources) {
            if (resource.isReadable()) {
                final MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                final Class<?> clazz = Class.forName(metadataReader.getClassMetadata().getClassName());
                if (clazz.isAnnotationPresent(Component.class) && AbstractLogic.class.isAssignableFrom(clazz)) {
                    EventCategoryTO eventCategoryTO = new EventCategoryTO();
                    eventCategoryTO.setCategory(clazz.getSimpleName());
                    for (Method method : clazz.getDeclaredMethods()) {
                        if (Modifier.isPublic(method.getModifiers()) && !eventCategoryTO.getEvents().contains(method.getName())) {
                            eventCategoryTO.getEvents().add(method.getName());
                        }
                    }
                    events.add(eventCategoryTO);
                }
            }
        }
        // SYNCOPE-608
        EventCategoryTO authenticationControllerEvents = new EventCategoryTO();
        authenticationControllerEvents.setCategory(AuditElements.AUTHENTICATION_CATEGORY);
        authenticationControllerEvents.getEvents().add(AuditElements.LOGIN_EVENT);
        events.add(authenticationControllerEvents);
        events.add(new EventCategoryTO(EventCategoryType.PROPAGATION));
        events.add(new EventCategoryTO(EventCategoryType.PULL));
        events.add(new EventCategoryTO(EventCategoryType.PUSH));
        for (AnyTypeKind anyTypeKind : AnyTypeKind.values()) {
            resourceDAO.findAll().forEach(resource -> {
                EventCategoryTO propEventCategoryTO = new EventCategoryTO(EventCategoryType.PROPAGATION);
                EventCategoryTO pullEventCategoryTO = new EventCategoryTO(EventCategoryType.PULL);
                EventCategoryTO pushEventCategoryTO = new EventCategoryTO(EventCategoryType.PUSH);
                propEventCategoryTO.setCategory(anyTypeKind.name().toLowerCase());
                propEventCategoryTO.setSubcategory(resource.getKey());
                pullEventCategoryTO.setCategory(anyTypeKind.name().toLowerCase());
                pushEventCategoryTO.setCategory(anyTypeKind.name().toLowerCase());
                pullEventCategoryTO.setSubcategory(resource.getKey());
                pushEventCategoryTO.setSubcategory(resource.getKey());
                for (ResourceOperation resourceOperation : ResourceOperation.values()) {
                    propEventCategoryTO.getEvents().add(resourceOperation.name().toLowerCase());
                }
                pullEventCategoryTO.getEvents().add(ResourceOperation.DELETE.name().toLowerCase());
                for (UnmatchingRule unmatching : UnmatchingRule.values()) {
                    String event = UnmatchingRule.toEventName(unmatching);
                    pullEventCategoryTO.getEvents().add(event);
                    pushEventCategoryTO.getEvents().add(event);
                }
                for (MatchingRule matching : MatchingRule.values()) {
                    String event = MatchingRule.toEventName(matching);
                    pullEventCategoryTO.getEvents().add(event);
                    pushEventCategoryTO.getEvents().add(event);
                }
                events.add(propEventCategoryTO);
                events.add(pullEventCategoryTO);
                events.add(pushEventCategoryTO);
            });
        }
        EventCategoryTO eventCategoryTO = new EventCategoryTO(EventCategoryType.TASK);
        eventCategoryTO.setCategory(PullJobDelegate.class.getSimpleName());
        events.add(eventCategoryTO);
        eventCategoryTO = new EventCategoryTO(EventCategoryType.TASK);
        eventCategoryTO.setCategory(PushJobDelegate.class.getSimpleName());
        events.add(eventCategoryTO);
    } catch (Exception e) {
        LOG.error("Failure retrieving audit/notification events", e);
    }
    return new ArrayList<>(events);
}
Also used : PullJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) PushJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) MetadataReader(org.springframework.core.type.classreading.MetadataReader) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) Method(java.lang.reflect.Method) EventCategoryTO(org.apache.syncope.common.lib.log.EventCategoryTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) UnmatchingRule(org.apache.syncope.common.lib.types.UnmatchingRule) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Component(org.springframework.stereotype.Component) MatchingRule(org.apache.syncope.common.lib.types.MatchingRule) HashSet(java.util.HashSet) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with EventCategoryTO

use of org.apache.syncope.common.lib.log.EventCategoryTO in project syncope by apache.

the class LoggerITCase method issueSYNCOPE976.

@Test
public void issueSYNCOPE976() {
    List<EventCategoryTO> events = loggerService.events();
    assertNotNull(events);
    EventCategoryTO userLogic = events.stream().filter(object -> "UserLogic".equals(object.getCategory())).findAny().get();
    assertNotNull(userLogic);
    assertEquals(1, userLogic.getEvents().stream().filter(event -> "create".equals(event)).count());
}
Also used : EventCategoryTO(org.apache.syncope.common.lib.log.EventCategoryTO) Test(org.junit.jupiter.api.Test)

Aggregations

EventCategoryTO (org.apache.syncope.common.lib.log.EventCategoryTO)4 Test (org.junit.jupiter.api.Test)2 Method (java.lang.reflect.Method)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)1 EventCategoryType (org.apache.syncope.common.lib.types.AuditElements.EventCategoryType)1 Result (org.apache.syncope.common.lib.types.AuditElements.Result)1 MatchingRule (org.apache.syncope.common.lib.types.MatchingRule)1 ResourceOperation (org.apache.syncope.common.lib.types.ResourceOperation)1 UnmatchingRule (org.apache.syncope.common.lib.types.UnmatchingRule)1 GroupLogic (org.apache.syncope.core.logic.GroupLogic)1 ResourceLogic (org.apache.syncope.core.logic.ResourceLogic)1 UserLogic (org.apache.syncope.core.logic.UserLogic)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 PullJobDelegate (org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate)1 PushJobDelegate (org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate)1 Resource (org.springframework.core.io.Resource)1