Search in sources :

Example 31 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class AbstractAnyLogic method beforeCreate.

protected Pair<TO, List<LogicActions>> beforeCreate(final TO input) {
    Realm realm = realmDAO.findByFullPath(input.getRealm());
    if (realm == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
        sce.getElements().add(input.getRealm());
        throw sce;
    }
    AnyType anyType = input instanceof UserTO ? anyTypeDAO.findUser() : input instanceof GroupTO ? anyTypeDAO.findGroup() : anyTypeDAO.find(input.getType());
    if (anyType == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
        sce.getElements().add(input.getType());
        throw sce;
    }
    TO any = input;
    templateUtils.apply(any, realm.getTemplate(anyType));
    List<LogicActions> actions = getActions(realm);
    for (LogicActions action : actions) {
        any = action.beforeCreate(any);
    }
    LOG.debug("Input: {}\nOutput: {}\n", input, any);
    return ImmutablePair.of(any, actions);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTO(org.apache.syncope.common.lib.to.AnyTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) UserTO(org.apache.syncope.common.lib.to.UserTO) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) LogicActions(org.apache.syncope.core.provisioning.api.LogicActions) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 32 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class NotificationManagerImpl method createTasks.

@Override
public List<NotificationTask> createTasks(final AuditElements.EventCategoryType type, final String category, final String subcategory, final String event, final Result condition, final Object before, final Object output, final Object... input) {
    Any<?> any = null;
    if (before instanceof UserTO) {
        any = userDAO.find(((UserTO) before).getKey());
    } else if (output instanceof UserTO) {
        any = userDAO.find(((UserTO) output).getKey());
    } else if (output instanceof Pair && ((Pair) output).getRight() instanceof UserTO) {
        any = userDAO.find(((UserTO) ((Pair) output).getRight()).getKey());
    } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof UserTO) {
        any = userDAO.find(((ProvisioningResult) output).getEntity().getKey());
    } else if (before instanceof AnyObjectTO) {
        any = anyObjectDAO.find(((AnyObjectTO) before).getKey());
    } else if (output instanceof AnyObjectTO) {
        any = anyObjectDAO.find(((AnyObjectTO) output).getKey());
    } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof AnyObjectTO) {
        any = anyObjectDAO.find(((ProvisioningResult) output).getEntity().getKey());
    } else if (before instanceof GroupTO) {
        any = groupDAO.find(((GroupTO) before).getKey());
    } else if (output instanceof GroupTO) {
        any = groupDAO.find(((GroupTO) output).getKey());
    } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof GroupTO) {
        any = groupDAO.find(((ProvisioningResult) output).getEntity().getKey());
    }
    AnyType anyType = any == null ? null : any.getType();
    LOG.debug("Search notification for [{}]{}", anyType, any);
    List<NotificationTask> notifications = new ArrayList<>();
    for (Notification notification : notificationDAO.findAll()) {
        if (LOG.isDebugEnabled()) {
            notification.getAbouts().forEach(about -> {
                LOG.debug("Notification about {} defined: {}", about.getAnyType(), about.get());
            });
        }
        if (notification.isActive()) {
            String currentEvent = AuditLoggerName.buildEvent(type, category, subcategory, event, condition);
            if (!notification.getEvents().contains(currentEvent)) {
                LOG.debug("No events found about {}", any);
            } else if (anyType == null || any == null || !notification.getAbout(anyType).isPresent() || searchDAO.matches(any, SearchCondConverter.convert(notification.getAbout(anyType).get().get()))) {
                LOG.debug("Creating notification task for event {} about {}", currentEvent, any);
                final Map<String, Object> model = new HashMap<>();
                model.put("type", type);
                model.put("category", category);
                model.put("subcategory", subcategory);
                model.put("event", event);
                model.put("condition", condition);
                model.put("before", before);
                model.put("output", output);
                model.put("input", input);
                if (any instanceof User) {
                    model.put("user", userDataBinder.getUserTO((User) any, true));
                } else if (any instanceof Group) {
                    model.put("group", groupDataBinder.getGroupTO((Group) any, true));
                } else if (any instanceof AnyObject) {
                    model.put("group", anyObjectDataBinder.getAnyObjectTO((AnyObject) any, true));
                }
                NotificationTask notificationTask = getNotificationTask(notification, any, model);
                notificationTask = taskDAO.save(notificationTask);
                notifications.add(notificationTask);
            }
        } else {
            LOG.debug("Notification {} is not active, task will not be created", notification.getKey());
        }
    }
    return notifications;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) User(org.apache.syncope.core.persistence.api.entity.user.User) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ArrayList(java.util.ArrayList) Notification(org.apache.syncope.core.persistence.api.entity.Notification) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.apache.commons.lang3.tuple.Pair)

