use of com.novell.ldap.LDAPAttributeSet in project ldapchai by ldapchai.
the class JLDAPProviderImpl method createEntry.
@ChaiProvider.LdapOperation
@ChaiProvider.ModifyOperation
public void createEntry(final String entryDN, final Set<String> baseObjectClasses, final Map<String, String> stringAttributes) throws ChaiOperationException {
activityPreCheck();
getInputValidator().createEntry(entryDN, baseObjectClasses, stringAttributes);
final LDAPAttributeSet ldapAttributeSet = new LDAPAttributeSet();
ldapAttributeSet.add(new LDAPAttribute(ChaiConstant.ATTR_LDAP_OBJECTCLASS, baseObjectClasses.toArray(new String[baseObjectClasses.size()])));
if (stringAttributes != null) {
for (final Map.Entry<String, String> entry : stringAttributes.entrySet()) {
final String attrName = entry.getKey();
ldapAttributeSet.add(new LDAPAttribute(attrName, entry.getValue()));
}
}
final LDAPEntry newEntry = new LDAPEntry(entryDN, ldapAttributeSet);
try {
ldapConnection.add(newEntry);
} catch (LDAPException e) {
throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
}
}
use of com.novell.ldap.LDAPAttributeSet in project janrufmonitor by tbrandt77.
the class LdapMappingManager method mapAttributes.
private IAttributeMap mapAttributes(LDAPEntry entry) {
IAttributeMap attributes = getRuntime().getCallerFactory().createAttributeMap();
LDAPAttributeSet attributeSet = entry.getAttributeSet();
Iterator allAttributes = attributeSet.iterator();
while (allAttributes.hasNext()) {
LDAPAttribute attribute = (LDAPAttribute) allAttributes.next();
if (m_attributeMappings.values().contains(attribute.getName())) {
String value = attribute.getStringValue();
if (m_logger.isLoggable(Level.INFO)) {
m_logger.info("Adding LDAP attribute: " + attribute.getName() + ", value: " + value);
}
if (!m_inversAttributeMappings.getProperty(attribute.getName()).equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)) {
attributes.add(getRuntime().getCallerFactory().createAttribute(m_inversAttributeMappings.getProperty(attribute.getName()), value));
} else {
try {
addImage(attributes, attribute.getByteValue(), entry);
} catch (IOException e) {
m_logger.log(Level.SEVERE, e.toString(), e);
}
}
}
}
return attributes;
}
use of com.novell.ldap.LDAPAttributeSet in project janrufmonitor by tbrandt77.
the class LdapMappingManager method mapPhones.
private List mapPhones(LDAPEntry entry, IAttributeMap attributes) {
List phones = new ArrayList();
LDAPAttributeSet attributeSet = entry.getAttributeSet();
Iterator allAttributes = attributeSet.iterator();
while (allAttributes.hasNext()) {
LDAPAttribute attribute = (LDAPAttribute) allAttributes.next();
if (m_phonenumberMappings.keySet().contains(attribute.getName())) {
Enumeration allValues = attribute.getStringValues();
if (allValues != null) {
String value = null;
while (allValues.hasMoreElements()) {
value = (String) allValues.nextElement();
if (!Base64.isLDIFSafe(value)) {
value = attribute.getStringValue();
}
if (m_logger.isLoggable(Level.INFO)) {
m_logger.info("Adding LDAP attribute: " + attribute.getName() + ", value: " + value);
}
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("LdapMappingManager raw number: " + value);
}
IPhonenumber pn = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(value);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("LdapMappingManager identified number: " + pn);
}
if (pn != null) {
phones.add(pn);
attributes.add(getNumberTypeAttribute(attribute.getName(), pn));
}
}
}
}
}
return phones;
}
use of com.novell.ldap.LDAPAttributeSet 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);
}
Aggregations