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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations