use of com.novell.ldap.LDAPEntry 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.LDAPEntry in project neo4j-apoc-procedures by neo4j-contrib.
the class LoadLdapTest method testLoadLDAP.
@Test
public void testLoadLDAP() throws Exception {
Map<String, Object> connParms = new HashMap<>();
connParms.put("ldapHost", "ldap.forumsys.com");
connParms.put("ldapPort", 389l);
connParms.put("loginDN", "cn=read-only-admin,dc=example,dc=com");
connParms.put("loginPW", "password");
LoadLdap.LDAPManager mgr = new LoadLdap.LDAPManager(LoadLdap.getConnectionMap(connParms));
Map<String, Object> searchParms = new HashMap<>();
searchParms.put("searchBase", "dc=example,dc=com");
searchParms.put("searchScope", "SCOPE_ONE");
searchParms.put("searchFilter", "(&(objectClass=*)(uid=training))");
ArrayList<String> ats = new ArrayList<>();
ats.add("uid");
searchParms.put("attributes", ats);
LDAPSearchResults results = mgr.doSearch(searchParms);
LDAPEntry le = results.next();
assertEquals("uid=training,dc=example,dc=com", le.getDN());
assertEquals("training", le.getAttribute("uid").getStringValue());
}
use of com.novell.ldap.LDAPEntry in project janrufmonitor by tbrandt77.
the class LdapContactsProxy method getContacts.
public synchronized ICallerList getContacts(String category) throws LdapContactsException {
ICallerList cl = getRuntime().getCallerFactory().createCallerList(getMaxResults());
String query = "(objectclass=*)";
if (category != null) {
String ldapAttrib = LdapMappingManager.getInstance().getLdapAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
if (ldapAttrib != null && ldapAttrib.trim().length() > 0) {
query = "(" + ldapAttrib + "=" + category + ")";
}
}
LDAPConnection lc = new LDAPConnection();
try {
lc.connect(getServer(), getPort());
lc.bind(LDAPConnection.LDAP_V3, getLoginUser(), getLoginPassword().getBytes("UTF-8"));
LDAPSearchConstraints cons = lc.getSearchConstraints();
cons.setMaxResults(getMaxResults());
String baseDN = this.getBaseDN();
String[] bases = null;
if (baseDN.indexOf("|") > 0) {
bases = baseDN.split("\\|");
} else {
bases = new String[] { baseDN };
}
for (int i = 0; i < bases.length; i++) {
LDAPSearchResults searchResults = lc.search(bases[i], getScope(), query, // return all attributes
null, // return attrs and values
false, cons);
ICaller c = null;
while (searchResults.hasMore()) {
LDAPEntry nextEntry = null;
try {
nextEntry = searchResults.next();
} catch (LDAPException e) {
if (e.getResultCode() == LDAPException.LDAP_TIMEOUT || e.getResultCode() == LDAPException.CONNECT_ERROR)
break;
else
continue;
}
c = LdapMappingManager.getInstance().mapToJamCaller(nextEntry);
if (c != null) {
cl.add(c);
}
}
}
// disconnect from the server
lc.disconnect();
LdapMappingManager.invalidate();
} catch (LDAPException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
throw new LdapContactsException(e.toString(), e);
} catch (UnsupportedEncodingException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
}
if (this.m_dbh != null) {
try {
this.m_dbh.deleteAll();
ICaller c = null;
for (int i = 0, j = cl.size(); i < j; i++) {
c = cl.get(i);
if (c instanceof IMultiPhoneCaller) {
List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
IPhonenumber pn = null;
for (int k = 0; k < phones.size(); k++) {
pn = (IPhonenumber) phones.get(k);
this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
}
} else {
IPhonenumber pn = c.getPhoneNumber();
this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
}
}
} catch (SQLException e) {
throw new LdapContactsException(e.getMessage(), e);
}
} else {
this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
}
return cl;
}
use of com.novell.ldap.LDAPEntry in project janrufmonitor by tbrandt77.
the class LdapContactsProxy method identifyByUUID.
private ICaller identifyByUUID(String uuid) throws LdapContactsException {
LDAPConnection lc = new LDAPConnection();
try {
lc.connect(getServer(), getPort());
lc.bind(LDAPConnection.LDAP_V3, getLoginUser(), getLoginPassword().getBytes("UTF8"));
lc.read(uuid);
// return attrs and values
LDAPEntry entry = lc.read(uuid);
if (entry != null) {
ICaller c = LdapMappingManager.getInstance().mapToJamCaller(entry);
if (c != null) {
return c;
}
}
} catch (LDAPException e) {
throw new LdapContactsException(e.toString(), e);
} catch (UnsupportedEncodingException e) {
throw new LdapContactsException(e.toString(), e);
} finally {
LdapMappingManager.invalidate();
try {
lc.disconnect();
} catch (LDAPException e) {
throw new LdapContactsException(e.toString(), e);
}
}
return null;
}
use of com.novell.ldap.LDAPEntry 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());
}
}
Aggregations