use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.
the class LdapEntryManager method findListViewResponse.
@Override
public <T> ListViewResponse<T> findListViewResponse(String baseDN, Class<T> entryClass, Filter filter, int startIndex, int count, int chunkSize, String sortBy, SortOrder sortOrder, String[] ldapReturnAttributes) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to find entries is null");
}
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
String[] currentLdapReturnAttributes = ldapReturnAttributes;
if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
currentLdapReturnAttributes = getLdapAttributes(null, propertiesAnnotations, false);
}
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
SearchResult searchResult = null;
ListViewResponse<T> vlvResponse = new ListViewResponse<T>();
try {
searchResult = this.ldapOperationService.searchSearchResult(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), startIndex, count, chunkSize, sortBy, sortOrder, vlvResponse, currentLdapReturnAttributes);
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
if (searchResult.getEntryCount() == 0) {
vlvResponse.setResult(new ArrayList<T>(0));
return vlvResponse;
}
List<T> entries = createEntitiesVirtualListView(entryClass, propertiesAnnotations, searchResult.getSearchEntries().toArray(new SearchResultEntry[searchResult.getSearchEntries().size()]));
vlvResponse.setResult(entries);
return vlvResponse;
}
use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.
the class LdapEntryManager method contains.
@Override
protected boolean contains(String baseDN, Filter filter, String[] objectClasses, String[] ldapReturnAttributes) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to check contain entries is null");
}
// Create filter
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
SearchResult searchResult = null;
try {
searchResult = this.ldapOperationService.search(baseDN, toLdapFilter(searchFilter), 1, 1, null, ldapReturnAttributes);
if ((searchResult == null) || !ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (SearchException ex) {
if (!(ResultCode.NO_SUCH_OBJECT_INT_VALUE == ex.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
}
return (searchResult != null) && (searchResult.getEntryCount() > 0);
}
use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.
the class LdapFilterConverter method convertToLdapFilter.
public com.unboundid.ldap.sdk.Filter convertToLdapFilter(Filter genericFilter) throws SearchException {
FilterType type = genericFilter.getType();
if (FilterType.RAW == type) {
try {
return com.unboundid.ldap.sdk.Filter.create(genericFilter.getFilterString());
} catch (com.unboundid.ldap.sdk.LDAPException ex) {
throw new SearchException("Failed to parse RAW Ldap filter", ex, ex.getResultCode().intValue());
}
}
if ((FilterType.NOT == type) || (FilterType.AND == type) || (FilterType.OR == type)) {
Filter[] genericFilters = genericFilter.getFilters();
com.unboundid.ldap.sdk.Filter[] ldapFilters = new com.unboundid.ldap.sdk.Filter[genericFilters.length];
if (genericFilters != null) {
for (int i = 0; i < genericFilters.length; i++) {
ldapFilters[i] = convertToLdapFilter(genericFilters[i]);
}
if (FilterType.NOT == type) {
return com.unboundid.ldap.sdk.Filter.createNOTFilter(ldapFilters[0]);
} else if (FilterType.AND == type) {
return com.unboundid.ldap.sdk.Filter.createANDFilter(ldapFilters);
} else if (FilterType.OR == type) {
return com.unboundid.ldap.sdk.Filter.createORFilter(ldapFilters);
}
}
}
if (FilterType.EQUALITY == type) {
return com.unboundid.ldap.sdk.Filter.createEqualityFilter(genericFilter.getAttributeName(), genericFilter.getAssertionValue());
}
if (FilterType.LESS_OR_EQUAL == type) {
return com.unboundid.ldap.sdk.Filter.createLessOrEqualFilter(genericFilter.getAttributeName(), genericFilter.getAssertionValue());
}
if (FilterType.GREATER_OR_EQUAL == type) {
return com.unboundid.ldap.sdk.Filter.createGreaterOrEqualFilter(genericFilter.getAttributeName(), genericFilter.getAssertionValue());
}
if (FilterType.PRESENCE == type) {
return com.unboundid.ldap.sdk.Filter.createPresenceFilter(genericFilter.getAttributeName());
}
if (FilterType.APPROXIMATE_MATCH == type) {
return com.unboundid.ldap.sdk.Filter.createApproximateMatchFilter(genericFilter.getAttributeName(), genericFilter.getAssertionValue());
}
if (FilterType.SUBSTRING == type) {
return com.unboundid.ldap.sdk.Filter.createSubstringFilter(genericFilter.getAttributeName(), genericFilter.getSubInitial(), genericFilter.getSubAny(), genericFilter.getSubFinal());
}
throw new SearchException(String.format("Unknown filter type '%s'", type), com.unboundid.ldap.sdk.ResultCode.PROTOCOL_ERROR_INT_VALUE);
}
use of org.gluu.search.filter.Filter in project oxTrust by GluuFederation.
the class AsimbaService method searchRequestors.
/**
* Search by pattern
*
* @param pattern Pattern
* @param sizeLimit Maximum count of results
* @return List of scopes
* @throws Exception
*/
public List<RequestorEntry> searchRequestors(String pattern, int sizeLimit) throws Exception {
// filter
String[] targetArray = new String[] { pattern };
Filter idFilter = Filter.createSubstringFilter(OxTrustConstants.uniqueIdentifier, null, targetArray, null);
Filter friendlyNameFilter = Filter.createSubstringFilter(OxTrustConstants.friendlyName, 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(idFilter, friendlyNameFilter, descriptionFilter, inameFilter);
// search
List<LDAPRequestorEntry> entries = ldapEntryManager.findEntries(getDnForLDAPRequestorEntry(null), LDAPRequestorEntry.class, searchFilter, sizeLimit);
// convert result
List<RequestorEntry> ret = new ArrayList<RequestorEntry>();
for (LDAPRequestorEntry entry : entries) {
ret.add(entry.getEntry());
}
return ret;
}
use of org.gluu.search.filter.Filter in project oxTrust by GluuFederation.
the class AsimbaService method searchRequestorPools.
/**
* Search by pattern
*
* @param pattern Pattern
* @param sizeLimit Maximum count of results
* @return List of scopes
* @throws Exception
*/
public List<RequestorPoolEntry> searchRequestorPools(String pattern, int sizeLimit) throws Exception {
// filter
String[] targetArray = new String[] { pattern };
Filter idFilter = Filter.createSubstringFilter(OxTrustConstants.uniqueIdentifier, null, targetArray, null);
Filter friendlyNameFilter = Filter.createSubstringFilter(OxTrustConstants.friendlyName, 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(idFilter, friendlyNameFilter, descriptionFilter, inameFilter);
// search
List<LDAPRequestorPoolEntry> entries = ldapEntryManager.findEntries(getDnForLDAPRequestorPoolEntry(null), LDAPRequestorPoolEntry.class, searchFilter, sizeLimit);
// convert result
List<RequestorPoolEntry> ret = new ArrayList<RequestorPoolEntry>();
for (LDAPRequestorPoolEntry entry : entries) {
ret.add(entry.getEntry());
}
return ret;
}
Aggregations