Search in sources :

Example 1 with AnyCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.

the class SyncopeLogic method searchAssignableGroups.

@PreAuthorize("isAuthenticated()")
public Pair<Integer, List<GroupTO>> searchAssignableGroups(final String realm, final String term, final int page, final int size) {
    AssignableCond assignableCond = new AssignableCond();
    assignableCond.setRealmFullPath(realm);
    SearchCond searchCond;
    if (StringUtils.isNotBlank(term)) {
        AnyCond termCond = new AnyCond(AttributeCond.Type.ILIKE);
        termCond.setSchema("name");
        String termSearchableValue = (term.startsWith("*") && !term.endsWith("*")) ? term + "%" : (!term.startsWith("*") && term.endsWith("*")) ? "%" + term : (term.startsWith("*") && term.endsWith("*") ? term : "%" + term + "%");
        termCond.setExpression(termSearchableValue);
        searchCond = SearchCond.getAndCond(SearchCond.getLeafCond(assignableCond), SearchCond.getLeafCond(termCond));
    } else {
        searchCond = SearchCond.getLeafCond(assignableCond);
    }
    int count = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, AnyTypeKind.GROUP);
    OrderByClause orderByClause = new OrderByClause();
    orderByClause.setField("name");
    orderByClause.setDirection(OrderByClause.Direction.ASC);
    List<Group> matching = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, page, size, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
    List<GroupTO> result = matching.stream().map(group -> groupDataBinder.getGroupTO(group, false)).collect(Collectors.toList());
    return Pair.of(count, result);
}
Also used : Arrays(java.util.Arrays) SecurityQuestionDAO(org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO) AopUtils(org.springframework.aop.support.AopUtils) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) GroupProvisioningManager(org.apache.syncope.core.provisioning.api.GroupProvisioningManager) PlatformInfo(org.apache.syncope.common.lib.info.PlatformInfo) StringUtils(org.apache.commons.lang3.StringUtils) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) InetAddress(java.net.InetAddress) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Map(java.util.Map) URI(java.net.URI) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Method(java.lang.reflect.Method) PayloadApplicationEvent(org.springframework.context.PayloadApplicationEvent) RuntimeMXBean(java.lang.management.RuntimeMXBean) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) GroupWorkflowAdapter(org.apache.syncope.core.workflow.api.GroupWorkflowAdapter) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) NotificationDAO(org.apache.syncope.core.persistence.api.dao.NotificationDAO) EntitlementsHolder(org.apache.syncope.core.provisioning.api.EntitlementsHolder) Resource(javax.annotation.Resource) EventListener(org.springframework.context.event.EventListener) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SystemInfo(org.apache.syncope.common.lib.info.SystemInfo) List(java.util.List) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) ConnIdBundleManager(org.apache.syncope.core.provisioning.api.ConnIdBundleManager) PropagationTaskExecutor(org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) VirAttrCache(org.apache.syncope.core.provisioning.api.cache.VirAttrCache) AbstractBaseBean(org.apache.syncope.common.lib.AbstractBaseBean) NumbersInfo(org.apache.syncope.common.lib.info.NumbersInfo) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) PasswordGenerator(org.apache.syncope.core.spring.security.PasswordGenerator) GroupDataBinder(org.apache.syncope.core.provisioning.api.data.GroupDataBinder) UserWorkflowAdapter(org.apache.syncope.core.workflow.api.UserWorkflowAdapter) TaskDAO(org.apache.syncope.core.persistence.api.dao.TaskDAO) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) AnyObjectProvisioningManager(org.apache.syncope.core.provisioning.api.AnyObjectProvisioningManager) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Iterator(java.util.Iterator) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) UnknownHostException(java.net.UnknownHostException) ImplementationLookup(org.apache.syncope.core.persistence.api.ImplementationLookup) Component(org.springframework.stereotype.Component) UserProvisioningManager(org.apache.syncope.core.provisioning.api.UserProvisioningManager) JavaImplInfo(org.apache.syncope.common.lib.info.JavaImplInfo) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) AnyObjectWorkflowAdapter(org.apache.syncope.core.workflow.api.AnyObjectWorkflowAdapter) TaskType(org.apache.syncope.common.lib.types.TaskType) Transactional(org.springframework.transaction.annotation.Transactional) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) Group(org.apache.syncope.core.persistence.api.entity.group.Group) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) GroupTO(org.apache.syncope.common.lib.to.GroupTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with AnyCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.

the class AbstractAnySearchDAO method matches.

@Override
public <T extends Any<?>> boolean matches(final T any, final SearchCond cond) {
    AnyCond keycond = new AnyCond(AttributeCond.Type.EQ);
    keycond.setSchema("key");
    keycond.setExpression(any.getKey());
    return !search(SearchCond.getAndCond(SearchCond.getLeafCond(keycond), cond), any.getType().getKind()).isEmpty();
}
Also used : AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond)

