use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class RegistrationPersistenceService method getExpiredRegistrationFilter.
private Filter getExpiredRegistrationFilter(String baseDn) {
int unfinishedRequestExpiration = appConfiguration.getFido2Configuration().getUnfinishedRequestExpiration();
unfinishedRequestExpiration = unfinishedRequestExpiration == 0 ? 120 : unfinishedRequestExpiration;
Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
calendar.add(Calendar.SECOND, -unfinishedRequestExpiration);
final Date unfinishedRequestExpirationDate = calendar.getTime();
// Build unfinished request expiration filter
Filter registrationStatusFilter = Filter.createNOTFilter(Filter.createEqualityFilter("jansStatus", Fido2RegistrationStatus.registered.getValue()));
Filter compomisedStatusFilter = Filter.createNOTFilter(Filter.createEqualityFilter("jansStatus", Fido2RegistrationStatus.compromised.getValue()));
Filter exirationDateFilter = Filter.createLessOrEqualFilter("creationDate", persistenceEntryManager.encodeTime(baseDn, unfinishedRequestExpirationDate));
Filter unfinishedRequestFilter = Filter.createANDFilter(registrationStatusFilter, compomisedStatusFilter, exirationDateFilter);
return unfinishedRequestFilter;
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class LdapEntryManager method findEntriesVirtualListView.
@Deprecated
public <T> List<T> findEntriesVirtualListView(String baseDN, Class<T> entryClass, Filter filter, int start, int count, String sortBy, SortOrder sortOrder, PagedResult vlvResponse, 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 = getAttributes(null, propertiesAnnotations, false);
}
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
SearchResult searchResult = null;
try {
searchResult = getOperationService().searchVirtualListView(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), start, count, 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) {
return new ArrayList<T>(0);
}
List<T> entries = createEntitiesVirtualListView(entryClass, propertiesAnnotations, searchResult.getSearchEntries().toArray(new SearchResultEntry[searchResult.getSearchEntries().size()]));
return entries;
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class LdapEntryManager 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 count entries is null");
}
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
SearchScope searchScope = scope;
if (searchScope == null) {
searchScope = SearchScope.SUB;
}
String[] ldapReturnAttributes;
CountBatchOperation<T> batchOperation;
if (SearchScope.BASE == searchScope) {
// Don't load attributes
ldapReturnAttributes = new String[] { "numsubordinates" };
batchOperation = null;
} else {
// Don't load attributes
ldapReturnAttributes = new String[] { "" };
batchOperation = new CountBatchOperation<T>();
}
SearchResult searchResult;
try {
LdapBatchOperationWraper<T> batchOperationWraper = null;
if (batchOperation != null) {
batchOperationWraper = new LdapBatchOperationWraper<T>(batchOperation);
}
searchResult = getOperationService().search(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(searchScope), batchOperationWraper, 0, 100, 0, null, ldapReturnAttributes);
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to calculate the number of entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
if (SearchScope.BASE != searchScope) {
return batchOperation.getCountEntries();
}
if (searchResult.getEntryCount() != 1) {
throw new EntryPersistenceException(String.format("Failed to calculate the number of entries due to missing result entry with baseDN: %s, filter: %s", baseDN, searchFilter));
}
Long result = searchResult.getSearchEntries().get(0).getAttributeValueAsLong("numsubordinates");
if (result == null) {
throw new EntryPersistenceException(String.format("Failed to calculate the number of entries due to missing attribute 'numsubordinates' with baseDN: %s, filter: %s", baseDN, searchFilter));
}
return result.intValue();
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class LdapEntryManager method remove.
@Override
public <T> int remove(String baseDN, Class<T> entryClass, Filter filter, int count) {
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;
}
DeleteBatchOperation batchOperation = new DeleteBatchOperation<T>(this);
SearchResult searchResult = null;
try {
LdapBatchOperationWraper<T> batchOperationWraper = new LdapBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
searchResult = getOperationService().search(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), batchOperationWraper, 0, 100, count, null, LdapOperationService.DN);
} catch (Exception ex) {
throw new EntryDeleteException(String.format("Failed to delete entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryDeleteException(String.format("Failed to delete entries with baseDN: %s, filter: %s", baseDN, searchFilter));
}
return batchOperation.getCountEntries();
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
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) {
String attributeName;
if (ArrayHelper.isEmpty(genericFilter.getFilters())) {
attributeName = genericFilter.getAttributeName();
} else {
attributeName = convertToLdapFilter(genericFilter.getFilters()[0]).getAttributeName();
}
return com.unboundid.ldap.sdk.Filter.createEqualityFilter(attributeName, String.valueOf(genericFilter.getAssertionValue()));
}
if (FilterType.LESS_OR_EQUAL == type) {
return com.unboundid.ldap.sdk.Filter.createLessOrEqualFilter(genericFilter.getAttributeName(), String.valueOf(genericFilter.getAssertionValue()));
}
if (FilterType.GREATER_OR_EQUAL == type) {
return com.unboundid.ldap.sdk.Filter.createGreaterOrEqualFilter(genericFilter.getAttributeName(), String.valueOf(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(), String.valueOf(genericFilter.getAssertionValue()));
}
if (FilterType.SUBSTRING == type) {
return com.unboundid.ldap.sdk.Filter.createSubstringFilter(genericFilter.getAttributeName(), genericFilter.getSubInitial(), genericFilter.getSubAny(), genericFilter.getSubFinal());
}
if (FilterType.LOWERCASE == type) {
// Return Dummy filter because case sensitivity is defined at LDAP schema level
return com.unboundid.ldap.sdk.Filter.createPresenceFilter(genericFilter.getAttributeName());
}
throw new SearchException(String.format("Unknown filter type '%s'", type), com.unboundid.ldap.sdk.ResultCode.PROTOCOL_ERROR_INT_VALUE);
}
Aggregations