/********************************************************************************************************** * METHODS **********************************************************************************************************/ public static CachedUserPrincipal Create(UserPrincipal principal) { var instance = new CachedUserPrincipal(); instance.Name = instance.TryGetValue(principal, p => p.Name); instance.DisplayName = instance.TryGetValue(principal, p => p.DisplayName); instance.SamAccountName = instance.TryGetValue(principal, p => p.SamAccountName); instance.UserPrincipalName = instance.TryGetValue(principal, p => p.UserPrincipalName); instance.EmailAddress = instance.TryGetValue(principal, p => p.EmailAddress); instance.EmployeeId = instance.TryGetValue(principal, p => p.EmployeeId); instance.GivenName = instance.TryGetValue(principal, p => p.GivenName); instance.MiddleName = instance.TryGetValue(principal, p => p.MiddleName); instance.Surname = instance.TryGetValue(principal, p => p.Surname); instance.VoiceTelephoneNumber = instance.TryGetValue(principal, p => p.VoiceTelephoneNumber); instance.Guid = instance.TryGetValue(principal, p => p.Guid); instance.Description = instance.TryGetValue(principal, p => p.Description); instance.DistinguishedName = instance.TryGetValue(principal, p => p.DistinguishedName); return(instance.initialized ? instance : null); }
public static FileSystemPrincipal GetOwner(FileSystemInfo item, LookupCache cache) { SecurityIdentifier ownerSID = null; IdentityReference ownerNTAccount = null; CachedUserPrincipal ownerPrincipal = null; try { FileSystemSecurity fac = null; if (item is FileInfo) { fac = File.GetAccessControl(item.FullName); } if (item is DirectoryInfo) { fac = Directory.GetAccessControl(item.FullName); } if (fac != null) { ownerSID = fac.GetOwner(typeof(SecurityIdentifier)) as SecurityIdentifier; if (ownerSID != null) { ownerNTAccount = cache.GetName <NTAccount>(FileSystemObjectTypes.NTAccount, ownerSID); ownerPrincipal = cache.GetName <CachedUserPrincipal>(FileSystemObjectTypes.Principal, ownerSID); } } return(new FileSystemPrincipal(ownerSID, ownerNTAccount, ownerPrincipal)); } catch (Exception) { } return(null); }
public FileSystemPrincipal(SecurityIdentifier sid, IdentityReference account, CachedUserPrincipal principal) { Sid = sid; Account = account; Principal = principal; }