Пример #1
0
        public LdapUser GetUser(string uid, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();
                using (DirectoryEntry entry = new DirectoryEntry(setup.LDAPHost + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind))
                {
                    var    username = uid;
                    string filter   = "(&(|(objectClass=inetOrgPerson))(&(uid=" + username + ")))";

                    DirectorySearcher nDS = new DirectorySearcher(entry);
                    nDS.SearchScope = SearchScope.Subtree;
                    nDS.Filter      = filter;
                    SearchResult src = nDS.FindOne();
                    if (src != null)
                    {
                        DirectoryEntry de = src.GetDirectoryEntry();
                        return(LdapUser.CastToUser(de.Properties));
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception("Error retrieving LDAP User", ex);
            }
        }
Пример #2
0
        public static LdapUser CastToUser(PropertyCollection Properties)
        {
            var ldapuser   = new LdapUser();
            var properties = typeof(LdapUser).GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var property in properties)
            {
                property.SetValue(ldapuser, getpropertyvalue(Properties, property.Name));
            }
            return(ldapuser);
        }