use of com.novell.ldap.LDAPAttribute in project ldapchai by ldapchai.
the class JLDAPProviderImpl method readMultiStringAttribute.
@ChaiProvider.LdapOperation
public Set<String> readMultiStringAttribute(final String entryDN, final String attribute) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().readMultiStringAttribute(entryDN, attribute);
try {
final LDAPEntry entry = ldapConnection.read(entryDN, new String[] { attribute });
final LDAPAttribute ldapAttribute = entry.getAttribute(attribute);
if (ldapAttribute == null) {
return Collections.emptySet();
} else {
return new HashSet<String>(Arrays.asList(ldapAttribute.getStringValueArray()));
}
} catch (LDAPException e) {
throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
}
}
use of com.novell.ldap.LDAPAttribute in project ldapchai by ldapchai.
the class JLDAPProviderImpl method searchImpl.
public Map<String, Map<String, List<String>>> searchImpl(final String baseDN, final SearchHelper searchHelper, final boolean onlyFirstValue) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
// make a copy so if it changes somewhere else we won't be affected.
final SearchHelper effectiveSearchHelper = new SearchHelper(searchHelper);
// replace a null dn with an empty string
final String effectiveBaseDN = baseDN != null ? baseDN : "";
final int ldapScope;
switch(effectiveSearchHelper.getSearchScope()) {
case ONE:
ldapScope = LDAPConnection.SCOPE_ONE;
break;
case BASE:
ldapScope = LDAPConnection.SCOPE_BASE;
break;
case SUBTREE:
ldapScope = LDAPConnection.SCOPE_SUB;
break;
default:
ldapScope = -1;
}
final Map<String, Map<String, List<String>>> returnMap = new LinkedHashMap<>();
final LDAPSearchConstraints constraints = new LDAPSearchConstraints();
constraints.setMaxResults(effectiveSearchHelper.getMaxResults());
constraints.setTimeLimit(effectiveSearchHelper.getTimeLimit());
final String[] returnAttributes = effectiveSearchHelper.getAttributes() == null ? null : effectiveSearchHelper.getAttributes().toArray(new String[effectiveSearchHelper.getAttributes().size()]);
final LDAPSearchResults results;
try {
results = ldapConnection.search(effectiveBaseDN, ldapScope, effectiveSearchHelper.getFilter(), returnAttributes, false, constraints);
while (results.hasMore()) {
final LDAPEntry loopEntry = results.next();
final String loopDN = loopEntry.getDN();
final Map<String, List<String>> loopAttributes = new LinkedHashMap<>();
final LDAPAttributeSet attrSet = loopEntry.getAttributeSet();
for (final Object anAttrSet : attrSet) {
final LDAPAttribute loopAttr = (LDAPAttribute) anAttrSet;
if (onlyFirstValue) {
loopAttributes.put(loopAttr.getName(), Collections.singletonList(loopAttr.getStringValue()));
} else {
loopAttributes.put(loopAttr.getName(), Arrays.asList(loopAttr.getStringValueArray()));
}
}
returnMap.put(loopDN, loopAttributes);
}
} catch (LDAPException e) {
if (!returnMap.isEmpty()) {
return Collections.unmodifiableMap(returnMap);
}
throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
}
return Collections.unmodifiableMap(returnMap);
}
use of com.novell.ldap.LDAPAttribute in project ldapchai by ldapchai.
the class JLDAPProviderImpl method readStringAttributes.
@ChaiProvider.LdapOperation
public Map<String, String> readStringAttributes(final String entryDN, final Set<String> attributes) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().readStringAttributes(entryDN, attributes);
final Map<String, String> returnProps = new LinkedHashMap<>();
try {
final LDAPEntry entry = ldapConnection.read(entryDN, attributes.toArray(new String[attributes.size()]));
for (final Object attr : entry.getAttributeSet()) {
final LDAPAttribute lAttr = (LDAPAttribute) attr;
returnProps.put(lAttr.getName(), lAttr.getStringValue());
}
return returnProps;
} catch (LDAPException e) {
throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
}
}
use of com.novell.ldap.LDAPAttribute in project ldapchai by ldapchai.
the class JLDAPProviderImpl method readMultiByteAttribute.
@ChaiProvider.LdapOperation
public byte[][] readMultiByteAttribute(final String entryDN, final String attribute) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().readMultiByteAttribute(entryDN, attribute);
try {
final LDAPEntry entry = ldapConnection.read(entryDN, new String[] { attribute });
final LDAPAttribute ldapAttribute = entry.getAttribute(attribute);
return ldapAttribute != null ? ldapAttribute.getByteValueArray() : new byte[0][0];
} catch (LDAPException e) {
throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
}
}
Aggregations