static internal Principal SearchResultToPrincipal(SearchResult sr, PrincipalContext owningContext, Type principalType) { Principal p; // Construct an appropriate Principal object. // Make* constructs a Principal that is marked persisted // and not loaded (p.unpersisted = false, p.loaded = false). // Since there should be no more multistore contexts, the owning context IS // the specific context // If we know the type we should just construct it ourselves so that we don't need to incur the costs of reflection. // If this is an extension type then we must reflect teh constructor to create the object. if (typeof(UserPrincipal) == principalType) { p = UserPrincipal.MakeUser(owningContext); } else if (typeof(ComputerPrincipal) == principalType) { p = ComputerPrincipal.MakeComputer(owningContext); } else if (typeof(GroupPrincipal) == principalType) { p = GroupPrincipal.MakeGroup(owningContext); } else if (null == principalType || typeof(AuthenticablePrincipal) == principalType || typeof(Principal) == principalType) { if (SDSUtils.IsOfObjectClass(sr, "computer")) { p = ComputerPrincipal.MakeComputer(owningContext); } else if (SDSUtils.IsOfObjectClass(sr, "user")) { p = UserPrincipal.MakeUser(owningContext); } else if (SDSUtils.IsOfObjectClass(sr, "group")) { p = GroupPrincipal.MakeGroup(owningContext); } else { p = AuthenticablePrincipal.MakeAuthenticablePrincipal(owningContext); } } else { p = Principal.MakePrincipal(owningContext, principalType); } // The DirectoryEntry we're constructing the Principal from // will serve as the underlying object for that Principal. p.UnderlyingSearchObject = sr; // It's up to our caller to assign an appropriate StoreKey. // Caller must also populate the underlyingObject field if the P is to be used R/W return(p); }
internal static Principal SearchResultToPrincipal(SearchResult sr, PrincipalContext owningContext, Type principalType) { Principal principal; if (typeof(UserPrincipal) != principalType) { if (typeof(ComputerPrincipal) != principalType) { if (typeof(GroupPrincipal) != principalType) { if (null == principalType || typeof(AuthenticablePrincipal) == principalType || typeof(Principal) == principalType) { if (!SDSUtils.IsOfObjectClass(sr, "computer")) { if (!SDSUtils.IsOfObjectClass(sr, "user")) { if (!SDSUtils.IsOfObjectClass(sr, "group")) { principal = AuthenticablePrincipal.MakeAuthenticablePrincipal(owningContext); } else { principal = GroupPrincipal.MakeGroup(owningContext); } } else { principal = UserPrincipal.MakeUser(owningContext); } } else { principal = ComputerPrincipal.MakeComputer(owningContext); } } else { principal = Principal.MakePrincipal(owningContext, principalType); } } else { principal = GroupPrincipal.MakeGroup(owningContext); } } else { principal = ComputerPrincipal.MakeComputer(owningContext); } } else { principal = UserPrincipal.MakeUser(owningContext); } principal.UnderlyingSearchObject = sr; return(principal); }
internal static Principal DirectoryEntryToPrincipal(DirectoryEntry de, PrincipalContext owningContext, Type principalType) { Principal principal; if (typeof(UserPrincipal) != principalType) { if (typeof(ComputerPrincipal) != principalType) { if (typeof(GroupPrincipal) != principalType) { if (null == principalType || typeof(AuthenticablePrincipal) == principalType || typeof(Principal) == principalType) { if (!SDSUtils.IsOfObjectClass(de, "computer")) { if (!SDSUtils.IsOfObjectClass(de, "user")) { if (!SDSUtils.IsOfObjectClass(de, "group")) { principal = AuthenticablePrincipal.MakeAuthenticablePrincipal(owningContext); } else { principal = GroupPrincipal.MakeGroup(owningContext); } } else { principal = UserPrincipal.MakeUser(owningContext); } } else { principal = ComputerPrincipal.MakeComputer(owningContext); } } else { principal = Principal.MakePrincipal(owningContext, principalType); } } else { principal = GroupPrincipal.MakeGroup(owningContext); } } else { principal = ComputerPrincipal.MakeComputer(owningContext); } } else { principal = UserPrincipal.MakeUser(owningContext); } principal.UnderlyingObject = de; return(principal); }
// Used to implement StoreCtx.GetAsPrincipal for AD and SAM static internal Principal DirectoryEntryToPrincipal(DirectoryEntry de, PrincipalContext owningContext, Type principalType) { Principal p; // Construct an appropriate Principal object. // Make* constructs a Principal that is marked persisted // and not loaded (p.unpersisted = false, p.loaded = false). // Since there should be no more multistore contexts, the owning context IS // the specific context if (typeof(UserPrincipal) == principalType) { p = UserPrincipal.MakeUser(owningContext); } else if (typeof(ComputerPrincipal) == principalType) { p = ComputerPrincipal.MakeComputer(owningContext); } else if (typeof(GroupPrincipal) == principalType) { p = GroupPrincipal.MakeGroup(owningContext); } else if (null == principalType || typeof(AuthenticablePrincipal) == principalType || typeof(Principal) == principalType) { if (SDSUtils.IsOfObjectClass(de, "computer")) { p = ComputerPrincipal.MakeComputer(owningContext); } else if (SDSUtils.IsOfObjectClass(de, "user")) { p = UserPrincipal.MakeUser(owningContext); } else if (SDSUtils.IsOfObjectClass(de, "group")) { p = GroupPrincipal.MakeGroup(owningContext); } else { p = AuthenticablePrincipal.MakeAuthenticablePrincipal(owningContext); } } else { p = Principal.MakePrincipal(owningContext, principalType); } // The DirectoryEntry we're constructing the Principal from // will serve as the underlying object for that Principal. p.UnderlyingObject = de; // It's up to our caller to assign an appropriate StoreKey. return(p); }