Search in sources :

Example 96 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class SubFilterGenerator method build.

/**
 * Computes a filter based on an atomic (non-divisible) SCIM expression described by the set of parameters passed.
 * If the filter cannot be built, null is returned.
 * @param subAttribute The name of the json property upon which the search is acting. If the search is targetted
 *                     directly upon an attribute, this is null
 * @param attribute The attribute of interest. If the attribute contains json contents, the search can be focused on
 *                  a sub-attribute inside it
 * @param compValue The comparison value (it's found after the operator, e.g "hi" in displayName co "hi")
 * @param attrType The attribute definition type of the attribute
 * @param type See compvalue in ScimFilter.g4 grammar file
 * @param operator The operator
 * @param multiValued Whether the attribute referenced in parameter is multivalued or not (null tries to handle both)
 * @return The filter built after processing this atomic expression (accompanied with an error string if any)
 */
public Pair<Filter, String> build(String subAttribute, String attribute, String compValue, Type attrType, CompValueType type, ScimOperator operator, Boolean multiValued) {
    log.debug("Preparing subfilter with attribute={}, subAttribute={}, compValue={}, attrType={}, multiValued={}", attribute, subAttribute, compValue, attrType, multiValued);
    Filter filth = null;
    error = null;
    if (type.equals(CompValueType.NULL)) {
        if (subAttribute == null) {
            // attribute=*
            // attribute IS NOT MISSING
            filth = Filter.createPresenceFilter(attribute).multiValued(multiValued);
            filth = negateIf(filth, operator.equals(ScimOperator.EQUAL));
        } else {
            // attribute=*"subattribute":null*
            // attribute LIKE "%\"subattribute\":null%"
            String sub = String.format("\"%s\":null", subAttribute);
            filth = Filter.createSubstringFilter(attribute, null, new String[] { sub }, null).multiValued(multiValued);
            filth = negateIf(filth, operator.equals(ScimOperator.NOT_EQUAL));
        }
    } else if (Type.STRING.equals(attrType) || Type.REFERENCE.equals(attrType)) {
        // Drop double quotes
        compValue = compValue.substring(1, compValue.length() - 1);
        filth = getSubFilterString(subAttribute, attribute, StringEscapeUtils.unescapeJson(compValue), operator, multiValued);
    } else if (Type.INTEGER.equals(attrType) || Type.DECIMAL.equals(attrType)) {
        filth = getSubFilterNumeric(subAttribute, attribute, compValue, operator, attrType, multiValued);
    } else if (Type.BOOLEAN.equals(attrType)) {
        filth = getSubFilterBoolean(subAttribute, attribute, compValue, operator, multiValued);
    } else if (Type.DATETIME.equals(attrType)) {
        compValue = compValue.substring(1, compValue.length() - 1);
        // Dates do not have characters to escape...
        filth = getSubFilterDateTime(subAttribute, attribute, compValue, operator, multiValued);
    }
    log.trace("getSubFilter. {}", Optional.ofNullable(filth).map(Filter::toString).orElse(null));
    return new Pair<>(filth, error);
}
Also used : Filter(io.jans.orm.search.filter.Filter) Pair(io.jans.util.Pair)

Example 97 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class FidoDeviceService method getGluuCustomFidoDeviceById.

public GluuCustomFidoDevice getGluuCustomFidoDeviceById(String userId, String id) {
    GluuCustomFidoDevice gluuCustomFidoDevice = null;
    try {
        String dn = getDnForFidoDevice(userId, id);
        if (StringUtils.isNotEmpty(userId))
            gluuCustomFidoDevice = ldapEntryManager.find(GluuCustomFidoDevice.class, dn);
        else {
            Filter filter = Filter.createEqualityFilter("jansId", id);
            gluuCustomFidoDevice = ldapEntryManager.findEntries(dn, GluuCustomFidoDevice.class, filter).get(0);
        }
    } catch (Exception e) {
        log.error("Failed to find device by id " + id, e);
    }
    return gluuCustomFidoDevice;
}
Also used : GluuCustomFidoDevice(io.jans.scim.model.fido.GluuCustomFidoDevice) Filter(io.jans.orm.search.filter.Filter)

Example 98 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class PersonService method searchPersons.

