Ejemplo n.º 1
0
        public static string[] GetUser(string user, string pass)
        {
            string displayname = string.Empty; string mail = string.Empty;

            try
            {
                string   dominio     = string.Empty;
                string[] arrDominios = Constantes.Parametros.DominioSudameris.Split(';');
                foreach (var data in arrDominios)
                {
                    dominio = data;
                    try
                    {
                        List <Directivas> users          = new List <Directivas>();
                        string            ldapDomainName = SeguridadActive.getLDAPDomainName(dominio);
                        string            domainName     = ldapDomainName.Replace("LDAP://", string.Empty);
                        List <string>     groupMemebers  = new List <string>();

                        DirectoryEntry    de       = new DirectoryEntry(ldapDomainName, user, pass);
                        DirectorySearcher deSearch = new DirectorySearcher(de);

                        string[] properties = { "fullname" };
                        deSearch.SearchScope     = SearchScope.Subtree;
                        deSearch.ReferralChasing = ReferralChasingOption.All;
                        deSearch.PropertiesToLoad.AddRange(properties);
                        deSearch.Filter = "(sAMAccountName=" + user + ")";

                        SearchResult result;
                        result = deSearch.FindOne();
                        DirectoryEntry directoryEntry = new DirectoryEntry();
                        directoryEntry = result.GetDirectoryEntry();

                        displayname = directoryEntry.Properties["displayname"].Value.ToString();
                        mail        = directoryEntry.Properties["mail"].Value.ToString();
                    }
                    catch
                    {
                        displayname = string.Empty; mail = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(displayname) && !string.IsNullOrEmpty(mail))
                    {
                        break;
                    }
                }
            }
            catch
            {
                displayname = string.Empty; mail = string.Empty;
            }

            string[] ar = { displayname, mail };
            return(ar);
        }
Ejemplo n.º 2
0
        public static List <Directivas> GetUsersInGroup(string group)
        {
            List <Directivas> users          = new List <Directivas>();
            string            ldapDomainName = SeguridadActive.getLDAPDomainName(Constantes.Parametros.DominioSudameris);
            string            domainName     = ldapDomainName.Replace("LDAP://", string.Empty);
            List <string>     groupMemebers  = new List <string>();

            DirectoryEntry    de = new DirectoryEntry(ldapDomainName);
            DirectorySearcher ds = new DirectorySearcher(de, "(objectClass=person)");

            ds.Filter = "(&(objectClass=group)(cn=" + group + "))";
            foreach (SearchResult result in ds.FindAll())
            {
                var         dir     = result.GetDirectoryEntry();
                var         list    = dir.Invoke("Members");
                IEnumerable entries = (IEnumerable)list;
                foreach (var entry in entries)
                {
                    DirectoryEntry member = new DirectoryEntry(entry);
                    if (member.SchemaClassName == "group")
                    {
                        List <Directivas> usersInGroup =
                            GetUsersInGroup(member.Properties["name"][0].ToString());
                        foreach (Directivas aduser in usersInGroup)
                        {
                            if (!users.ToDictionary(u => u.Name).ContainsKey(aduser.Name))
                            {
                                users.Add(aduser);
                            }
                        }
                    }
                    else
                    {
                        Directivas aduser = new Directivas(
                            (byte[])member.Properties["objectSid"][0],
                            member.Properties["name"][0].ToString(),
                            member.Properties["distinguishedName"][0].ToString(),
                            member.Properties["sAMAccountName"][0].ToString());
                        users.Add(aduser);
                    }
                }
            }
            return(users);
        }
Ejemplo n.º 3
0
        public static string[] GetUsuario(string user, string pass)
        {
            string displayname = string.Empty; string mail = string.Empty;

            var dominio = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;

            try
            {
                List <Directivas> users          = new List <Directivas>();
                string            ldapDomainName = SeguridadActive.getLDAPDomainName(dominio);
                string            domainName     = ldapDomainName.Replace("LDAP://", string.Empty);
                List <string>     groupMemebers  = new List <string>();

                DirectoryEntry    de       = new DirectoryEntry(ldapDomainName, user, pass);
                DirectorySearcher deSearch = new DirectorySearcher(de);

                string[] properties = { "fullname" };
                deSearch.SearchScope     = SearchScope.Subtree;
                deSearch.ReferralChasing = ReferralChasingOption.All;
                deSearch.PropertiesToLoad.AddRange(properties);
                deSearch.Filter = "(sAMAccountName=" + user + ")";

                SearchResult result;
                result = deSearch.FindOne();
                DirectoryEntry directoryEntry = new DirectoryEntry();
                directoryEntry = result.GetDirectoryEntry();

                displayname = directoryEntry.Properties["displayname"].Value.ToString();
                mail        = directoryEntry.Properties["mail"].Value.ToString();
            }
            catch
            {
                displayname = string.Empty; mail = string.Empty;
            }
            if (!string.IsNullOrEmpty(displayname) && !string.IsNullOrEmpty(mail))
            {
                //break;
            }
            string[] ar = { displayname, mail };
            return(ar);
        }