Search in sources :

Example 1 with AttrSchemaType

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

the class MappingManagerImpl method prepareAttr.

/**
 * Prepare an attribute to be sent to a connector instance.
 *
 * @param provision external resource
 * @param mapItem mapping item for the given attribute
 * @param any given any object
 * @param password clear-text password
 * @return connObjectKey + prepared attribute
 */
private Pair<String, Attribute> prepareAttr(final Provision provision, final Item mapItem, final Any<?> any, final String password) {
    IntAttrName intAttrName;
    try {
        intAttrName = intAttrNameParser.parse(mapItem.getIntAttrName(), provision.getAnyType().getKind());
    } catch (ParseException e) {
        LOG.error("Invalid intAttrName '{}' specified, ignoring", mapItem.getIntAttrName(), e);
        return null;
    }
    boolean readOnlyVirSchema = false;
    Schema schema = null;
    AttrSchemaType schemaType = AttrSchemaType.String;
    if (intAttrName.getSchemaType() != null) {
        switch(intAttrName.getSchemaType()) {
            case PLAIN:
                schema = plainSchemaDAO.find(intAttrName.getSchemaName());
                if (schema != null) {
                    schemaType = schema.getType();
                }
                break;
            case VIRTUAL:
                schema = virSchemaDAO.find(intAttrName.getSchemaName());
                readOnlyVirSchema = (schema != null && schema.isReadonly());
                break;
            default:
        }
    }
    List<PlainAttrValue> values = getIntValues(provision, mapItem, intAttrName, any);
    LOG.debug("Define mapping for: " + "\n* ExtAttrName " + mapItem.getExtAttrName() + "\n* is connObjectKey " + mapItem.isConnObjectKey() + "\n* is password " + mapItem.isPassword() + "\n* mandatory condition " + mapItem.getMandatoryCondition() + "\n* Schema " + intAttrName.getSchemaName() + "\n* ClassType " + schemaType.getType().getName() + "\n* Values " + values);
    Pair<String, Attribute> result;
    if (readOnlyVirSchema) {
        result = null;
    } else {
        List<Object> objValues = new ArrayList<>();
        for (PlainAttrValue value : values) {
            if (FrameworkUtil.isSupportedAttributeType(schemaType.getType())) {
                objValues.add(value.getValue());
            } else {
                objValues.add(value.getValueAsString(schemaType));
            }
        }
        if (mapItem.isConnObjectKey()) {
            result = Pair.of(objValues.isEmpty() ? null : objValues.iterator().next().toString(), null);
        } else if (mapItem.isPassword() && any instanceof User) {
            String passwordAttrValue = password;
            if (StringUtils.isBlank(passwordAttrValue)) {
                User user = (User) any;
                if (user.canDecodePassword()) {
                    try {
                        passwordAttrValue = ENCRYPTOR.decode(user.getPassword(), user.getCipherAlgorithm());
                    } catch (Exception e) {
                        LOG.error("Could not decode password for {}", user, e);
                    }
                } else if (provision.getResource().isRandomPwdIfNotProvided()) {
                    try {
                        passwordAttrValue = passwordGenerator.generate(provision.getResource());
                    } catch (InvalidPasswordRuleConf e) {
                        LOG.error("Could not generate policy-compliant random password for {}", user, e);
                    }
                }
            }
            if (passwordAttrValue == null) {
                result = null;
            } else {
                result = Pair.of(null, AttributeBuilder.buildPassword(passwordAttrValue.toCharArray()));
            }
        } else if (schema != null && schema.isMultivalue()) {
            result = Pair.of(null, AttributeBuilder.build(mapItem.getExtAttrName(), objValues));
        } else {
            result = Pair.of(null, objValues.isEmpty() ? AttributeBuilder.build(mapItem.getExtAttrName()) : AttributeBuilder.build(mapItem.getExtAttrName(), objValues.iterator().next()));
        }
    }
    return result;
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) Attribute(org.identityconnectors.framework.common.objects.Attribute) InvalidPasswordRuleConf(org.apache.syncope.core.provisioning.api.utils.policy.InvalidPasswordRuleConf) Schema(org.apache.syncope.core.persistence.api.entity.Schema) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) ParseException(java.text.ParseException)