public List<GluuCustomPerson> searchPersons(String pattern, int sizeLimit, List<GluuCustomPerson> excludedPersons) throws Exception {
    Filter orFilter = buildFilter(pattern);
    Filter searchFilter = orFilter;
    if (excludedPersons != null && excludedPersons.size() > 0) {
        List<Filter> excludeFilters = new ArrayList<Filter>();
        for (GluuCustomPerson excludedPerson : excludedPersons) {
            Filter eqFilter = Filter.createEqualityFilter(OxConstants.UID, excludedPerson.getUid());
            excludeFilters.add(eqFilter);
        }
        Filter orExcludeFilter = null;
        if (excludedPersons.size() == 1) {
            orExcludeFilter = excludeFilters.get(0);
        } else {
            orExcludeFilter = Filter.createORFilter(excludeFilters);
        }
        Filter notFilter = Filter.createNOTFilter(orExcludeFilter);
        searchFilter = Filter.createANDFilter(orFilter, notFilter);
    }
    return persistenceEntryManager.findEntries(getDnForPerson(null), GluuCustomPerson.class, searchFilter, sizeLimit);
}
Also used : GluuCustomPerson(io.jans.scim.model.GluuCustomPerson) Filter(io.jans.orm.search.filter.Filter) ArrayList(java.util.ArrayList)

Example 99 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class PersonService method getPersonsByEmail.

public List<GluuCustomPerson> getPersonsByEmail(String mail, String... returnAttributes) {
    log.debug("Getting user information from DB: mail = {}", mail);
    if (StringHelper.isEmpty(mail)) {
        return null;
    }
    Filter userMailFilter = Filter.createEqualityFilter(Filter.createLowercaseFilter("mail"), StringHelper.toLowerCase(mail));
    boolean multiValued = false;
    GluuAttribute mailAttribute = attributeService.getAttributeByName("mail");
    if ((mailAttribute != null) && (mailAttribute.getOxMultiValuedAttribute() != null) && mailAttribute.getOxMultiValuedAttribute()) {
        multiValued = true;
    }
    userMailFilter.multiValued(multiValued);
    List<GluuCustomPerson> entries = persistenceEntryManager.findEntries(getDnForPerson(null), GluuCustomPerson.class, userMailFilter, returnAttributes);
    log.debug("Found {} entries for mail = {}", entries.size(), mail);
    return entries;
}
Also used : GluuCustomPerson(io.jans.scim.model.GluuCustomPerson) Filter(io.jans.orm.search.filter.Filter) GluuAttribute(io.jans.model.GluuAttribute)

Example 100 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class PersonService method buildFilter.

private Filter buildFilter(String pattern) {
    String[] targetArray = new String[] { pattern };
    Filter uidFilter = Filter.createSubstringFilter(OxConstants.UID, null, targetArray, null);
    Filter mailFilter = Filter.createSubstringFilter(OxTrustConstants.mail, null, targetArray, null);
    Filter nameFilter = Filter.createSubstringFilter(OxTrustConstants.displayName, null, targetArray, null);
    Filter ppidFilter = Filter.createSubstringFilter(OxTrustConstants.ppid, null, targetArray, null);
    Filter inumFilter = Filter.createSubstringFilter(OxTrustConstants.inum, null, targetArray, null);
    Filter snFilter = Filter.createSubstringFilter(OxTrustConstants.sn, null, targetArray, null);
    Filter searchFilter = Filter.createORFilter(uidFilter, mailFilter, nameFilter, ppidFilter, inumFilter, snFilter);
    return searchFilter;
}
Also used : Filter(io.jans.orm.search.filter.Filter)

Aggregations

Filter (io.jans.orm.search.filter.Filter)188 Test (org.testng.annotations.Test)50 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)32 ConvertedExpression (io.jans.orm.couchbase.model.ConvertedExpression)28 SearchException (io.jans.orm.exception.operation.SearchException)25 ConvertedExpression (io.jans.orm.sql.model.ConvertedExpression)24 MappingException (io.jans.orm.exception.MappingException)22 ArrayList (java.util.ArrayList)21 AuthenticationException (io.jans.orm.exception.AuthenticationException)20 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)19 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)18 Date (java.util.Date)14 List (java.util.List)14 SqlEntryManager (io.jans.orm.sql.impl.SqlEntryManager)11 SqlEntryManagerSample (io.jans.orm.sql.persistence.SqlEntryManagerSample)11 CustomAttribute (io.jans.orm.model.base.CustomAttribute)9 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)9 DateTimeParseException (java.time.format.DateTimeParseException)9 SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)8 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)8