示例#1
0
        public List <UserProxyFullPrincipal> GetChildUserProxyFullObjects(int maxRecords)
        {
            var directoryDe = new DirectoryEntry();

            if (ContextType == ContextType.ApplicationDirectory)
            {
                if (!string.IsNullOrEmpty(Container) &&
                    !string.IsNullOrEmpty(Name))
                {
                    directoryDe = new DirectoryEntry(string.Format("LDAP://{0}/{1}", Name, Container));
                }
                else
                {
                    directoryDe = new DirectoryEntry(string.Format("LDAP://{0}", Name));
                }
            }
            if (ContextType == ContextType.Machine ||
                ContextType == ContextType.Domain)
            {
                throw new NotSupportedException(
                          "This functionality is only available for ApplicationDirectory ContextType PrincipalContext objects.");
            }
            var search = new DirectorySearcher(directoryDe)
            {
                Tombstone    = false,
                Asynchronous = true,
                PageSize     = 100,
                Filter       = "(objectClass=userProxyFull)"
            };
            var results  = search.FindAll();
            var i        = 0;
            var children = new List <UserProxyFullPrincipal>();

            foreach (SearchResult result in results)
            {
                i++;
                var delims = new[] { '/' };
                var pieces = result.Path.Split(delims);
                var dn     = pieces[pieces.Count() - 1];
                if (maxRecords > 0 && i > maxRecords)
                {
                    break;
                }
                try
                {
                    children.Add(UserProxyFullPrincipal.FindByIdentity(this, IdentityType.DistinguishedName, dn));
                }
                catch
                {
                }
            }
            return(children);
        }
示例#2
0
        //work around way to create a new userProxyFull object
        public static UserProxyFullPrincipal CreateProxy(PrincipalContext context, string name, SecurityIdentifier sid)
        {
            var sidInBytes = new byte[sid.BinaryLength];

            sid.GetBinaryForm(sidInBytes, 0);
            var ouDe    = new DirectoryEntry(string.Format("LDAP://{0}/{1}", context.ConnectedServer, context.Container));
            var proxyDe = ouDe.Children.Add(String.Format("CN={0}", name), "userProxy");

            proxyDe.Properties["objectSid"].Clear();
            proxyDe.Properties["objectSid"].Value         = sidInBytes;
            proxyDe.Properties["userPrincipalName"].Value = name;
            proxyDe.CommitChanges();
            return(UserProxyFullPrincipal.FindByIdentity(context, name));
        }