Examples of AbstractSchema


Examples of org.apache.syncope.core.persistence.beans.AbstractSchema

            final AttributableUtil attributableUtil, final SyncopeClientCompositeErrorException scce) {

        // 1. attributes
        SyncopeClientException invalidValues = new SyncopeClientException(SyncopeClientExceptionType.InvalidValues);

        AbstractSchema schema;
        AbstractAttr attribute;

        // Only consider attributeTO with values
        for (AttributeTO attributeTO : attributableTO.getAttributes()) {
            if (attributeTO.getValues() != null && !attributeTO.getValues().isEmpty()) {

                schema = getSchema(attributeTO.getSchema(), attributableUtil.schemaClass());

                if (schema != null) {
                    attribute = attributable.getAttribute(schema.getName());
                    if (attribute == null) {
                        attribute = attributableUtil.newAttr();
                        attribute.setSchema(schema);
                    }
View Full Code Here

Examples of org.apache.syncope.core.persistence.beans.AbstractSchema

        if (schemaDAO.find(schemaTO.getName(), attrUtil.schemaClass()) != null) {
            throw new EntityExistsException(attrUtil.schemaClass().getSimpleName()
                    + " '" + schemaTO.getName() + "'");
        }

        AbstractSchema schema = attrUtil.newSchema();
        binder.create(schemaTO, schema);
        schema = schemaDAO.save(schema);

        response.setStatus(HttpServletResponse.SC_CREATED);
        return binder.getSchemaTO(schema);
View Full Code Here

Examples of org.apache.syncope.core.persistence.beans.AbstractSchema

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

        Class<? extends AbstractSchema> reference = getAttributableUtil(kind).schemaClass();
        AbstractSchema schema = schemaDAO.find(schemaName, reference);
        if (schema == null) {
            throw new NotFoundException("Schema '" + schemaName + "'");
        }

        SchemaTO schemaToDelete = binder.getSchemaTO(schema);
View Full Code Here

Examples of org.apache.syncope.core.persistence.beans.AbstractSchema

    @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 + "'");
        }

        return binder.getSchemaTO(schema);
View Full Code Here

Examples of org.apache.syncope.core.persistence.beans.AbstractSchema

    @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() + "'");
        }

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