Example 2 with AttrSchemaType

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

the class MappingManagerImpl method setIntValues.

@Transactional(readOnly = true)
@Override
public void setIntValues(final Item mapItem, final Attribute attr, final AnyTO anyTO, final AnyUtils anyUtils) {
    List<Object> values = null;
    if (attr != null) {
        values = attr.getValue();
        for (ItemTransformer transformer : MappingUtils.getItemTransformers(mapItem)) {
            values = transformer.beforePull(mapItem, anyTO, values);
        }
    }
    values = values == null ? Collections.emptyList() : values;
    IntAttrName intAttrName;
    try {
        intAttrName = intAttrNameParser.parse(mapItem.getIntAttrName(), anyUtils.getAnyTypeKind());
    } catch (ParseException e) {
        LOG.error("Invalid intAttrName '{}' specified, ignoring", mapItem.getIntAttrName(), e);
        return;
    }
    if (intAttrName.getField() != null) {
        switch(intAttrName.getField()) {
            case "password":
                if (anyTO instanceof UserTO && !values.isEmpty()) {
                    ((UserTO) anyTO).setPassword(ConnObjectUtils.getPassword(values.get(0)));
                }
                break;
            case "username":
                if (anyTO instanceof UserTO) {
                    ((UserTO) anyTO).setUsername(values.isEmpty() || values.get(0) == null ? null : values.get(0).toString());
                }
                break;
            case "name":
                if (anyTO instanceof GroupTO) {
                    ((GroupTO) anyTO).setName(values.isEmpty() || values.get(0) == null ? null : values.get(0).toString());
                } else if (anyTO instanceof AnyObjectTO) {
                    ((AnyObjectTO) anyTO).setName(values.isEmpty() || values.get(0) == null ? null : values.get(0).toString());
                }
                break;
            case "mustChangePassword":
                if (anyTO instanceof UserTO && !values.isEmpty() && values.get(0) != null) {
                    ((UserTO) anyTO).setMustChangePassword(BooleanUtils.toBoolean(values.get(0).toString()));
                }
                break;
            case "userOwner":
            case "groupOwner":
                if (anyTO instanceof GroupTO && attr != null) {
                    // using a special attribute (with schema "", that will be ignored) for carrying the
                    // GroupOwnerSchema value
                    AttrTO attrTO = new AttrTO();
                    attrTO.setSchema(StringUtils.EMPTY);
                    if (values.isEmpty() || values.get(0) == null) {
                        attrTO.getValues().add(StringUtils.EMPTY);
                    } else {
                        attrTO.getValues().add(values.get(0).toString());
                    }
                    ((GroupTO) anyTO).getPlainAttrs().add(attrTO);
                }
                break;
            default:
        }
    } else if (intAttrName.getSchemaType() != null) {
        GroupableRelatableTO groupableTO = null;
        Group group = null;
        if (anyTO instanceof GroupableRelatableTO && intAttrName.getMembershipOfGroup() != null) {
            groupableTO = (GroupableRelatableTO) anyTO;
            group = groupDAO.findByName(intAttrName.getMembershipOfGroup());
        }
        switch(intAttrName.getSchemaType()) {
            case PLAIN:
                AttrTO attrTO = new AttrTO();
                attrTO.setSchema(intAttrName.getSchemaName());
                PlainSchema schema = plainSchemaDAO.find(intAttrName.getSchemaName());
                for (Object value : values) {
                    AttrSchemaType schemaType = schema == null ? AttrSchemaType.String : schema.getType();
                    if (value != null) {
                        PlainAttrValue attrValue = anyUtils.newPlainAttrValue();
                        switch(schemaType) {
                            case String:
                                attrValue.setStringValue(value.toString());
                                break;
                            case Binary:
                                attrValue.setBinaryValue((byte[]) value);
                                break;
                            default:
                                try {
                                    attrValue.parseValue(schema, value.toString());
                                } catch (ParsingValidationException e) {
                                    LOG.error("While parsing provided value {}", value, e);
                                    attrValue.setStringValue(value.toString());
                                    schemaType = AttrSchemaType.String;
                                }
                                break;
                        }
                        attrTO.getValues().add(attrValue.getValueAsString(schemaType));
                    }
                }
                if (groupableTO == null || group == null) {
                    anyTO.getPlainAttrs().add(attrTO);
                } else {
                    Optional<MembershipTO> membership = groupableTO.getMembership(group.getKey());
                    if (!membership.isPresent()) {
                        membership = Optional.of(new MembershipTO.Builder().group(group.getKey(), group.getName()).build());
                        groupableTO.getMemberships().add(membership.get());
                    }
                    membership.get().getPlainAttrs().add(attrTO);
                }
                break;
            case DERIVED:
                attrTO = new AttrTO();
                attrTO.setSchema(intAttrName.getSchemaName());
                if (groupableTO == null || group == null) {
                    anyTO.getDerAttrs().add(attrTO);
                } else {
                    Optional<MembershipTO> membership = groupableTO.getMembership(group.getKey());
                    if (!membership.isPresent()) {
                        membership = Optional.of(new MembershipTO.Builder().group(group.getKey(), group.getName()).build());
                        groupableTO.getMemberships().add(membership.get());
                    }
                    membership.get().getDerAttrs().add(attrTO);
                }
                break;
            case VIRTUAL:
                attrTO = new AttrTO();
                attrTO.setSchema(intAttrName.getSchemaName());
                // virtual attributes don't get transformed, iterate over original attr.getValue()
                if (attr != null && attr.getValue() != null && !attr.getValue().isEmpty()) {
                    attr.getValue().stream().filter(value -> value != null).forEachOrdered(value -> attrTO.getValues().add(value.toString()));
                }
                if (groupableTO == null || group == null) {
                    anyTO.getVirAttrs().add(attrTO);
                } else {
                    Optional<MembershipTO> membership = groupableTO.getMembership(group.getKey());
                    if (!membership.isPresent()) {
                        membership = Optional.of(new MembershipTO.Builder().group(group.getKey(), group.getName()).build());
                        groupableTO.getMemberships().add(membership.get());
                    }
                    membership.get().getVirAttrs().add(attrTO);
                }
                break;
            default:
        }
    }
}
Also used : Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PlainAttr(org.apache.syncope.core.persistence.api.entity.PlainAttr) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Schema(org.apache.syncope.core.persistence.api.entity.Schema) InvalidPasswordRuleConf(org.apache.syncope.core.provisioning.api.utils.policy.InvalidPasswordRuleConf) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.identityconnectors.framework.common.objects.Attribute) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) ConnObjectUtils(org.apache.syncope.core.provisioning.java.utils.ConnObjectUtils) GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) ParseException(java.text.ParseException) OperationalAttributes(org.identityconnectors.framework.common.objects.OperationalAttributes) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) OrgUnitItem(org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem) DerAttrHandler(org.apache.syncope.core.provisioning.api.DerAttrHandler) Set(java.util.Set) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) List(java.util.List) DerSchemaDAO(org.apache.syncope.core.persistence.api.dao.DerSchemaDAO) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttributeUtil(org.identityconnectors.framework.common.objects.AttributeUtil) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) VirAttrCache(org.apache.syncope.core.provisioning.api.cache.VirAttrCache) ApplicationDAO(org.apache.syncope.core.persistence.api.dao.ApplicationDAO) ItemTransformer(org.apache.syncope.core.provisioning.api.data.ItemTransformer) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyUtilsFactory(org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory) RealmTO(org.apache.syncope.common.lib.to.RealmTO) GroupableRelatable(org.apache.syncope.core.persistence.api.entity.GroupableRelatable) AnyTO(org.apache.syncope.common.lib.to.AnyTO) FrameworkUtil(org.identityconnectors.framework.common.FrameworkUtil) BooleanUtils(org.apache.commons.lang3.BooleanUtils) PasswordGenerator(org.apache.syncope.core.spring.security.PasswordGenerator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Application(org.apache.syncope.core.persistence.api.entity.Application) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) Item(org.apache.syncope.core.persistence.api.entity.resource.Item) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) Encryptor(org.apache.syncope.core.spring.security.Encryptor) Logger(org.slf4j.Logger) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) PlainSchemaDAO(org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO) VirAttrHandler(org.apache.syncope.core.provisioning.api.VirAttrHandler) User(org.apache.syncope.core.persistence.api.entity.user.User) Membership(org.apache.syncope.core.persistence.api.entity.Membership) Name(org.identityconnectors.framework.common.objects.Name) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) Component(org.springframework.stereotype.Component) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) Any(org.apache.syncope.core.persistence.api.entity.Any) DateFormatUtils(org.apache.commons.lang3.time.DateFormatUtils) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) Transactional(org.springframework.transaction.annotation.Transactional) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) ItemTransformer(org.apache.syncope.core.provisioning.api.data.ItemTransformer) AttrTO(org.apache.syncope.common.lib.to.AttrTO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) GroupTO(org.apache.syncope.common.lib.to.GroupTO) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) UserTO(org.apache.syncope.common.lib.to.UserTO) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) ParseException(java.text.ParseException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with AttrSchemaType

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

the class AbstractAnySearchDAO method check.

protected Triple<PlainSchema, PlainAttrValue, AnyCond> check(final AnyCond cond, final AnyTypeKind kind) {
    AnyCond condClone = SerializationUtils.clone(cond);
    AnyUtils attrUtils = anyUtilsFactory.getInstance(kind);
    // Keeps track of difference between entity's getKey() and JPA @Id fields
    if ("key".equals(condClone.getSchema())) {
        condClone.setSchema("id");
    }
    Field anyField = ReflectionUtils.findField(attrUtils.anyClass(), condClone.getSchema());
    if (anyField == null) {
        LOG.warn("Ignoring invalid schema '{}'", condClone.getSchema());
        throw new IllegalArgumentException();
    }
    PlainSchema schema = new JPAPlainSchema();
    schema.setKey(anyField.getName());
    for (AttrSchemaType attrSchemaType : AttrSchemaType.values()) {
        if (anyField.getType().isAssignableFrom(attrSchemaType.getType())) {
            schema.setType(attrSchemaType);
        }
    }
    // Deal with any Integer fields logically mapping to boolean values
    boolean foundBooleanMin = false;
    boolean foundBooleanMax = false;
    if (Integer.class.equals(anyField.getType())) {
        for (Annotation annotation : anyField.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) {
        schema.setType(AttrSchemaType.Boolean);
    }
    // Deal with any fields representing relationships to other entities
    if (anyField.getType().getAnnotation(Entity.class) != null) {
        Method relMethod = null;
        try {
            relMethod = ClassUtils.getPublicMethod(anyField.getType(), "getKey", new Class<?>[0]);
        } catch (Exception e) {
            LOG.error("Could not find {}#getKey", anyField.getType(), e);
        }
        if (relMethod != null && String.class.isAssignableFrom(relMethod.getReturnType())) {
            condClone.setSchema(condClone.getSchema() + "_id");
            schema.setType(AttrSchemaType.String);
        }
    }
    PlainAttrValue attrValue = attrUtils.newPlainAttrValue();
    if (condClone.getType() != AttributeCond.Type.LIKE && condClone.getType() != AttributeCond.Type.ILIKE && condClone.getType() != AttributeCond.Type.ISNULL && condClone.getType() != AttributeCond.Type.ISNOTNULL) {
        try {
            ((JPAPlainSchema) schema).validator().validate(condClone.getExpression(), attrValue);
        } catch (ValidationException e) {
            LOG.error("Could not validate expression '" + condClone.getExpression() + "'", e);
            throw new IllegalArgumentException();
        }
    }
    return Triple.of(schema, attrValue, condClone);
}
Also used : Entity(javax.persistence.Entity) ValidationException(javax.validation.ValidationException) Max(javax.validation.constraints.Max) JPAPlainSchema(org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) ValidationException(javax.validation.ValidationException) Field(java.lang.reflect.Field) Min(javax.validation.constraints.Min) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) JPAPlainSchema(org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils)

Example 4 with AttrSchemaType

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

the class ParametersDirectoryPanel method getColumns.

@Override
protected List<IColumn<AttrTO, String>> getColumns() {
    final List<IColumn<AttrTO, String>> columns = new ArrayList<>();
    columns.add(new PropertyColumn<>(new ResourceModel("schema"), "schema"));
    columns.add(new PropertyColumn<AttrTO, String>(new ResourceModel("values"), "values") {

        private static final long serialVersionUID = -1822504503325964706L;

        @Override
        public void populateItem(final Item<ICellPopulator<AttrTO>> item, final String componentId, final IModel<AttrTO> rowModel) {
            PlainSchemaTO modelSchemaTO = (PlainSchemaTO) rowModel.getObject().getSchemaInfo();
            AttrSchemaType type = modelSchemaTO.getType();
            if (type == AttrSchemaType.Binary || type == AttrSchemaType.Encrypted) {
                item.add(new Label(componentId, type.name()).add(new AttributeModifier("style", "font-style:italic")));
            } else {
                super.populateItem(item, componentId, rowModel);
            }
        }
    });
    return columns;
}
Also used : ArrayList(java.util.ArrayList) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Label(org.apache.wicket.markup.html.basic.Label) AttributeModifier(org.apache.wicket.AttributeModifier) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) StringResourceModel(org.apache.wicket.model.StringResourceModel) ResourceModel(org.apache.wicket.model.ResourceModel)

