Search in sources :

Example 16 with Filter

use of org.gluu.search.filter.Filter in project oxTrust by GluuFederation.

the class SectorIdentifierService method searchSectorIdentifiers.

/**
 * Search sector identifiers by pattern
 *
 * @param pattern   Pattern
 * @param sizeLimit Maximum count of results
 * @return List of sector identifiers
 */
public List<OxAuthSectorIdentifier> searchSectorIdentifiers(String pattern, int sizeLimit) {
    String[] targetArray = new String[] { pattern };
    Filter searchFilter = Filter.createSubstringFilter(OxTrustConstants.oxId, null, targetArray, null);
    List<OxAuthSectorIdentifier> result = ldapEntryManager.findEntries(getDnForSectorIdentifier(null), OxAuthSectorIdentifier.class, searchFilter, sizeLimit);
    return result;
}
Also used : OxAuthSectorIdentifier(org.gluu.oxtrust.model.OxAuthSectorIdentifier) Filter(org.gluu.search.filter.Filter)

Example 17 with Filter

use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.

the class LdapSampleBatchJob method main.

public static void main(String[] args) {
    // Prepare sample connection details
    LdapSampleEntryManager ldapSampleEntryManager = new LdapSampleEntryManager();
    // Create LDAP entry manager
    final LdapEntryManager ldapEntryManager = ldapSampleEntryManager.createLdapEntryManager();
    BatchOperation<SimpleTokenLdap> tokenLdapBatchOperation = new ProcessBatchOperation<SimpleTokenLdap>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleTokenLdap> objects) {
            for (SimpleTokenLdap simpleTokenLdap : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(ldapEntryManager, "oxAuthExpiration", simpleTokenLdap.getAttribute("oxAuthExpiration"));
                    simpleTokenLdap.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    ldapEntryManager.merge(simpleTokenLdap);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter1 = Filter.createPresenceFilter("oxAuthExpiration");
    ldapEntryManager.findEntries("o=gluu", SimpleTokenLdap.class, filter1, SearchScope.SUB, new String[] { "oxAuthExpiration" }, tokenLdapBatchOperation, 0, 0, 100);
    BatchOperation<SimpleSession> sessionBatchOperation = new ProcessBatchOperation<SimpleSession>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleSession> objects) {
            for (SimpleSession simpleSession : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(ldapEntryManager, "oxLastAccessTime", simpleSession.getAttribute("oxLastAccessTime"));
                    simpleSession.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    ldapEntryManager.merge(simpleSession);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter2 = Filter.createPresenceFilter("oxLastAccessTime");
    ldapEntryManager.findEntries("o=gluu", SimpleSession.class, filter2, SearchScope.SUB, new String[] { "oxLastAccessTime" }, sessionBatchOperation, 0, 0, 100);
    BatchOperation<SimpleClient> clientBatchOperation = new ProcessBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter3 = Filter.createPresenceFilter("oxAuthClientSecretExpiresAt");
    List<SimpleClient> result3 = ldapEntryManager.findEntries("o=gluu", SimpleClient.class, filter3, SearchScope.SUB, new String[] { "oxAuthClientSecretExpiresAt" }, clientBatchOperation, 0, 0, 1000);
    LOG.info("Result count (without collecting results): " + result3.size());
    BatchOperation<SimpleClient> clientBatchOperation2 = new DefaultBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter4 = Filter.createPresenceFilter("oxAuthClientSecretExpiresAt");
    List<SimpleClient> result4 = ldapEntryManager.findEntries("o=gluu", SimpleClient.class, filter4, SearchScope.SUB, new String[] { "oxAuthClientSecretExpiresAt" }, clientBatchOperation2, 0, 0, 1000);
    LOG.info("Result count (with collecting results): " + result4.size());
}
Also used : SimpleTokenLdap(org.gluu.ldap.model.SimpleTokenLdap) CustomAttribute(org.gluu.persist.model.base.CustomAttribute) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) DefaultBatchOperation(org.gluu.persist.model.DefaultBatchOperation) LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) Filter(org.gluu.search.filter.Filter) ProcessBatchOperation(org.gluu.persist.model.ProcessBatchOperation) List(java.util.List) SimpleClient(org.gluu.ldap.model.SimpleClient) SimpleSession(org.gluu.ldap.model.SimpleSession)

Example 18 with Filter

use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.

the class BaseEntryManager method createAttributesFilter.

protected Filter[] createAttributesFilter(List<AttributeData> attributes) {
    if ((attributes == null) || (attributes.size() == 0)) {
        return null;
    }
    List<Filter> results = new ArrayList<Filter>(attributes.size());
    for (AttributeData attribute : attributes) {
        String attributeName = attribute.getName();
        for (String value : attribute.getValues()) {
            Filter filter = Filter.createEqualityFilter(attributeName, value);
            results.add(filter);
        }
    }
    return results.toArray(new Filter[results.size()]);
}
Also used : Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList) AttributeData(org.gluu.persist.model.AttributeData)

Example 19 with Filter

use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.

the class BaseEntryManager method addObjectClassFilter.

protected Filter addObjectClassFilter(Filter filter, String[] objectClasses) {
    if (objectClasses.length == 0) {
        return filter;
    }
    Filter[] objectClassFilter = new Filter[objectClasses.length];
    for (int i = 0; i < objectClasses.length; i++) {
        objectClassFilter[i] = Filter.createEqualityFilter(OBJECT_CLASS, objectClasses[i]);
    }
    Filter searchFilter = Filter.createANDFilter(objectClassFilter);
    if (filter != null) {
        searchFilter = Filter.createANDFilter(Filter.createANDFilter(objectClassFilter), filter);
    }
    return searchFilter;
}
Also used : Filter(org.gluu.search.filter.Filter)

Example 20 with Filter

use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.

the class BaseEntryManager method createFilterByEntry.

protected <T> Filter createFilterByEntry(Object entry, Class<T> entryClass, List<AttributeData> attributes) {
    Filter[] attributesFilters = createAttributesFilter(attributes);
    Filter attributesFilter = null;
    if (attributesFilters != null) {
        attributesFilter = Filter.createANDFilter(attributesFilters);
    }
    String[] objectClasses = getCustomObjectClasses(entry, entryClass);
    return addObjectClassFilter(attributesFilter, objectClasses);
}
Also used : Filter(org.gluu.search.filter.Filter)

Aggregations

Filter (org.gluu.search.filter.Filter)122 ArrayList (java.util.ArrayList)34 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)9 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)7 MappingException (org.gluu.persist.exception.mapping.MappingException)7 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)6 SearchException (org.gluu.persist.exception.operation.SearchException)6 List (java.util.List)5 GluuAttribute (org.gluu.model.GluuAttribute)5 PropertyAnnotation (org.gluu.persist.model.PropertyAnnotation)5 SearchResult (com.unboundid.ldap.sdk.SearchResult)4 ParseException (java.text.ParseException)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)4 PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)4 AuthenticationException (org.gluu.persist.exception.operation.AuthenticationException)4 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)4 SearchScopeException (org.gluu.persist.exception.operation.SearchScopeException)4 GluuAttribute (org.xdi.model.GluuAttribute)4 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)3 Date (java.util.Date)3