use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class BaseEntryManager method getEntrySortByProperties.
protected String[] getEntrySortByProperties(Class<?> entryClass) {
if (entryClass == null) {
throw new MappingException("Entry class is null");
}
// Check if entry is LDAP Entry
List<Annotation> entryAnnotations = ReflectHelper.getClassAnnotations(entryClass, LDAP_ENTRY_TYPE_ANNOTATIONS);
Annotation annotation = ReflectHelper.getAnnotationByType(entryAnnotations, DataEntry.class);
if (annotation == null) {
return null;
}
return ((DataEntry) annotation).sortBy();
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class BaseEntryManager method getEntrySortByNames.
protected String[] getEntrySortByNames(Class<?> entryClass) {
if (entryClass == null) {
throw new MappingException("Entry class is null");
}
// Check if entry is LDAP Entry
List<Annotation> entryAnnotations = ReflectHelper.getClassAnnotations(entryClass, LDAP_ENTRY_TYPE_ANNOTATIONS);
Annotation annotation = ReflectHelper.getAnnotationByType(entryAnnotations, DataEntry.class);
if (annotation == null) {
return null;
}
return ((DataEntry) annotation).sortByName();
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class SpannerEntryManager method createEntities.
protected <T> List<T> createEntities(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, ParsedKey baseDn, EntryData... searchResultEntries) {
List<T> result = new ArrayList<T>(searchResultEntries.length);
Map<String, List<AttributeData>> entriesAttributes = new LinkedHashMap<String, List<AttributeData>>(100);
int count = 0;
for (int i = 0; i < searchResultEntries.length; i++) {
count++;
EntryData entryData = searchResultEntries[i];
AttributeData attributeDataDn = entryData.getAttributeDate(SpannerOperationService.DN);
if ((attributeDataDn == null) || (attributeDataDn.getValue() == null)) {
throw new MappingException("Failed to convert EntryData to Entry because DN is missing");
}
entriesAttributes.put(attributeDataDn.getValue().toString(), entryData.getAttributeData());
// Remove reference to allow java clean up object
searchResultEntries[i] = null;
// Allow java to clean up temporary objects
if (count >= 100) {
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
result.addAll(currentResult);
entriesAttributes = new LinkedHashMap<String, List<AttributeData>>(100);
count = 0;
}
}
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
result.addAll(currentResult);
return result;
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class LdapEntryManager method findEntries.
@Override
public <T> List<T> findEntries(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope, String[] ldapReturnAttributes, BatchOperation<T> batchOperation, int start, int count, int chunkSize) {
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 {
LdapBatchOperationWraper<T> batchOperationWraper = new LdapBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
searchResult = getOperationService().search(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(scope), batchOperationWraper, start, chunkSize, count, null, currentLdapReturnAttributes);
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter));
}
if (searchResult.getEntryCount() == 0) {
return new ArrayList<T>(0);
}
List<T> entries = createEntities(entryClass, propertiesAnnotations, searchResult.getSearchEntries().toArray(new SearchResultEntry[searchResult.getSearchEntries().size()]));
// Default sort if needed
sortEntriesIfNeeded(entryClass, entries);
return entries;
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class LdapEntryManager 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 count entries is null");
}
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
// Find entries
Filter searchFilter = Filter.createEqualityFilter(LdapOperationService.UID, userName);
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(searchFilter, objectClasses);
}
SearchScope scope = SearchScope.SUB;
try {
SearchResult searchResult = getOperationService().search(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(scope), null, 0, 1, 1, null, LdapOperationService.UID_ARRAY);
if ((searchResult == null) || (searchResult.getEntryCount() != 1)) {
return false;
}
String bindDn = searchResult.getSearchEntries().get(0).getDN();
return getOperationService().authenticate(bindDn, password, null);
} catch (ConnectionException ex) {
throw new AuthenticationException(String.format("Failed to authenticate user: %s", userName), ex);
} catch (SearchScopeException ex) {
throw new AuthenticationException(String.format("Failed to convert scope: %s", scope), ex);
} catch (SearchException ex) {
throw new AuthenticationException(String.format("Failed to find user DN: %s", userName), ex);
}
}
Aggregations