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