private List<LDAPUser> doSearchForUsers(string cn, string baseDN, LDAPConnOpts lco, bool allAttrs) { List<LDAPUser> users = new List<LDAPUser>(); if (StringExtensions.IsEmpty(cn)) cn = "*"; int x = (int)lco; LdapSearchResults lsr = lc.Search(baseDN, x, "(&(objectClass=user)(cn=" + cn + "))", null, false ); if (lsr.hasMore() == false) { throw new Exception("No matching users found for " + cn); } else { while (lsr.hasMore()) { LDAPUser user; LdapEntry nextEntry = null; try { nextEntry = lsr.next(); Logger.Debug("Next Entry {0}", nextEntry.DN); user = AttributeUtil.iterUsrAttrs(nextEntry.getAttributeSet(), nextEntry.DN); users.Add(user); } catch(LdapException e) { Logger.Error("Error: " + e.LdapErrorMessage); // Exception is thrown, go for next entry continue; } } } return users; }
/// <summary> /// Performs a search from the base specified /// The ldap search must be specified e.g (&(objectClass=user)(cn=jared*)) /// </summary> /// <param name="ldapSearchSyntax"> /// A <see cref="System.String"/> /// </param> /// <returns> /// A <see cref="List<LDAPUser>"/> /// </returns> public List<LDAPZFDApp> FindZFDApps(string cn, string baseDN, LDAPConnOpts lco) { List<LDAPZFDApp> apps = new List<LDAPZFDApp>(); if (StringExtensions.IsEmpty(cn)) cn = "*"; LdapSearchResults lsc=lc.Search(baseDN, LdapConnection.SCOPE_SUB, "(&(objectClass=appApplication)(cn=" + cn +"))", //e.g. (&(objectClass=user)(cn=jared*)) null, false); while (lsc.hasMore()) // we found some matches in the search and have results to parse { LDAPZFDApp app; LdapEntry nextEntry = null; try { nextEntry = lsc.next(); Logger.Debug("Next Entry {0}", nextEntry.DN); app = AttributeUtil.iterZFDAppAttrs(nextEntry.getAttributeSet(), nextEntry.DN); apps.Add(app); } catch(LdapException e) { Logger.Error("Error: " + e.LdapErrorMessage); // Exception is thrown, go for next entry continue; } } return apps; }
/// <summary> /// Search for users with the specified CN. /// Wild cards can be used for the search. /// /// Must specify the baseDN to search from. /// /// Specify the LDAP search criteria. SUB, One, BASE /// These control if the search will searc subcontainers or not. /// /// The param allAttrs specifies whether or not the property unknown attributes is populated /// with attributes that have no match method (property in the LDAPUser object) /// </summary> /// <exception cref="Exception">Exception is thrown if no users are found</exception> /// <param name="cn"> /// A <see cref="System.String"/> /// </param> /// <param name="baseDN"> /// A <see cref="System.String"/> /// </param> /// <param name="lco"> /// A <see cref="LDAPConnOpts"/> /// </param> /// <param name="allAttrs"> /// A <see cref="System.Boolean"/> /// </param> /// <returns> /// A <see cref="List<LDAPUser>"/> /// </returns> public List<LDAPUser> findUsers(string cn, string baseDN, LDAPConnOpts lco, bool allAttrs) { return doSearchForUsers(cn, baseDN, lco, false); }
/// <summary> /// Searchs for a specified user or users. /// A null or empty parameter can be passed in which case the search will be wild. /// </summary> /// <param name="cn"> /// A <see cref="System.String"/> /// </param> /// <returns> /// A <see cref="Dictionary<System.String, LDAPUser>"/> /// </returns> public Dictionary<string, LDAPUser> findUniqUsers(string cn, LDAPConnOpts lco) { Logger.Debug("searching wth a scope level of {0}", lco); Dictionary<string, LDAPUser> d = new Dictionary<string, LDAPUser>(); if (StringExtensions.IsEmpty(cn)) cn = "*"; LdapSearchResults lsc=lc.Search(authUser.BASE_DN, (int)lco, "(&(objectClass=Person)(cn=" + cn + "))", //e.g. (&(objectClass=user)(cn=jared*)) null, false); while (lsc.hasMore()) // we found some matches in the search and have results to parse { LDAPUser user; LdapEntry nextEntry = null; try { nextEntry = lsc.next(); Logger.Debug("Next Entry {0}", nextEntry.DN); user = AttributeUtil.iterUsrAttrs(nextEntry.getAttributeSet(), nextEntry.DN); d.Add(AttributeUtil.getAttr(nextEntry.getAttributeSet(), ATTRNAME.CN),user); } catch (ArgumentException ae) { Logger.Debug(ae.StackTrace); Logger.Error("Duplicate user {0}", nextEntry.DN); continue; } catch(LdapException e) { Logger.Error("Error: " + e.LdapErrorMessage); // Exception is thrown, go for next entry continue; } } return d; }
private List<LDAPUser> doSearchForUsers(string filter, string baseDN, LDAPConnOpts ldapConnectionOpts, bool allAttrs) { List<LDAPUser> users = new List<LDAPUser>(); int x = (int)ldapConnectionOpts; LdapSearchResults lsr = lc.Search(baseDN, x, filter, null, false ); if (lsr.hasMore() == false) { throw new Exception("No matching users found for " + filter); } else { while (lsr.hasMore()) { LDAPUser user; LdapEntry nextEntry = null; try { nextEntry = lsr.next(); Logger.Debug("Next Entry {0}", nextEntry.DN); user = AttributeUtil.iterUsrAttrs(nextEntry.getAttributeSet(), nextEntry.DN); users.Add(user); } catch(LdapException e) { Logger.Error("Error: " + e.LdapErrorMessage); // Exception is thrown, go for next entry continue; } } } return users; }
/// <summary> /// Search for users with the specified CN. /// Wild cards can be used for the search. /// /// Must specify the baseDN to search from. /// /// Specify the LDAP search criteria. SUB, One, BASE /// These control if the search will searc subcontainers or not /// </summary> /// <exception cref="Exception">Exception is thrown if no users are found</exception> /// <param name="cn"> /// A <see cref="System.String"/> /// </param> /// <param name="baseDN"> /// A <see cref="System.String"/> /// </param> /// <param name="lco"> /// A <see cref="LDAPConnOpts"/> /// </param> /// <returns> /// A <see cref="List<LDAPUser>"/> /// </returns> public List<LDAPUser> findUsers(string cn, string baseDN, LDAPConnOpts lco) { return doSearchForUsers("(&(objectClass=user)(cn=" + cn + "))", baseDN, lco, false); }