Example 33 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO 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 34 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupDataBinderImpl method getGroupTO.

@Transactional(readOnly = true)
@Override
public GroupTO getGroupTO(final Group group, final boolean details) {
    GroupTO groupTO = new GroupTO();
    // set sys info
    groupTO.setCreator(group.getCreator());
    groupTO.setCreationDate(group.getCreationDate());
    groupTO.setLastModifier(group.getLastModifier());
    groupTO.setLastChangeDate(group.getLastChangeDate());
    groupTO.setKey(group.getKey());
    groupTO.setName(group.getName());
    if (group.getUserOwner() != null) {
        groupTO.setUserOwner(group.getUserOwner().getKey());
    }
    if (group.getGroupOwner() != null) {
        groupTO.setGroupOwner(group.getGroupOwner().getKey());
    }
    Map<DerSchema, String> derAttrValues = derAttrHandler.getValues(group);
    Map<VirSchema, List<String>> virAttrValues = details ? virAttrHandler.getValues(group) : Collections.<VirSchema, List<String>>emptyMap();
    fillTO(groupTO, group.getRealm().getFullPath(), group.getAuxClasses(), group.getPlainAttrs(), derAttrValues, virAttrValues, group.getResources(), details);
    if (details) {
        // dynamic realms
        groupTO.getDynRealms().addAll(groupDAO.findDynRealms(group.getKey()));
    }
    // Static user and AnyType membership counts
    groupTO.setStaticUserMembershipCount(groupDAO.countUMembers(group));
    groupTO.setStaticAnyObjectMembershipCount(groupDAO.countAMembers(group));
    // Dynamic user and AnyType membership counts
    groupTO.setDynamicUserMembershipCount(groupDAO.countUDynMembers(group));
    groupTO.setDynamicAnyObjectMembershipCount(groupDAO.countADynMembers(group));
    if (group.getUDynMembership() != null) {
        groupTO.setUDynMembershipCond(group.getUDynMembership().getFIQLCond());
    }
    group.getADynMemberships().forEach(memb -> {
        groupTO.getADynMembershipConds().put(memb.getAnyType().getKey(), memb.getFIQLCond());
    });
    group.getTypeExtensions().forEach(typeExt -> {
        groupTO.getTypeExtensions().add(getTypeExtensionTO(typeExt));
    });
    return groupTO;
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) List(java.util.List) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class SearchClausePanel method settingsDependingComponents.

