using DSInternals.Common.Cryptography; using DSInternals.Common.Schema; namespace DSInternals.Common.Data; /// /// Provides methods for creating instances from directory objects. /// public static class AccountFactory { /// /// Creates a instance from the specified directory object. /// /// The directory object to create an account from. /// The NetBIOS domain name. /// The secret decryptor used to decrypt password hashes. Can be if decryption is not needed. /// The KDS root key resolver for decrypting LAPS passwords. Can be if LAPS decryption is not needed. /// A bitwise combination of the enumeration values that specifies which property sets to load. /// A instance, or if the object is not a security principal. /// The parameter is . public static DSAccount? CreateAccount(DirectoryObject dsObject, string netBIOSDomainName, DirectorySecretDecryptor? pek, IKdsRootKeyResolver? rootKeyResolver = null, AccountPropertySets propertySets = AccountPropertySets.All) { // Validate the input. ArgumentNullException.ThrowIfNull(dsObject); // Check that the object is an account dsObject.ReadAttribute(CommonDirectoryAttributes.SamAccountType, out SamAccountType? accountType); switch (accountType) { case SamAccountType.User: return new DSUser(dsObject, netBIOSDomainName, pek, propertySets); case SamAccountType.Computer: return new DSComputer(dsObject, netBIOSDomainName, pek, rootKeyResolver, propertySets); case SamAccountType.Trust: return new DSAccount(dsObject, netBIOSDomainName, pek, propertySets); default: // This object is not an account return null; } } }