Search in sources :

Example 16 with Filter

use of com.unboundid.ldap.sdk.Filter in project oxCore by GluuFederation.

the class MetricService method getExpiredMetricEntries.

public List<MetricEntry> getExpiredMetricEntries(BatchOperation<MetricEntry> batchOperation, int batchSize, String baseDnForPeriod, Date expirationDate) {
    Filter expiratioFilter = Filter.createLessOrEqualFilter("oxStartDate", ldapEntryManager.encodeGeneralizedTime(expirationDate));
    List<MetricEntry> metricEntries = ldapEntryManager.findEntries(baseDnForPeriod, MetricEntry.class, expiratioFilter, SearchScope.SUB, new String[] { "uniqueIdentifier" }, batchOperation, 0, batchSize, batchSize);
    return metricEntries;
}
Also used : Filter(com.unboundid.ldap.sdk.Filter) MetricEntry(org.xdi.model.metric.ldap.MetricEntry)

Example 17 with Filter

use of com.unboundid.ldap.sdk.Filter in project oxTrust by GluuFederation.

the class BaseScimWebService method search.

public <T> List<T> search(String dn, Class<T> entryClass, String filterString, int startIndex, int count, String sortBy, String sortOrder, VirtualListViewResponse vlvResponse, String attributesArray) throws Exception {
    log.info("----------");
    log.info(" ### RAW PARAMS ###");
    log.info(" filter string = " + filterString);
    log.info(" startIndex = " + startIndex);
    log.info(" count = " + count);
    log.info(" sortBy = " + sortBy);
    log.info(" sortOrder = " + sortOrder);
    log.info(" attributes = " + attributesArray);
    Filter filter = null;
    if (filterString == null || (filterString != null && filterString.isEmpty())) {
        filter = Filter.create("inum=*");
    } else {
        Class clazz = null;
        if (entryClass.getName().equals(GluuCustomPerson.class.getName())) {
            clazz = ScimPerson.class;
        } else if (entryClass.getName().equals(GluuGroup.class.getName())) {
            clazz = ScimGroup.class;
        }
        filter = scimFilterParserService.createFilter(filterString, clazz);
    }
    startIndex = (startIndex < 1) ? 1 : startIndex;
    count = (count < 1) ? DEFAULT_COUNT : count;
    count = (count > getMaxCount()) ? getMaxCount() : count;
    sortBy = (sortBy != null && !sortBy.isEmpty()) ? sortBy : "displayName";
    if (entryClass.getName().equals(GluuCustomPerson.class.getName())) {
        sortBy = getUserLdapAttributeName(sortBy);
    } else if (entryClass.getName().equals(GluuGroup.class.getName())) {
        sortBy = getGroupLdapAttributeName(sortBy);
    }
    SortOrder sortOrderEnum = null;
    if (sortOrder != null && !sortOrder.isEmpty()) {
        sortOrderEnum = SortOrder.getByValue(sortOrder);
    } else if (sortBy != null && (sortOrder == null || (sortOrder != null && sortOrder.isEmpty()))) {
        sortOrderEnum = SortOrder.ASCENDING;
    } else {
        sortOrderEnum = SortOrder.ASCENDING;
    }
    // String[] attributes = (attributesArray != null && !attributesArray.isEmpty()) ? mapper.readValue(attributesArray, String[].class) : null;
    String[] attributes = (attributesArray != null && !attributesArray.isEmpty()) ? attributesArray.split("\\,") : null;
    if (attributes != null && attributes.length > 0) {
        // Add the attributes which are returned by default
        List<String> attributesList = new ArrayList<String>(Arrays.asList(attributes));
        Set<String> attributesSet = new LinkedHashSet<String>();
        for (String attribute : attributesList) {
            if (attribute != null && !attribute.isEmpty()) {
                attribute = FilterUtil.stripScim1Schema(attribute);
                if (entryClass.getName().equals(GluuCustomPerson.class.getName()) && attribute.toLowerCase().startsWith("name.")) {
                    if (!attributesSet.contains("name.familyName")) {
                        attributesSet.add("name.familyName");
                        attributesSet.add("name.middleName");
                        attributesSet.add("name.givenName");
                        attributesSet.add("name.honorificPrefix");
                        attributesSet.add("name.honorificSuffix");
                    }
                } else {
                    attributesSet.add(attribute);
                }
            }
        }
        attributesSet.add("id");
        if (entryClass.getName().equals(GluuCustomPerson.class.getName())) {
            attributesSet.add("userName");
        }
        if (entryClass.getName().equals(GluuGroup.class.getName())) {
            attributesSet.add("displayName");
        }
        /*
			attributesSet.add("meta.created");
			attributesSet.add("meta.lastModified");
			attributesSet.add("meta.location");
			attributesSet.add("meta.version");
			*/
        attributes = attributesSet.toArray(new String[attributesSet.size()]);
        for (int i = 0; i < attributes.length; i++) {
            if (attributes[i] != null && !attributes[i].isEmpty()) {
                if (entryClass.getName().equals(GluuCustomPerson.class.getName())) {
                    attributes[i] = getUserLdapAttributeName(attributes[i].trim());
                } else if (entryClass.getName().equals(GluuGroup.class.getName())) {
                    attributes[i] = getGroupLdapAttributeName(attributes[i].trim());
                }
            }
        }
    }
    log.info(" ### CONVERTED PARAMS ###");
    log.info(" parsed filter = " + filter.toString());
    log.info(" startIndex = " + startIndex);
    log.info(" count = " + count);
    log.info(" sortBy = " + sortBy);
    log.info(" sortOrder = " + sortOrderEnum.getValue());
    log.info(" attributes = " + ((attributes != null && attributes.length > 0) ? new ObjectMapper().writeValueAsString(attributes) : null));
    // List<T> result = ldapEntryManager.findEntriesVirtualListView(dn, entryClass, filter, startIndex, count, sortBy, sortOrderEnum, vlvResponse, attributes);
    List<T> result = ldapEntryManager.findEntriesSearchSearchResult(dn, entryClass, filter, startIndex, count, getMaxCount(), sortBy, sortOrderEnum, vlvResponse, attributes);
    log.info(" ### RESULTS INFO ###");
    log.info(" totalResults = " + vlvResponse.getTotalResults());
    log.info(" itemsPerPage = " + vlvResponse.getItemsPerPage());
    log.info(" startIndex = " + vlvResponse.getStartIndex());
    log.info("----------");
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) SortOrder(org.xdi.ldap.model.SortOrder) GluuGroup(org.gluu.oxtrust.model.GluuGroup) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) DEFAULT_COUNT(org.gluu.oxtrust.model.scim2.Constants.DEFAULT_COUNT) Filter(com.unboundid.ldap.sdk.Filter) ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 18 with Filter