Example 3 with AnyCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyCond 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 AnyCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.

the class DefaultPullCorrelationRule method getSearchCond.

@Override
public SearchCond getSearchCond(final ConnectorObject connObj, final Provision provision) {
    Map<String, Item> mappingItems = provision.getMapping().getItems().stream().collect(Collectors.toMap(Item::getIntAttrName, Function.identity()));
    // search for anys by attribute(s) specified in the policy
    SearchCond searchCond = null;
    for (String schema : conf.getSchemas()) {
        Item mappingItem = mappingItems.get(schema);
        Attribute attr = mappingItem == null ? null : connObj.getAttributeByName(mappingItem.getExtAttrName());
        if (attr == null) {
            throw new IllegalArgumentException("Connector object does not contains the attributes to perform the search: " + schema);
        }
        AttributeCond.Type type;
        String expression = null;
        if (attr.getValue() == null || attr.getValue().isEmpty() || (attr.getValue().size() == 1 && attr.getValue().get(0) == null)) {
            type = AttributeCond.Type.ISNULL;
        } else {
            type = AttributeCond.Type.EQ;
            expression = attr.getValue().size() > 1 ? attr.getValue().toString() : attr.getValue().get(0).toString();
        }
        SearchCond nodeCond;
        // any objects: just key or name can be selected
        if ("key".equalsIgnoreCase(schema) || "username".equalsIgnoreCase(schema) || "name".equalsIgnoreCase(schema)) {
            AnyCond cond = new AnyCond();
            cond.setSchema(schema);
            cond.setType(type);
            cond.setExpression(expression);
            nodeCond = SearchCond.getLeafCond(cond);
        } else {
            AttributeCond cond = new AttributeCond();
            cond.setSchema(schema);
            cond.setType(type);
            cond.setExpression(expression);
            nodeCond = SearchCond.getLeafCond(cond);
        }
        searchCond = searchCond == null ? nodeCond : SearchCond.getAndCond(searchCond, nodeCond);
    }
    return searchCond;
}
Also used : Item(org.apache.syncope.core.persistence.api.entity.resource.Item) Attribute(org.identityconnectors.framework.common.objects.Attribute) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond)

Example 5 with AnyCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.

the class SearchCondConverterTest method ilike.

@Test
public void ilike() {
    String fiql = new UserFiqlSearchConditionBuilder().is("username").equalToIgnoreCase("ros*").query();
    assertEquals("username=~ros*", fiql);
    AttributeCond attrCond = new AnyCond(AttributeCond.Type.ILIKE);
    attrCond.setSchema("username");
    attrCond.setExpression("ros%");
    SearchCond simpleCond = SearchCond.getLeafCond(attrCond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
}
Also used : AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) UserFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) Test(org.junit.jupiter.api.Test)

Aggregations

AnyCond (org.apache.syncope.core.persistence.api.dao.search.AnyCond)25 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)20 Test (org.junit.jupiter.api.Test)16 AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)11 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)10 UserFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder)6 User (org.apache.syncope.core.persistence.api.entity.user.User)6 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)3 Group (org.apache.syncope.core.persistence.api.entity.group.Group)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)2 RealmTO (org.apache.syncope.common.lib.to.RealmTO)2 Realm (org.apache.syncope.core.persistence.api.entity.Realm)2 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)2 Annotation (java.lang.annotation.Annotation)1 ManagementFactory (java.lang.management.ManagementFactory)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1