Examples of org.apache.syncope.core.persistence.beans.AbstractSchema

        switch (accountIdItem.getIntMappingType()) {
            case UserSchema:
            case RoleSchema:
                final AbstractAttrValue value = attrUtil.newAttrValue();

                AbstractSchema schema = schemaDAO.find(accountIdItem.getIntAttrName(), attrUtil.schemaClass());
                if (schema == null) {
                    value.setStringValue(uid);
                } else {
                    try {
                        value.parseValue(schema, uid);
View Full Code Here

Examples of org.apache.syncope.core.persistence.beans.AbstractSchema

        }

        List<AbstractAttrValue> values = getIntValues(
                resource, mapItem, attributables, vAttrsToBeRemoved, vAttrsToBeUpdated);

        AbstractSchema schema = null;
        boolean readOnlyVirSchema = false;
        AttributeSchemaType schemaType;

        switch (mapItem.getIntMappingType()) {
            case UserSchema:
            case RoleSchema:
            case MembershipSchema:
                SchemaDAO schemaDAO = context.getBean(SchemaDAO.class);
                schema = schemaDAO.find(mapItem.getIntAttrName(),
                        MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
                schemaType = schema == null ? AttributeSchemaType.String : schema.getType();
                break;

            case UserVirtualSchema:
            case RoleVirtualSchema:
            case MembershipVirtualSchema:
                VirSchemaDAO virSchemaDAO = context.getBean(VirSchemaDAO.class);
                AbstractVirSchema virSchema = virSchemaDAO.find(mapItem.getIntAttrName(),
                        MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
                readOnlyVirSchema = (virSchema != null && virSchema.isReadonly());
                schemaType = AttributeSchemaType.String;
                break;

            default:
                schemaType = AttributeSchemaType.String;
        }

        final String extAttrName = mapItem.getExtAttrName();

        LOG.debug("Define mapping for: "
                + "\n* ExtAttrName " + extAttrName
                + "\n* is accountId " + mapItem.isAccountid()
                + "\n* is password " + (mapItem.isPassword() || mapItem.getIntMappingType() == IntMappingType.Password)
                + "\n* mandatory condition " + mapItem.getMandatoryCondition()
                + "\n* Schema " + mapItem.getIntAttrName()
                + "\n* IntMappingType " + mapItem.getIntMappingType().toString()
                + "\n* ClassType " + schemaType.getType().getName()
                + "\n* Values " + values);

        List<Object> objValues = new ArrayList<Object>();

        for (AbstractAttrValue value : values) {
            if (FrameworkUtil.isSupportedAttributeType(schemaType.getType())) {
                objValues.add(value.getValue());
            } else {
                objValues.add(value.getValueAsString());
            }
        }

        Map.Entry<String, Attribute> result;
        if (readOnlyVirSchema) {
            result = null;
        } else if (mapItem.isAccountid()) {
            result = new AbstractMap.SimpleEntry<String, Attribute>(objValues.iterator().next().toString(), null);
        } else if (mapItem.isPassword() && subject instanceof SyncopeUser) {
            String passwordAttrValue = password;
            if (StringUtils.isBlank(passwordAttrValue)) {
                SyncopeUser user = (SyncopeUser) subject;
                if (user.canDecodePassword()) {
                    try {
                        passwordAttrValue = PasswordEncoder.decode(user.getPassword(), user.getCipherAlgorithm());
                    } catch (Exception e) {
                        LOG.error("Could not decode password for {}", user, e);
                    }
                } else if (resource.isRandomPwdIfNotProvided()) {
                    try {
                        passwordAttrValue = passwordGenerator.generate(user);
                    } catch (InvalidPasswordPolicySpecException e) {
                        LOG.error("Could not generate policy-compliant random password for {}", user, e);

                        passwordAttrValue = SecureRandomUtil.generateRandomPassword(16);
                    }
                }
            }

            if (passwordAttrValue == null) {
                result = null;
            } else {
                result = new AbstractMap.SimpleEntry<String, Attribute>(null,
                        AttributeBuilder.buildPassword(passwordAttrValue.toCharArray()));
            }
        } else {
            if ((schema != null && schema.isMultivalue()) || AttributableUtil.getInstance(subject).getType()
                    != mapItem.getIntMappingType().getAttributableType()) {
                result = new AbstractMap.SimpleEntry<String, Attribute>(null, AttributeBuilder.build(extAttrName,
                        objValues));
            } else {
                result = new AbstractMap.SimpleEntry<String, Attribute>(null, objValues.isEmpty()
View Full Code Here

Examples of org.apache.syncope.core.persistence.beans.AbstractSchema

        final Entry<AbstractSchema, List<AbstractAttrValue>> entry =
                SchemaMappingUtil.getIntValues(mapping, attributables, password, schemaDAO);

        final List<AbstractAttrValue> values = entry.getValue();
        final AbstractSchema schema = entry.getKey();
        final SchemaType schemaType = schema == null ? SchemaType.String : schema.getType();

        final String extAttrName = SchemaMappingUtil.getExtAttrName(mapping);

        LOG.debug("Define mapping for: "
                + "\n* ExtAttrName " + extAttrName
                + "\n* is accountId " + mapping.isAccountid()
                + "\n* is password " + (mapping.isPassword() || mapping.getIntMappingType().equals(
                IntMappingType.Password))
                + "\n* mandatory condition " + mapping.getMandatoryCondition()
                + "\n* Schema " + mapping.getIntAttrName()
                + "\n* IntMappingType " + mapping.getIntMappingType().toString()
                + "\n* ClassType " + schemaType.getClassName()
                + "\n* Values " + values);

        List<Object> objValues = new ArrayList<Object>();

        for (AbstractAttrValue value : values) {
            if (FrameworkUtil.isSupportedAttributeType(Class.forName(schemaType.getClassName()))) {
                objValues.add(value.getValue());
            } else {
                objValues.add(value.getValueAsString());
            }
        }

        Map.Entry<String, Attribute> res;

        if (mapping.isAccountid()) {
            res = new DefaultMapEntry(objValues.iterator().next().toString(), null);
        } else if (mapping.isPassword()) {
            res = new DefaultMapEntry(null,
                    AttributeBuilder.buildPassword(objValues.iterator().next().toString().toCharArray()));
        } else {
            if (schema != null && schema.isMultivalue()) {
                res = new DefaultMapEntry(null, AttributeBuilder.build(extAttrName, objValues));
            } else {
                res = new DefaultMapEntry(null, objValues.isEmpty()
                        ? AttributeBuilder.build(extAttrName)
                        : AttributeBuilder.build(extAttrName, objValues.iterator().next()));
View Full Code Here

Examples of org.apache.syncope.core.persistence.beans.AbstractSchema

    }

    private String getQuery(final AttributeCond cond, final boolean not, final List<Object> parameters,
            final AttributableUtil attrUtil) {

        AbstractSchema schema = schemaDAO.find(cond.getSchema(), attrUtil.schemaClass());
        if (schema == null) {
            LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
            return EMPTY_ATTR_QUERY;
        }

        AbstractAttrValue attrValue = attrUtil.newAttrValue();
        try {
            if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ISNULL
                    && cond.getType() != AttributeCond.Type.ISNOTNULL) {

                schema.getValidator().validate(cond.getExpression(), attrValue);
            }
        } catch (ValidationException e) {
            LOG.error("Could not validate expression '" + cond.getExpression() + "'", e);
            return EMPTY_ATTR_QUERY;
        }

        StringBuilder query = new StringBuilder("SELECT DISTINCT subject_id FROM ").append(attrUtil.searchView());
        if (cond.getType() == AttributeCond.Type.ISNOTNULL) {
            query.append(" WHERE subject_id NOT IN (SELECT subject_id FROM ").
                    append(attrUtil.searchView()).append("_null_attr WHERE schema_name='").
                    append(schema.getName()).append("')");
        } else {
            if (cond.getType() == AttributeCond.Type.ISNULL) {
                query.append("_null_attr WHERE schema_name='").append(schema.getName()).append("'");
            } else {
                if (schema.isUniqueConstraint()) {
                    query.append("_unique_attr ");
                } else {
                    query.append("_attr ");
                }
                query.append("WHERE schema_name='").append(schema.getName());

                fillAttributeQuery(query, attrValue, schema, cond, not, parameters);
            }
        }
View Full Code Here

Examples of org.apache.syncope.core.persistence.beans.AbstractSchema

        if (attributableField == null) {
            LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
            return EMPTY_ATTR_QUERY;
        }

        AbstractSchema schema = attrUtil.newSchema();
        schema.setName(attributableField.getName());
        for (AttributeSchemaType type : AttributeSchemaType.values()) {
            if (attributableField.getType().isAssignableFrom(type.getType())) {
                schema.setType(type);
            }
        }

        // Deal with Attributable Integer fields logically mapping to boolean values
        // (SyncopeRole.inheritAttributes, for example)
        boolean foundBooleanMin = false;
        boolean foundBooleanMax = false;
        if (Integer.class.equals(attributableField.getType())) {
            for (Annotation annotation : attributableField.getAnnotations()) {
                if (Min.class.equals(annotation.annotationType())) {
                    foundBooleanMin = ((Min) annotation).value() == 0;
                } else if (Max.class.equals(annotation.annotationType())) {
                    foundBooleanMax = ((Max) annotation).value() == 1;
                }
            }
        }
        if (foundBooleanMin && foundBooleanMax) {
            if ("true".equalsIgnoreCase(cond.getExpression())) {
                cond.setExpression("1");
                schema.setType(AttributeSchemaType.Long);
            } else if ("false".equalsIgnoreCase(cond.getExpression())) {
                cond.setExpression("0");
                schema.setType(AttributeSchemaType.Long);
            }
        }

        // Deal with Attributable fields representing relationships to other entities
        // Only _id and _name are suppored
        if (attributableField.getType().getAnnotation(Entity.class) != null) {
            if (BeanUtils.findDeclaredMethodWithMinimalParameters(attributableField.getType(), "getId") != null) {
                cond.setSchema(cond.getSchema() + "_id");
                schema.setType(AttributeSchemaType.Long);
            }
            if (BeanUtils.findDeclaredMethodWithMinimalParameters(attributableField.getType(), "getName") != null) {
                cond.setSchema(cond.getSchema() + "_name");
                schema.setType(AttributeSchemaType.String);
            }
        }

        AbstractAttrValue attrValue = attrUtil.newAttrValue();
        try {
            if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ISNULL
                    && cond.getType() != AttributeCond.Type.ISNOTNULL) {

                schema.getValidator().validate(cond.getExpression(), attrValue);
            }
        } catch (ValidationException e) {
            LOG.error("Could not validate expression '" + cond.getExpression() + "'", e);
            return EMPTY_ATTR_QUERY;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.