Search in sources :

Example 91 with Filter

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

the class CacheRefreshTimer method loadSourceServerEntriesWithoutLimits.

private List<GluuSimplePerson> loadSourceServerEntriesWithoutLimits(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection[] sourceServerConnections) throws SearchException {
    Filter customFilter = cacheRefreshService.createFilter(cacheRefreshConfiguration.getCustomLdapFilter());
    String[] keyAttributes = getCompoundKeyAttributes(cacheRefreshConfiguration);
    String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
    String[] keyObjectClasses = getCompoundKeyObjectClasses(cacheRefreshConfiguration);
    String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
    String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
    Set<String> addedDns = new HashSet<String>();
    List<GluuSimplePerson> sourcePersons = new ArrayList<GluuSimplePerson>();
    for (LdapServerConnection sourceServerConnection : sourceServerConnections) {
        String sourceServerName = sourceServerConnection.getSourceServerName();
        PersistenceEntryManager sourcePersistenceEntryManager = sourceServerConnection.getPersistenceEntryManager();
        String[] baseDns = sourceServerConnection.getBaseDns();
        Filter filter = cacheRefreshService.createFilter(keyAttributes, keyObjectClasses, "", customFilter);
        if (log.isTraceEnabled()) {
            log.trace("Using next filter to load entris from source server: {}", filter);
        }
        for (String baseDn : baseDns) {
            List<GluuSimplePerson> currentSourcePersons = sourcePersistenceEntryManager.findEntries(baseDn, GluuSimplePerson.class, filter, SearchScope.SUB, returnAttributes, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
            // Add to result and ignore root entry if needed
            for (GluuSimplePerson currentSourcePerson : currentSourcePersons) {
                currentSourcePerson.setSourceServerName(sourceServerName);
                // if (!StringHelper.equalsIgnoreCase(baseDn,
                // currentSourcePerson.getDn())) {
                String currentSourcePersonDn = currentSourcePerson.getDn().toLowerCase();
                if (!addedDns.contains(currentSourcePersonDn)) {
                    sourcePersons.add(currentSourcePerson);
                    addedDns.add(currentSourcePersonDn);
                }
            // }
            }
        }
    }
    return sourcePersons;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 92 with Filter

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

the class PasswordResetService method getExpiredPasswordResetRequests.

public List<PasswordResetRequest> getExpiredPasswordResetRequests(BatchOperation<PasswordResetRequest> batchOperation, Date expirationDate, String[] returnAttributes, int sizeLimit, int chunkSize) {
    final String baseDn = getDnForPasswordResetRequest(null);
    Filter expirationFilter = Filter.createLessOrEqualFilter("creationDate", ldapEntryManager.encodeTime(baseDn, expirationDate));
    List<PasswordResetRequest> passwordResetRequests = ldapEntryManager.findEntries(baseDn, PasswordResetRequest.class, expirationFilter, SearchScope.SUB, returnAttributes, batchOperation, 0, sizeLimit, chunkSize);
    return passwordResetRequests;
}
Also used : PasswordResetRequest(org.gluu.oxtrust.model.PasswordResetRequest) Filter(org.gluu.search.filter.Filter)

Example 93 with Filter

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

the class PushDeviceService method findPushDevices.

/**
 * Search oxPush devices by pattern
 *
 * @param pattern Pattern
 * @param sizeLimit Maximum count of results
 * @return List of oxPush devices
 */
public List<PushDevice> findPushDevices(String pattern, int sizeLimit) {
    String[] targetArray = new String[] { pattern };
    Filter oxIdFilter = Filter.createSubstringFilter("oxId", null, targetArray, null);
    Filter oxTypeFilter = Filter.createSubstringFilter("oxType", null, targetArray, null);
    Filter oxAuthUserIdFilter = Filter.createSubstringFilter("oxAuthUserId", null, targetArray, null);
    Filter searchFilter = Filter.createORFilter(oxIdFilter, oxTypeFilter, oxAuthUserIdFilter);
    List<PushDevice> result = ldapEntryManager.findEntries(getDnForPushDevice(null), PushDevice.class, searchFilter, sizeLimit);
    return result;
}
Also used : Filter(org.gluu.search.filter.Filter) PushDevice(org.gluu.oxtrust.model.push.PushDevice)

Example 94 with Filter

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

the class FidoDeviceService method getGluuCustomFidoDeviceById.

@Override
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("oxId", 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(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) Filter(org.gluu.search.filter.Filter)

Example 95 with Filter

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

the class GroupService method isMemberOrOwner.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.gluu.oxtrust.ldap.service.IGroupService#isMemberOrOwner(java.lang.String,
	 * java.lang.String)
	 */
@Override
public boolean isMemberOrOwner(String groupDN, String personDN) {
    Filter ownerFilter = Filter.createEqualityFilter(OxTrustConstants.owner, personDN);
    Filter memberFilter = Filter.createEqualityFilter(OxTrustConstants.member, personDN);
    Filter searchFilter = Filter.createORFilter(ownerFilter, memberFilter);
    boolean isMemberOrOwner = false;
    try {
        isMemberOrOwner = persistenceEntryManager.findEntries(groupDN, GluuGroup.class, searchFilter, 1).size() > 0;
    } catch (EntryPersistenceException ex) {
        log.error("Failed to determine if person '{}' memeber or owner of group '{}'", personDN, groupDN, ex);
    }
    return isMemberOrOwner;
}
Also used : Filter(org.gluu.search.filter.Filter) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

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