Package org.apache.syncope.core.util

Examples of org.apache.syncope.core.util.AttributableUtil


     * Logger.
     */
    protected static final Logger LOG = LoggerFactory.getLogger(AbstractController.class);

    protected AttributableUtil getAttributableUtil(final String kind) {
        AttributableUtil result = null;

        try {
            result = AttributableUtil.valueOf(kind.toUpperCase());
        } catch (Exception e) {
            LOG.error("Attributable not supported: " + kind);
View Full Code Here


        return schemaToDelete;
    }

    @RequestMapping(method = RequestMethod.GET, value = "/{kind}/list")
    public List<SchemaTO> list(@PathVariable("kind") final String kind) {
        AttributableUtil attributableUtil = getAttributableUtil(kind);
        List<AbstractSchema> schemas = schemaDAO.findAll(attributableUtil.schemaClass());

        List<SchemaTO> schemaTOs = new ArrayList<SchemaTO>(schemas.size());
        for (AbstractSchema schema : schemas) {
            schemaTOs.add(schemaDataBinder.getSchemaTO(schema, attributableUtil));
        }
View Full Code Here

    @PreAuthorize("hasRole('SCHEMA_READ')")
    @RequestMapping(method = RequestMethod.GET, value = "/{kind}/read/{schema}")
    public SchemaTO read(@PathVariable("kind") final String kind, @PathVariable("schema") final String schemaName)
            throws NotFoundException {

        AttributableUtil attributableUtil = getAttributableUtil(kind);
        AbstractSchema schema = schemaDAO.find(schemaName, attributableUtil.schemaClass());
        if (schema == null) {
            throw new NotFoundException("Schema '" + schemaName + "'");
        }

        auditManager.audit(Category.schema, SchemaSubCategory.read, Result.success,
View Full Code Here

    @PreAuthorize("hasRole('SCHEMA_UPDATE')")
    @RequestMapping(method = RequestMethod.POST, value = "/{kind}/update")
    public SchemaTO update(@RequestBody final SchemaTO schemaTO, @PathVariable("kind") final String kind)
            throws NotFoundException {

        AttributableUtil attributableUtil = getAttributableUtil(kind);
        AbstractSchema schema = schemaDAO.find(schemaTO.getName(), attributableUtil.schemaClass());
        if (schema == null) {
            throw new NotFoundException("Schema '" + schemaTO.getName() + "'");
        }

        schemaDataBinder.update(schemaTO, schema, attributableUtil);
View Full Code Here

            final String name,
            final ExternalResource resource,
            final Connector connector) {
        Long result = null;

        final AttributableUtil attrUtil = AttributableUtil.getInstance(oclass);

        final List<ConnectorObject> found = connector.search(oclass,
                new EqualsFilter(new Name(name)), connector.getOperationOptions(
                        attrUtil.getMappingItems(resource, MappingPurpose.SYNCHRONIZATION)));

        if (found.isEmpty()) {
            LOG.debug("No {} found on {} with __NAME__ {}", oclass, resource, name);
        } else {
            if (found.size() > 1) {
                LOG.warn("More than one {} found on {} with __NAME__ {} - taking first only", oclass, resource, name);
            }

            ConnectorObject connObj = found.iterator().next();
            final List<Long> subjectIds = findExisting(connObj.getUid().getUidValue(), connObj, resource, attrUtil);
            if (subjectIds.isEmpty()) {
                LOG.debug("No matching {} found for {}, aborting", attrUtil.getType(), connObj);
            } else {
                if (subjectIds.size() > 1) {
                    LOG.warn("More than one {} found {} - taking first only", attrUtil.getType(), subjectIds);
                }

                result = subjectIds.iterator().next();
            }
        }
View Full Code Here

            final Set<String> membVAttrsToBeRemoved, final Map<String, AttributeMod> membVAttrsToBeUpdatedMap,
            final Boolean enable, final boolean deleteOnResource, final PropagationByResource propByRes) {

        LOG.debug("Provisioning subject {}:\n{}", subject, propByRes);

        final AttributableUtil attrUtil = AttributableUtil.getInstance(subject);

        if (!propByRes.get(ResourceOperation.CREATE).isEmpty()
                && vAttrsToBeRemoved != null && vAttrsToBeUpdated != null) {

            connObjectUtil.retrieveVirAttrValues(subject, attrUtil);

            // update vAttrsToBeUpdated as well
            for (AbstractVirAttr virAttr : subject.getVirAttrs()) {
                final String schema = virAttr.getSchema().getName();

                final AttributeMod attributeMod = new AttributeMod();
                attributeMod.setSchema(schema);
                attributeMod.getValuesToBeAdded().addAll(virAttr.getValues());

                vAttrsToBeUpdated.put(schema, attributeMod);
            }
        }

        // Avoid duplicates - see javadoc
        propByRes.purge();
        LOG.debug("After purge: {}", propByRes);

        final List<PropagationTask> tasks = new ArrayList<PropagationTask>();

        for (ResourceOperation operation : ResourceOperation.values()) {
            for (String resourceName : propByRes.get(operation)) {
                final ExternalResource resource = resourceDAO.find(resourceName);
                if (resource == null) {
                    LOG.error("Invalid resource name specified: {}, ignoring...", resourceName);
                } else if (attrUtil.getMappingItems(resource, MappingPurpose.PROPAGATION).isEmpty()) {
                    LOG.warn("Requesting propagation for {} but no propagation mapping provided for {}",
                            attrUtil.getType(), resource);
                } else {
                    PropagationTask task = new PropagationTask();
                    task.setResource(resource);
                    task.setObjectClassName(connObjectUtil.fromAttributable(subject).getObjectClassValue());
                    task.setSubjectType(attrUtil.getType());
                    if (!deleteOnResource) {
                        task.setSubjectId(subject.getId());
                    }
                    task.setPropagationOperation(operation);
                    task.setPropagationMode(resource.getPropagationMode());
                    task.setOldAccountId(propByRes.getOldAccountId(resource.getName()));

                    Map.Entry<String, Set<Attribute>> preparedAttrs = MappingUtil.prepareAttributes(attrUtil, subject,
                            password, changePwd, vAttrsToBeRemoved, vAttrsToBeUpdated, membVAttrsToBeRemoved,
                            membVAttrsToBeUpdatedMap, enable, resource);
                    task.setAccountId(preparedAttrs.getKey());

                    // Check if any of mandatory attributes (in the mapping) is missing or not received any value:
                    // if so, add special attributes that will be evaluated by PropagationTaskExecutor
                    List<String> mandatoryMissing = new ArrayList<String>();
                    List<String> mandatoryNullOrEmpty = new ArrayList<String>();
                    for (AbstractMappingItem item : attrUtil.getMappingItems(resource, MappingPurpose.PROPAGATION)) {
                        if (!item.isAccountid()
                                && JexlUtil.evaluateMandatoryCondition(item.getMandatoryCondition(), subject)) {

                            Attribute attr = AttributeUtil.find(item.getExtAttrName(), preparedAttrs.getValue());
                            if (attr == null) {
View Full Code Here

            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
            sce.getElements().add("Schema name");
            throw sce;
        }

        final AttributableUtil attrUtil = AttributableUtil.getInstance(attrType);

        if (doesSchemaExist(schemaType, schemaTO.getName(), attrUtil)) {
            throw new EntityExistsException(schemaType + "/" + attrType + "/" + schemaTO.getName());
        }

        T created;
        switch (schemaType) {
            case VIRTUAL:
                AbstractVirSchema virSchema = attrUtil.newVirSchema();
                binder.create((VirSchemaTO) schemaTO, virSchema);
                virSchema = virSchemaDAO.save(virSchema);
                created = (T) binder.getVirSchemaTO(virSchema);
                break;
            case DERIVED:
                AbstractDerSchema derSchema = attrUtil.newDerSchema();
                binder.create((DerSchemaTO) schemaTO, derSchema);
                derSchema = derSchemaDAO.save(derSchema);

                created = (T) binder.getDerSchemaTO(derSchema);
                break;

            case NORMAL:
            default:
                AbstractNormalSchema normalSchema = attrUtil.newSchema();
                binder.create((SchemaTO) schemaTO, normalSchema);
                normalSchema = schemaDAO.save(normalSchema);

                created = (T) binder.getSchemaTO(normalSchema, attrUtil);
        }
View Full Code Here

        return created;
    }

    @PreAuthorize("hasRole('SCHEMA_DELETE')")
    public void delete(final AttributableType attrType, final SchemaType schemaType, final String schemaName) {
        final AttributableUtil attrUtil = AttributableUtil.getInstance(attrType);

        if (!doesSchemaExist(schemaType, schemaName, attrUtil)) {
            throw new NotFoundException(schemaType + "/" + attrType + "/" + schemaName);
        }
View Full Code Here

    }

    @PreAuthorize("isAuthenticated()")
    @SuppressWarnings("unchecked")
    public <T extends AbstractSchemaTO> List<T> list(final AttributableType attrType, final SchemaType schemaType) {
        final AttributableUtil attrUtil = AttributableUtil.getInstance(attrType);

        List<T> result;
        switch (schemaType) {
            case VIRTUAL:
                List<AbstractVirSchema> virSchemas = virSchemaDAO.findAll(attrUtil.virSchemaClass());
                result = (List<T>) new ArrayList<VirSchemaTO>(virSchemas.size());
                for (AbstractVirSchema derSchema : virSchemas) {
                    result.add((T) binder.getVirSchemaTO(derSchema));
                }
                break;

            case DERIVED:
                List<AbstractDerSchema> derSchemas = derSchemaDAO.findAll(attrUtil.derSchemaClass());
                result = (List<T>) new ArrayList<DerSchemaTO>(derSchemas.size());
                for (AbstractDerSchema derSchema : derSchemas) {
                    result.add((T) binder.getDerSchemaTO(derSchema));
                }
                break;

            case NORMAL:
            default:
                List<AbstractNormalSchema> schemas = schemaDAO.findAll(attrUtil.schemaClass());
                result = (List<T>) new ArrayList<SchemaTO>(schemas.size());
                for (AbstractNormalSchema schema : schemas) {
                    result.add((T) binder.getSchemaTO(schema, attrUtil));
                }
        }
View Full Code Here

    @PreAuthorize("hasRole('SCHEMA_READ')")
    @SuppressWarnings("unchecked")
    public <T extends AbstractSchemaTO> T read(
            final AttributableType attrType, final SchemaType schemaType, final String schemaName) {

        final AttributableUtil attrUtil = AttributableUtil.getInstance(attrType);

        T read;
        switch (schemaType) {
            case VIRTUAL:
                AbstractVirSchema virSchema = virSchemaDAO.find(schemaName, attrUtil.virSchemaClass());
                if (virSchema == null) {
                    throw new NotFoundException("Virtual Schema '" + schemaName + "'");
                }

                read = (T) binder.getVirSchemaTO(virSchema);
                break;

            case DERIVED:
                AbstractDerSchema derSchema = derSchemaDAO.find(schemaName, attrUtil.derSchemaClass());
                if (derSchema == null) {
                    throw new NotFoundException("Derived schema '" + schemaName + "'");
                }

                read = (T) binder.getDerSchemaTO(derSchema);
                break;

            case NORMAL:
            default:
                AbstractNormalSchema schema = schemaDAO.find(schemaName, attrUtil.schemaClass());
                if (schema == null) {
                    throw new NotFoundException("Schema '" + schemaName + "'");
                }

                read = (T) binder.getSchemaTO(schema, attrUtil);
View Full Code Here

TOP

Related Classes of org.apache.syncope.core.util.AttributableUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.