Example 5 with AttrSchemaType

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

the class PlainAttrs method getFieldPanel.

@SuppressWarnings({ "rawtypes", "unchecked" })
protected FieldPanel getFieldPanel(final PlainSchemaTO schemaTO) {
    final boolean required;
    final boolean readOnly;
    final AttrSchemaType type;
    final boolean jexlHelp;
    if (mode == AjaxWizard.Mode.TEMPLATE) {
        required = false;
        readOnly = false;
        type = AttrSchemaType.String;
        jexlHelp = true;
    } else {
        required = schemaTO.getMandatoryCondition().equalsIgnoreCase("true");
        readOnly = schemaTO.isReadonly();
        type = schemaTO.getType();
        jexlHelp = false;
    }
    FieldPanel panel;
    switch(type) {
        case Boolean:
            panel = new AjaxCheckBoxPanel("panel", schemaTO.getKey(), new Model<>(), true);
            panel.setRequired(required);
            break;
        case Date:
            String dataPattern = schemaTO.getConversionPattern() == null ? SyncopeConstants.DEFAULT_DATE_PATTERN : schemaTO.getConversionPattern();
            if (dataPattern.contains("H")) {
                panel = new AjaxDateTimeFieldPanel("panel", schemaTO.getKey(), new Model<>(), dataPattern);
            } else {
                panel = new AjaxDateFieldPanel("panel", schemaTO.getKey(), new Model<>(), dataPattern);
            }
            if (required) {
                panel.addRequiredLabel();
            }
            break;
        case Enum:
            panel = new AjaxDropDownChoicePanel<>("panel", schemaTO.getKey(), new Model<>(), true);
            ((AjaxDropDownChoicePanel<String>) panel).setChoices(SchemaUtils.getEnumeratedValues(schemaTO));
            if (StringUtils.isNotBlank(schemaTO.getEnumerationKeys())) {
                ((AjaxDropDownChoicePanel) panel).setChoiceRenderer(new IChoiceRenderer<String>() {

                    private static final long serialVersionUID = -3724971416312135885L;

                    private final Map<String, String> valueMap = SchemaUtils.getEnumeratedKeyValues(schemaTO);

                    @Override
                    public String getDisplayValue(final String value) {
                        return valueMap.get(value) == null ? value : valueMap.get(value);
                    }

                    @Override
                    public String getIdValue(final String value, final int i) {
                        return value;
                    }

                    @Override
                    public String getObject(final String id, final IModel<? extends List<? extends String>> choices) {
                        return id;
                    }
                });
            }
            if (required) {
                panel.addRequiredLabel();
            }
            break;
        case Long:
            panel = new AjaxSpinnerFieldPanel.Builder<Long>().enableOnChange().build("panel", schemaTO.getKey(), Long.class, new Model<Long>());
            if (required) {
                panel.addRequiredLabel();
            }
            break;
        case Double:
            panel = new AjaxSpinnerFieldPanel.Builder<Double>().enableOnChange().step(0.1).build("panel", schemaTO.getKey(), Double.class, new Model<Double>());
            if (required) {
                panel.addRequiredLabel();
            }
            break;
        case Binary:
            final PageReference pageReference = getPageReference();
            panel = new BinaryFieldPanel("panel", schemaTO.getKey(), new Model<>(), schemaTO.getMimeType(), fileKey) {

                private static final long serialVersionUID = -3268213909514986831L;

                @Override
                protected PageReference getPageReference() {
                    return pageReference;
                }
            };
            if (required) {
                panel.addRequiredLabel();
            }
            break;
        case Encrypted:
            panel = new EncryptedFieldPanel("panel", schemaTO.getKey(), new Model<>(), true);
            if (required) {
                panel.addRequiredLabel();
            }
            break;
        default:
            panel = new AjaxTextFieldPanel("panel", schemaTO.getKey(), new Model<>(), true);
            if (jexlHelp) {
                AjaxTextFieldPanel.class.cast(panel).enableJexlHelp();
            }
            if (required) {
                panel.addRequiredLabel();
            }
    }
    panel.setReadOnly(readOnly);
    return panel;
}
Also used : AjaxDateFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateFieldPanel) AjaxSpinnerFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxSpinnerFieldPanel) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) AjaxCheckBoxPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel) EncryptedFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.EncryptedFieldPanel) PageReference(org.apache.wicket.PageReference) FieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.FieldPanel) AjaxSpinnerFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxSpinnerFieldPanel) EncryptedFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.EncryptedFieldPanel) AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) AjaxDateTimeFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateTimeFieldPanel) AjaxDateFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateFieldPanel) MultiFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel) BinaryFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.BinaryFieldPanel) AbstractFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AbstractFieldPanel) AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) StringResourceModel(org.apache.wicket.model.StringResourceModel) IModel(org.apache.wicket.model.IModel) ListModel(org.apache.wicket.model.util.ListModel) Model(org.apache.wicket.model.Model) PropertyModel(org.apache.wicket.model.PropertyModel) ResourceModel(org.apache.wicket.model.ResourceModel) BinaryFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.BinaryFieldPanel) AjaxDateTimeFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateTimeFieldPanel)

Aggregations

AttrSchemaType (org.apache.syncope.common.lib.types.AttrSchemaType)5 ArrayList (java.util.ArrayList)3 PlainAttrValue (org.apache.syncope.core.persistence.api.entity.PlainAttrValue)3 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)3 ParseException (java.text.ParseException)2 AttrTO (org.apache.syncope.common.lib.to.AttrTO)2 ParsingValidationException (org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException)2 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)2 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)2 Schema (org.apache.syncope.core.persistence.api.entity.Schema)2 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)2 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)2 User (org.apache.syncope.core.persistence.api.entity.user.User)2 IntAttrName (org.apache.syncope.core.provisioning.api.IntAttrName)2 InvalidPasswordRuleConf (org.apache.syncope.core.provisioning.api.utils.policy.InvalidPasswordRuleConf)2 ResourceModel (org.apache.wicket.model.ResourceModel)2 StringResourceModel (org.apache.wicket.model.StringResourceModel)2 Attribute (org.identityconnectors.framework.common.objects.Attribute)2 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1