Search in sources :

Example 1 with AnyTypeKind

use of org.apache.syncope.common.lib.types.AnyTypeKind in project syncope by apache.

the class SchemaDataBinderImpl method update.

@Override
public PlainSchema update(final PlainSchemaTO schemaTO, final PlainSchema schema) {
    SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
    boolean hasAttrs = false;
    for (AnyTypeKind anyTypeKind : AnyTypeKind.values()) {
        AnyUtils anyUtils = anyUtilsFactory.getInstance(anyTypeKind);
        hasAttrs |= plainSchemaDAO.findAttrs(schema, anyUtils.plainAttrClass()).isEmpty();
    }
    if (hasAttrs) {
        if (schema.getType() != schemaTO.getType()) {
            SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidPlainSchema);
            e.getElements().add("Cannot change type since " + schema.getKey() + " has attributes");
            scce.addException(e);
        }
        if (schema.isUniqueConstraint() != schemaTO.isUniqueConstraint()) {
            SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidPlainSchema);
            e.getElements().add("Cannot alter unique contraint since " + schema.getKey() + " has attributes");
            scce.addException(e);
        }
    }
    if (scce.hasExceptions()) {
        throw scce;
    }
    return fill(schema, schemaTO);
}
Also used : SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils)

Example 2 with AnyTypeKind

use of org.apache.syncope.common.lib.types.AnyTypeKind in project syncope by apache.

the class SchemaRestClient method getSchemas.

public <T extends SchemaTO> List<T> getSchemas(final SchemaType schemaType, final AnyTypeKind kind) {
    final AnyTypeService client = getService(AnyTypeService.class);
    final List<String> classes = new ArrayList<>();
    switch(kind) {
        case USER:
        case GROUP:
            final AnyTypeTO type = client.read(kind.name());
            if (type != null) {
                classes.addAll(type.getClasses());
            }
            break;
        default:
            new AnyTypeRestClient().listAnyTypes().stream().filter(anyTypeTO -> (anyTypeTO.getKind() != AnyTypeKind.USER && anyTypeTO.getKind() != AnyTypeKind.GROUP)).forEach((anyTypeTO) -> {
                classes.addAll(anyTypeTO.getClasses());
            });
    }
    return getSchemas(schemaType, null, classes.toArray(new String[] {}));
}
Also used : AnyTypeService(org.apache.syncope.common.rest.api.service.AnyTypeService) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SchemaService(org.apache.syncope.common.rest.api.service.SchemaService) SchemaType(org.apache.syncope.common.lib.types.SchemaType) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) ArrayList(java.util.ArrayList) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) List(java.util.List) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) EntityTO(org.apache.syncope.common.lib.to.EntityTO) SchemaTO(org.apache.syncope.common.lib.to.SchemaTO) SchemaQuery(org.apache.syncope.common.rest.api.beans.SchemaQuery) Collections(java.util.Collections) AnyTypeService(org.apache.syncope.common.rest.api.service.AnyTypeService) ArrayList(java.util.ArrayList) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO)

Example 3 with AnyTypeKind

use of org.apache.syncope.common.lib.types.AnyTypeKind 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 AnyTypeKind

use of org.apache.syncope.common.lib.types.AnyTypeKind in project syncope by apache.

the class ProvisionProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    String key = exchange.getIn().getBody(String.class);
    List<String> resources = exchange.getProperty("resources", List.class);
    Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
    if (getAnyTypeKind() == AnyTypeKind.USER) {
        Boolean changePwd = exchange.getProperty("changePwd", Boolean.class);
        String password = exchange.getProperty("password", String.class);
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(key);
        userPatch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build()).collect(Collectors.toList()));
        if (changePwd) {
            userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).value(password).resources(resources).build());
        }
        PropagationByResource propByRes = new PropagationByResource();
        propByRes.addAll(ResourceOperation.UPDATE, resources);
        WorkflowResult<Pair<UserPatch, Boolean>> wfResult = new WorkflowResult<>(ImmutablePair.of(userPatch, (Boolean) null), propByRes, "update");
        List<PropagationTaskTO> tasks = getPropagationManager().getUserUpdateTasks(wfResult, changePwd, null);
        PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
        exchange.getOut().setBody(propagationReporter.getStatuses());
    } else {
        PropagationByResource propByRes = new PropagationByResource();
        propByRes.addAll(ResourceOperation.UPDATE, resources);
        AnyTypeKind anyTypeKind = AnyTypeKind.GROUP;
        if (getAnyTypeKind() != null) {
            anyTypeKind = getAnyTypeKind();
        }
        List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(anyTypeKind, key, false, null, propByRes, null, null);
        PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
        exchange.getOut().setBody(propagationReporter.getStatuses());
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with AnyTypeKind

use of org.apache.syncope.common.lib.types.AnyTypeKind in project syncope by apache.

the class JPAPlainSchemaDAO method delete.

@Override
public void delete(final String key) {
    PlainSchema schema = find(key);
    if (schema == null) {
        return;
    }
    AnyUtilsFactory anyUtilsFactory = new JPAAnyUtilsFactory();
    for (AnyTypeKind anyTypeKind : AnyTypeKind.values()) {
        AnyUtils anyUtils = anyUtilsFactory.getInstance(anyTypeKind);
        for (PlainAttr<?> attr : findAttrs(schema, anyUtils.plainAttrClass())) {
            plainAttrDAO.delete(attr.getKey(), anyUtils.plainAttrClass());
        }
        resourceDAO().deleteMapping(key);
    }
    if (schema.getAnyTypeClass() != null) {
        schema.getAnyTypeClass().getPlainSchemas().remove(schema);
    }
    entityManager().remove(schema);
}
Also used : AnyUtilsFactory(org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) JPAPlainSchema(org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils)

Aggregations

AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)5 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3 ArrayList (java.util.ArrayList)2 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)2 Method (java.lang.reflect.Method)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)1 EventCategoryTO (org.apache.syncope.common.lib.log.EventCategoryTO)1 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)1 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)1 AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)1 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)1 EntityTO (org.apache.syncope.common.lib.to.EntityTO)1 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)1