@Override
public FieldPanel<SearchClause> settingsDependingComponents() {
    final SearchClause searchClause = this.clause.getObject();
    final WebMarkupContainer operatorContainer = new WebMarkupContainer("operatorContainer");
    operatorContainer.setOutputMarkupId(true);
    field.add(operatorContainer);
    final BootstrapToggleConfig config = new BootstrapToggleConfig().withOnStyle(BootstrapToggleConfig.Style.info).withOffStyle(BootstrapToggleConfig.Style.warning).withSize(BootstrapToggleConfig.Size.mini);
    operatorFragment.add(new BootstrapToggle("operator", new Model<Boolean>() {

        private static final long serialVersionUID = -7157802546272668001L;

        @Override
        public Boolean getObject() {
            return searchClause.getOperator() == Operator.AND;
        }

        @Override
        public void setObject(final Boolean object) {
            searchClause.setOperator(object ? Operator.AND : Operator.OR);
        }
    }, config) {

        private static final long serialVersionUID = 2969634208049189343L;

        @Override
        protected IModel<String> getOffLabel() {
            return Model.of("OR");
        }

        @Override
        protected IModel<String> getOnLabel() {
            return Model.of("AND");
        }

        @Override
        protected CheckBox newCheckBox(final String id, final IModel<Boolean> model) {
            final CheckBox checkBox = super.newCheckBox(id, model);
            checkBox.add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(final AjaxRequestTarget target) {
                }
            });
            return checkBox;
        }
    }.setOutputMarkupPlaceholderTag(true));
    if (getIndex() > 0) {
        operatorContainer.add(operatorFragment);
    } else {
        operatorContainer.add(searchButtonFragment);
    }
    final AjaxTextFieldPanel property = new AjaxTextFieldPanel("property", "property", new PropertyModel<String>(searchClause, "property"), false);
    property.hideLabel().setOutputMarkupId(true).setEnabled(true);
    property.setChoices(properties.getObject());
    field.add(property);
    property.getField().add(AttributeModifier.replace("onkeydown", Model.of("if(event.keyCode == 13) { event.preventDefault(); }")));
    property.getField().add(new IndicatorAjaxEventBehavior("onkeyup") {

        private static final long serialVersionUID = -7866120562087857309L;

        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            if (field.getModel().getObject() == null || field.getModel().getObject().getType() == null) {
                return;
            }
            if (field.getModel().getObject().getType() == Type.GROUP_MEMBERSHIP) {
                String[] inputAsArray = property.getField().getInputAsArray();
                if (StringUtils.isBlank(property.getField().getInput()) || inputAsArray.length == 0) {
                    property.setChoices(properties.getObject());
                } else {
                    String inputValue = (inputAsArray.length > 1 && inputAsArray[1] != null) ? inputAsArray[1] : property.getField().getInput();
                    inputValue = (inputValue.startsWith("*") && !inputValue.endsWith("*")) ? inputValue + "*" : (!inputValue.startsWith("*") && inputValue.endsWith("*")) ? "*" + inputValue : (inputValue.startsWith("*") && inputValue.endsWith("*") ? inputValue : "*" + inputValue + "*");
                    if (groupInfo.getRight() > AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY) {
                        List<GroupTO> filteredGroups = groupRestClient.search("/", SyncopeClient.getGroupSearchConditionBuilder().is("name").equalToIgnoreCase(inputValue).query(), 1, AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY, new SortParam<>("name", true), null);
                        Collection<String> newList = CollectionUtils.collect(filteredGroups, new Transformer<GroupTO, String>() {

                            @Override
                            public String transform(final GroupTO input) {
                                return input.getName();
                            }
                        });
                        final List<String> names = new ArrayList<>(newList);
                        Collections.sort(names);
                        property.setChoices(names);
                    }
                }
            }
        }

        @Override
        protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners().clear();
        }
    }, new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
        }
    });
    final AjaxDropDownChoicePanel<SearchClause.Comparator> comparator = new AjaxDropDownChoicePanel<>("comparator", "comparator", new PropertyModel<>(searchClause, "comparator"));
    comparator.setChoices(comparators);
    comparator.setNullValid(false).hideLabel().setOutputMarkupId(true);
    comparator.setRequired(required);
    comparator.setChoiceRenderer(getComparatorRender(field.getModel()));
    field.add(comparator);
    final AjaxTextFieldPanel value = new AjaxTextFieldPanel("value", "value", new PropertyModel<>(searchClause, "value"), false);
    value.hideLabel().setOutputMarkupId(true);
    field.add(value);
    value.getField().add(AttributeModifier.replace("onkeydown", Model.of("if(event.keyCode == 13) {event.preventDefault();}")));
    value.getField().add(new IndicatorAjaxEventBehavior("onkeydown") {

        private static final long serialVersionUID = -7133385027739964990L;

        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            target.focusComponent(null);
            value.getField().inputChanged();
            value.getField().validate();
            if (value.getField().isValid()) {
                value.getField().valid();
                value.getField().updateModel();
            }
        }

        @Override
        protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners().add(new AjaxCallListener() {

                private static final long serialVersionUID = 7160235486520935153L;

                @Override
                public CharSequence getPrecondition(final Component component) {
                    return "if (Wicket.Event.keyCode(attrs.event)  == 13) { return true; } else { return false; }";
                }
            });
        }
    });
    final AjaxDropDownChoicePanel<SearchClause.Type> type = new AjaxDropDownChoicePanel<>("type", "type", new PropertyModel<>(searchClause, "type"));
    type.setChoices(types).hideLabel().setRequired(required).setOutputMarkupId(true);
    type.setNullValid(false);
    type.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            final SearchClause searchClause = new SearchClause();
            if (StringUtils.isNotEmpty(type.getDefaultModelObjectAsString())) {
                searchClause.setType(Type.valueOf(type.getDefaultModelObjectAsString()));
            }
            SearchClausePanel.this.clause.setObject(searchClause);
            setFieldAccess(searchClause.getType(), property, comparator, value);
            // reset property value in case and just in case of change of type
            property.setModelObject(StringUtils.EMPTY);
            target.add(property);
            target.add(comparator);
            target.add(value);
        }
    });
    field.add(type);
    comparator.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            if (type.getModelObject() == SearchClause.Type.ATTRIBUTE || type.getModelObject() == SearchClause.Type.RELATIONSHIP) {
                if (comparator.getModelObject() == SearchClause.Comparator.IS_NULL || comparator.getModelObject() == SearchClause.Comparator.IS_NOT_NULL) {
                    value.setModelObject(StringUtils.EMPTY);
                    value.setEnabled(false);
                } else {
                    value.setEnabled(true);
                }
                target.add(value);
            }
            if (type.getModelObject() == SearchClause.Type.RELATIONSHIP) {
                property.setEnabled(true);
                final SearchClause searchClause = new SearchClause();
                searchClause.setType(Type.valueOf(type.getDefaultModelObjectAsString()));
                searchClause.setComparator(comparator.getModelObject());
                SearchClausePanel.this.clause.setObject(searchClause);
                target.add(property);
            }
        }
    });
    setFieldAccess(searchClause.getType(), property, comparator, value);
    return this;
}
Also used : Transformer(org.apache.commons.collections4.Transformer) IndicatorAjaxFormComponentUpdatingBehavior(org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) SortParam(org.apache.wicket.extensions.markup.html.repeater.util.SortParam) Comparator(org.apache.syncope.client.console.panels.search.SearchClause.Comparator) IndicatorAjaxEventBehavior(org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxEventBehavior) List(java.util.List) ArrayList(java.util.ArrayList) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IModel(org.apache.wicket.model.IModel) AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) Type(org.apache.syncope.client.console.panels.search.SearchClause.Type) BootstrapToggleConfig(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig) BootstrapToggle(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggle) CheckBox(org.apache.wicket.markup.html.form.CheckBox) Collection(java.util.Collection) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Aggregations

GroupTO (org.apache.syncope.common.lib.to.GroupTO)90 Test (org.junit.jupiter.api.Test)47 UserTO (org.apache.syncope.common.lib.to.UserTO)34 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)23 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)16 List (java.util.List)15 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)14 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)14 Response (javax.ws.rs.core.Response)13 NamingException (javax.naming.NamingException)12 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 Map (java.util.Map)11 ForbiddenException (javax.ws.rs.ForbiddenException)11 AccessControlException (java.security.AccessControlException)10 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Collections (java.util.Collections)9