use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class NativePersistenceCacheProvider method cleanup.
public void cleanup(final Date now, int batchSize) {
log.debug("Start NATIVE_PERSISTENCE clean up");
try {
Filter filter = Filter.createANDFilter(Filter.createEqualityFilter("del", true), Filter.createLessOrEqualFilter("exp", entryManager.encodeTime(baseDn, now)));
final int removedCount = entryManager.remove(baseDn, NativePersistenceCacheEntity.class, filter, batchSize);
log.debug("End NATIVE_PERSISTENCE clean up, items removed: " + removedCount);
} catch (Exception e) {
log.error("Failed to perform clean up.", e);
}
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class UmaResourceService method findResources.
public List<UmaResource> findResources(String pattern, int sizeLimit) {
String[] targetArray = new String[] { pattern };
Filter jsIdFilter = Filter.createSubstringFilter("jansId", null, targetArray, null);
Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null, targetArray, null);
Filter searchFilter = Filter.createORFilter(jsIdFilter, displayNameFilter);
return persistenceEntryManager.findEntries(getDnForResource(null), UmaResource.class, searchFilter, sizeLimit);
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class CouchbaseEntryManager method contains.
@Override
protected <T> boolean contains(String baseDN, String[] objectClasses, Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, Filter filter, 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;
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ConvertedExpression convertedExpression;
try {
convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
}
PagedResult<JsonObject> searchResult = null;
try {
ParsedKey keyWithInum = toCouchbaseKey(baseDN);
searchResult = searchImpl(keyWithInum.getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), SearchScope.SUB, ldapReturnAttributes, null, null, SearchReturnDataType.SEARCH, 1, 1, 0);
if (searchResult == null) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
return (searchResult != null) && (searchResult.getEntriesCount() > 0);
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class CouchbaseEntryManager method countEntries.
@Override
public <T> int countEntries(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope) {
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);
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ConvertedExpression convertedExpression;
try {
convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
}
PagedResult<JsonObject> searchResult;
try {
searchResult = searchImpl(toCouchbaseKey(baseDN).getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), scope, null, null, null, SearchReturnDataType.COUNT, 0, 0, 0);
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to calculate the number of entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
return searchResult.getTotalEntriesCount();
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class CouchbaseEntryManager method authenticate.
@Override
public <T> boolean authenticate(String baseDN, Class<T> entryClass, String userName, String password) {
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);
// Find entries
Filter searchFilter = Filter.createEqualityFilter(Filter.createLowercaseFilter(CouchbaseOperationService.UID), StringHelper.toLowerCase(userName));
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(searchFilter, objectClasses);
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ConvertedExpression convertedExpression;
try {
convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
}
try {
PagedResult<JsonObject> searchResult = searchImpl(toCouchbaseKey(baseDN).getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), SearchScope.SUB, CouchbaseOperationService.UID_ARRAY, null, null, SearchReturnDataType.SEARCH, 0, 1, 1);
if ((searchResult == null) || (searchResult.getEntriesCount() != 1)) {
return false;
}
String bindDn = searchResult.getEntries().get(0).getString(CouchbaseOperationService.DN);
return authenticate(bindDn, password);
} catch (SearchException ex) {
throw new AuthenticationException(String.format("Failed to find user DN: %s", userName), ex);
} catch (Exception ex) {
throw new AuthenticationException(String.format("Failed to authenticate user: %s", userName), ex);
}
}
Aggregations