本文整理汇总了C#中System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroups方法的典型用法代码示例。如果您正苦于以下问题:C# UserPrincipal.GetAuthorizationGroups方法的具体用法?C# UserPrincipal.GetAuthorizationGroups怎么用?C# UserPrincipal.GetAuthorizationGroups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DirectoryServices.AccountManagement.UserPrincipal
的用法示例。
在下文中一共展示了UserPrincipal.GetAuthorizationGroups方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteUser
public void WriteUser(UserPrincipal user)
{
Console.WriteLine(user.Name);
if (_showPrincipalDetails)
{
Console.WriteLine("\tDisplayName: " + $"{user.DisplayName}");
Console.WriteLine("\tSid: " + $"{user.Sid}");
Console.WriteLine("\tIsSecurityGroup: " + $"{user.UserPrincipalName}");
Console.WriteLine("\tDescription: " + $"{user.Description}");
Console.WriteLine("\tIsLockedOut: " + $"{user.IsAccountLockedOut()}");
}
if (_showMembership)
{
Console.WriteLine("\tMembers:");
foreach (var member in user.GetAuthorizationGroups().ToList())
{
Console.WriteLine("\t\t" + $"{member.Name} ({member.StructuralObjectClass})");
}
}
}
示例2: DumpUserPrincipal
private void DumpUserPrincipal(UserPrincipal userPrincipal)
{
Console.WriteLine(userPrincipal.Name);
if (_options.ShowMembership)
{
var groups = userPrincipal.GetAuthorizationGroups();
try
{
var allGroups = groups.ToList();
foreach (var group in allGroups.OrderBy(g => g.Name))
{
Console.WriteLine(group.Name);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
Environment.ExitCode = 1;
}
}
}
示例3: WriteUser
public void WriteUser(UserPrincipal user)
{
if (!_headerWritten)
{
_headerWritten = true;
_writer.Write("Name");
if (_options.Detailed)
{
_writer.Write(";DisplayName;Sid;UserPrincipalName;Description");
}
if (_options.ShowMembership)
{
_writer.Write(";Membership");
}
_writer.WriteLine();
}
_writer.Write("\"" + user.Name + "\"");
if (_options.Detailed)
{
_writer.Write(";\"" + user.Name + "\";" +
"\"" + user.DisplayName + "\";" +
"\"" + user.Sid + "\";" +
"\"" + user.UserPrincipalName + "\";" +
"\"" + user.Description + "\"");
}
if (_options.ShowMembership)
{
if (_options.ShowMembership)
{
foreach (var member in user.GetAuthorizationGroups().Select(member => member.Name).ToList())
{
_writer.Write(Environment.NewLine + "\"" + user.Name + "\";\"" + member + "\"");
}
}
}
_writer.WriteLine();
}
示例4: createNewUserBackgroundWorker_DoWork
private void createNewUserBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
try
{
using (var principalContext = new PrincipalContext(ContextType.Domain, domainDnsName, cnDnDictionary[createInComboBox.Text]))
{
using (var checkForExistingUser = UserPrincipal.FindByIdentity(principalContext, sAMAccountNameTextBox.Text))
{
if (checkForExistingUser != null)
{
AddActivityItem(sAMAccountNameTextBox.Text + " already exists. Use a different sAMAccountName.");
activityListBox.BackColor = Color.Pink;
return;
}
}
using (var newUser = new UserPrincipal(principalContext))
{
newUser.SamAccountName = sAMAccountNameTextBox.Text;
if (givenNameTextBox.Text.Length > 0)
newUser.GivenName = givenNameTextBox.Text;
if (middleNameTextBox.Text.Length > 0)
newUser.MiddleName = middleNameTextBox.Text;
if (surnameTextBox.Text.Length > 0)
newUser.Surname = surnameTextBox.Text;
if (displayNameTextBox.Text.Length > 0)
newUser.DisplayName = displayNameTextBox.Text;
if (emailTextBox.Text.Length > 0)
newUser.EmailAddress = emailTextBox.Text;
if (employeeIDTextBox.Text.Length > 0)
newUser.EmployeeId = employeeIDTextBox.Text;
if (descriptionTextBox.Text.Length > 0)
newUser.Description = descriptionTextBox.Text;
if (userPrincipalNameTextBox.Text.Length > 0)
newUser.UserPrincipalName = userPrincipalNameTextBox.Text;
newUser.SetPassword(passwordTextBox.Text);
if (userEnabledCheckBox.Checked)
newUser.Enabled = true;
if (changePasswordCheckBox.Checked)
newUser.ExpirePasswordNow();
if (passwordNeverExpiresCheckBox.Checked)
newUser.PasswordNeverExpires = true;
newUser.Save();
if (!string.IsNullOrEmpty(copyFromComboBox.Text))
{
using (PrincipalSearchResult<Principal> newUsersExistingGroupMemberships = newUser.GetAuthorizationGroups())
using (var userToCopyFrom = UserPrincipal.FindByIdentity(principalContext, copyFromComboBox.Text))
{
using (PrincipalSearchResult<Principal> groups = userToCopyFrom.GetAuthorizationGroups())
{
foreach (GroupPrincipal groupPrincipal in groups)
{
bool newUserIsAlreadyAMember = false;
foreach (GroupPrincipal existingGroupMembership in newUsersExistingGroupMemberships)
{
if (existingGroupMembership.Name == groupPrincipal.Name)
newUserIsAlreadyAMember = true;
}
if (newUserIsAlreadyAMember == false)
{
groupPrincipal.Members.Add(newUser);
groupPrincipal.Save();
AddActivityItem("User added to group: " + groupPrincipal.Name);
}
}
}
}
}
else
{
AddActivityItem("No group memberships were copied.");
}
// To set additional attributes beyond those provided by UserPrincipal, we must drop down to the underlying object.
using (DirectoryEntry newUserEntry = (DirectoryEntry)newUser.GetUnderlyingObject())
{
if (initialsTextBox.Text.Length > 0)
newUserEntry.Properties["initials"].Value = initialsTextBox.Text;
if (employeeNumberTextBox.Text.Length > 0)
newUserEntry.Properties["employeeNumber"].Value = employeeNumberTextBox.Text;
if (telephoneNumberTextBox.Text.Length > 0)
newUserEntry.Properties["telephoneNumber"].Value = telephoneNumberTextBox.Text;
newUserEntry.CommitChanges();
}
AddActivityItem("User " + newUser.SamAccountName + " created successfully.");
//.........这里部分代码省略.........