use of com.unboundid.ldap.sdk.Filter in project oxCore by GluuFederation.

the class AttributeService method getAttributesByAttribute.

public List<GluuAttribute> getAttributesByAttribute(String attributeName, String attributeValue, String baseDn) {
    String[] targetArray = new String[] { attributeValue };
    Filter filter = Filter.createSubstringFilter(attributeName, null, targetArray, null);
    List<GluuAttribute> result = ldapEntryManager.findEntries(baseDn, GluuAttribute.class, filter);
    return result;
}
Also used : Filter(com.unboundid.ldap.sdk.Filter) GluuAttribute(org.xdi.model.GluuAttribute)

Example 19 with Filter

use of com.unboundid.ldap.sdk.Filter in project oxCore by GluuFederation.

the class LookupService method getDisplayNameEntries.

/**
	 * Returns list of DisplayNameEntry objects
	 * 
	 * @param baseDn
	 *            base DN
	 * @param dns
	 *            list of display names to find
	 * @return list of DisplayNameEntry objects
	 */
@SuppressWarnings("unchecked")
public List<DisplayNameEntry> getDisplayNameEntries(String baseDn, List<String> dns) {
    List<String> inums = getInumsFromDns(dns);
    if (inums.size() == 0) {
        return null;
    }
    String key = getCompoundKey(inums);
    List<DisplayNameEntry> entries = (List<DisplayNameEntry>) cacheService.get(OxConstants.CACHE_LOOKUP_NAME, key);
    if (entries == null) {
        Filter searchFilter = buildInumFilter(inums);
        entries = ldapEntryManager.findEntries(baseDn, DisplayNameEntry.class, searchFilter);
        cacheService.put(OxConstants.CACHE_LOOKUP_NAME, key, entries);
    }
    return entries;
}
Also used : Filter(com.unboundid.ldap.sdk.Filter) ArrayList(java.util.ArrayList) List(java.util.List) DisplayNameEntry(org.xdi.model.DisplayNameEntry)

Example 20 with Filter

use of com.unboundid.ldap.sdk.Filter in project oxTrust by GluuFederation.

the class GroupService method searchGroups.

/* (non-Javadoc)
	 * @see org.gluu.oxtrust.ldap.service.IGroupService#searchGroups(java.lang.String, int)
	 */
@Override
public List<GluuGroup> searchGroups(String pattern, int sizeLimit) throws Exception {
    String[] targetArray = new String[] { pattern };
    Filter displayNameFilter = Filter.createSubstringFilter(OxTrustConstants.displayName, null, targetArray, null);
    Filter descriptionFilter = Filter.createSubstringFilter(OxTrustConstants.description, null, targetArray, null);
    Filter inameFilter = Filter.createSubstringFilter(OxTrustConstants.iname, null, targetArray, null);
    Filter searchFilter = Filter.createORFilter(displayNameFilter, descriptionFilter, inameFilter);
    List<GluuGroup> result = ldapEntryManager.findEntries(getDnForGroup(null), GluuGroup.class, searchFilter, 0, sizeLimit);
    return result;
}
Also used : Filter(com.unboundid.ldap.sdk.Filter) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Aggregations

Filter (com.unboundid.ldap.sdk.Filter)61 ArrayList (java.util.ArrayList)21 LDAPException (com.unboundid.ldap.sdk.LDAPException)9 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)6 LdapEntryManager (org.gluu.site.ldap.persistence.LdapEntryManager)6 LinkedHashSet (java.util.LinkedHashSet)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)4 GluuAttribute (org.xdi.model.GluuAttribute)4 ScopeDescription (org.xdi.oxauth.model.uma.persistence.ScopeDescription)4 List (java.util.List)3 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)3 HashSet (java.util.HashSet)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)2 GluuCustomFidoDevice (org.gluu.oxtrust.model.fido.GluuCustomFidoDevice)2 DEFAULT_COUNT (org.gluu.oxtrust.model.scim2.Constants.DEFAULT_COUNT)2 CustomAttribute (org.xdi.ldap.model.CustomAttribute)2 LdapDummyEntry (org.xdi.ldap.model.LdapDummyEntry)2 SortOrder (org.xdi.ldap.model.SortOrder)2