本文整理汇总了C#中SecurityIdentifier类的典型用法代码示例。如果您正苦于以下问题:C# SecurityIdentifier类的具体用法?C# SecurityIdentifier怎么用?C# SecurityIdentifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SecurityIdentifier类属于命名空间,在下文中一共展示了SecurityIdentifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: verifyNTuser
public static string verifyNTuser(string userName)
{
DirectoryEntry dEntry = new DirectoryEntry("LDAP://ds.kycourts.net/CN=Users,DC=ds,DC=kycourts,DC=net");
DirectorySearcher dSearch = new DirectorySearcher(dEntry);
dSearch.PageSize = 6000;
dSearch.Filter = "cn="+userName;
dSearch.PropertiesToLoad.Add("cn");
dSearch.PropertiesToLoad.Add("mail");
dSearch.PropertiesToLoad.Add("objectSid");
dSearch.CacheResults = true;
if (dSearch.FindAll().Count > 0)
{
foreach (SearchResult sResultSet in dSearch.FindAll())
{
SecurityIdentifier sid = new SecurityIdentifier((byte[])sResultSet.Properties["objectSid"][0], 0);
string[] namesid = sid.ToString().Split('-');
dEntry.Close();
return sResultSet.Properties["cn"][0].ToString() + ";" + sResultSet.Properties["mail"][0].ToString() + ";" +
namesid[namesid.Length - 1].ToString();
}
}
else
{
dEntry.Close();
return "false";
}
return "false";
}
示例2: GetSingleStringPropertyCollectionValue
public static string GetSingleStringPropertyCollectionValue(ResultPropertyCollection props, string name)
{
try
{
if (!props.Contains(name))
{
return string.Empty;
}
ResultPropertyValueCollection pvc = props[name];
if (pvc == null || pvc.Count == 0)
{
return string.Empty;
}
if (string.Compare(name, Constants.Properties.AdProperties.ObjectSID) == 0)
{
byte[] sidInBytes = (byte[])pvc[0];
SecurityIdentifier sid = new SecurityIdentifier(sidInBytes, 0);
return Convert.ToString(sid);
}
else
{
return Convert.ToString(pvc[0]);
}
}
catch (Exception ex)
{
throw new ApplicationException(string.Format("Failed to retrieve property '{0}' from ResultPropertyCollection.", name), ex);
}
}
示例3: CreateFromSecurityIdentifier
public static ActiveDirectoryRole CreateFromSecurityIdentifier(SecurityIdentifier sid)
{
if (sid == null)
throw new ArgumentNullException("sid");
ActiveDirectoryRole role = new ActiveDirectoryRole(GetRootEntry(), new DirectoryRootQuery("objectSID", sid.ToString(), DirectoryQueryOperation.Equal));
role.Operations.Add(s_directoryGroupQuery);
ValidateRole(role);
return role;
}
示例4: AreSidsInSameDomain
internal static bool AreSidsInSameDomain(SecurityIdentifier sid1, SecurityIdentifier sid2)
{
if (!sid1.IsAccountSid() || !sid2.IsAccountSid())
{
return false;
}
else
{
return sid1.AccountDomainSid.Equals(sid2.AccountDomainSid);
}
}
示例5: CreateAdGroup
public static string CreateAdGroup(string name, string adPath)
{
string grpSid = String.Empty;
using (WindowsImpersonationContextFacade impersonationContext
= new WindowsImpersonationContextFacade(
nc))
{
//DirectoryEntry directoryEntry = new DirectoryEntry(DomainPath);
//DirectoryEntry ou = directoryEntry.Children.Find(adPath);
//DirectoryEntry group = ou.Children.Add($"CN={name}", "group");
//group.Properties["samAccountName"].Value = name;
//group.CommitChanges();
bool groupIsExist = false;
DirectoryEntry directoryEntry = new DirectoryEntry(DomainPath);
using (directoryEntry)
{
//Если пользователь существует
DirectorySearcher search = new DirectorySearcher(directoryEntry);
search.Filter = String.Format("(&(objectClass=user)(sAMAccountName={0}))", name);
SearchResult resultGroup = search.FindOne();
groupIsExist = resultGroup != null && resultGroup.Properties.Contains("sAMAccountName");
if (!groupIsExist)
{
DirectoryEntry ou = directoryEntry.Children.Find(adPath);
DirectoryEntry group = ou.Children.Add($"CN={name}", "group");
group.Properties["samAccountName"].Value = name;
group.CommitChanges();
SecurityIdentifier sid = new SecurityIdentifier((byte[])group.Properties["objectsid"][0],
0);
grpSid = sid.Value;
}
else
{
SecurityIdentifier sid = new SecurityIdentifier((byte[])resultGroup.Properties["objectsid"][0],
0);
grpSid = sid.Value;
}
}
}
return grpSid;
}
示例6: FindGroup
public static string FindGroup(SecurityIdentifier searchSid)
{
using(var ad = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer"))
{
ad.Children.SchemaFilter.Add("group");
foreach(DirectoryEntry dChildEntry in ad.Children)
{
var bytes = (byte[])dChildEntry.Properties["objectSid"].Value;
var sid = new SecurityIdentifier(bytes, 0).ToString();
if(sid == searchSid.ToString())
{
return dChildEntry.Name;
}
}
}
throw new Exception("Cannot find group");
}
示例7: GetSingleStringPropertyCollectionValue
public static string GetSingleStringPropertyCollectionValue(ResultPropertyCollection props, string name)
{
if (!props.Contains(name))
{
return string.Empty;
}
ResultPropertyValueCollection pvc = props[name];
if (pvc == null || pvc.Count == 0)
{
return string.Empty;
}
if (string.Compare(name, Constants.Properties.AdProperties.ObjectSID) == 0)
{
byte[] sidInBytes = (byte[])pvc[0];
SecurityIdentifier sid = new SecurityIdentifier(sidInBytes, 0);
return Convert.ToString(sid);
}
else
{
return pvc[0] as string;
}
}
示例8: SetAudit
public void SetAudit(AuditFlags auditFlags, SecurityIdentifier sid, int accessMask, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, ObjectAceFlags objectFlags, Guid objectType, Guid inheritedObjectType);
示例9: RemoveAuditSpecific
public void RemoveAuditSpecific(SecurityIdentifier sid, ObjectAuditRule rule);
示例10: RemoveAudit
public bool RemoveAudit(SecurityIdentifier sid, ObjectAuditRule rule);
示例11: ObjectAce
public ObjectAce(AceFlags aceFlags, AceQualifier qualifier, int accessMask, SecurityIdentifier sid, ObjectAceFlags flags, Guid type, Guid inheritedType, bool isCallback, byte[] opaque);
示例12: SetAccess
public void SetAccess(AccessControlType accessType, SecurityIdentifier sid, int accessMask, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, ObjectAceFlags objectFlags, Guid objectType, Guid inheritedObjectType);
示例13: RemoveAccessSpecific
public void RemoveAccessSpecific(AccessControlType accessType, SecurityIdentifier sid, ObjectAccessRule rule);
示例14: CheckWriteAccessEnabled
public static bool CheckWriteAccessEnabled(string path, string sid)
{
// get file or directory security object
FileSystemSecurity security = GetFileSystemSecurity(path);
if (security == null)
return false;
if (sid == null)
return false;
AuthorizationRuleCollection rules = security.GetAccessRules(true, true, typeof(SecurityIdentifier));
SecurityIdentifier identity = new SecurityIdentifier(sid);
foreach (FileSystemAccessRule rule in rules)
{
if (rule.IdentityReference == identity
&& rule.AccessControlType == AccessControlType.Allow
&& (rule.FileSystemRights & FileSystemRights.Write) == FileSystemRights.Write)
return true;
}
return false;
}
示例15: CompoundAce
public CompoundAce(AceFlags flags, int accessMask, CompoundAceType compoundAceType, SecurityIdentifier sid);