Add LDAP user to storage group and/or Roles

Mar 18, 2010 at 12:28 PM

Hi,

I have code that returns a list of LDAP users and I want to be able to add a select few to Azman.  Based on my LDAP code how would I convert the LDAP user to something that is acceptable to Azman  I have looked at example code and I think I have to produce an IAzManSid and then call the CreateStoreGroupMember method but I have no idea how to do this from a LDAP user.

My LDAP code is as follows:

 

        public SearchResultCollection GetWindowsUsers(string DomainUserName)
        {
            try
            {
                DirectoryEntry rootDSE = new DirectoryEntry("LDAP://rootDSE");
                string defaultNamingContext = (string)rootDSE.Properties["defaultNamingContext"][0];

                string rootQuery = "LDAP://" + defaultNamingContext;
                string searchFilter = string.Format("(&(samAccountName={0})(objectCategory=person)(objectClass=user))", "*" + DomainUserName + "*");

                using (DirectoryEntry root = new DirectoryEntry(rootQuery))
                {
                    using (DirectorySearcher searcher = new DirectorySearcher(root))
                    {
                        searcher.Filter = searchFilter;
                        return searcher.FindAll();
                    }
                }
            }
            catch (Exception e)
            {
                return null;
            }
        }

Any help would be appreciated :-).

 

 

Coordinator
Mar 18, 2010 at 1:49 PM

Hi,

you can do this:

            using (DirectorySearcher searcher = new DirectorySearcher(root))

            {

                searcher.Filter = searchFilter;

                SearchResultCollection searchResultCollection = searcher.FindAll();

                foreach (SearchResult sr in this.searchResultCollection)

                {

                    DirectoryEntry de = sr.GetDirectoryEntry();

                    IAzManSid sid = new SqlAzManSID((byte[])de.Properties["objectSid"].Value);

                    //To something with sid

                }

            }

Regards,

Andrea.

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator  
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com

Mar 18, 2010 at 2:08 PM

Thanks Andrea,

 

This works fine :-)