Skip to content

Commit 3970cef

Browse files
authored
feat:update ldap package (#753)
* refactor(SyncCache): simplify ResetAsync method Replaced the `ClientQueryAsync` method with `ClientQuery().ToListAsync()` in the `ResetAsync` implementation. The `ClientQueryAsync` method and its internal logic have been removed, streamlining the asynchronous query process and improving code readability and maintainability. * feat(Ldap): add UserAccountControl support - Added `UserAccountControl` property in `LdapUser.cs` for managing user account control information. - Introduced `UserAccountControl` enum in `UserAccountControl.cs` to define various account control flags. - Updated `_attributes` array in `LdapProvider.cs` to include `userAccountControl` for LDAP queries. - Implemented parsing logic for `userAccountControl` in `LdapProvider.cs` to convert its value to the `UserAccountControl` enum. - Updated `Novell.Directory.Ldap.NETStandard` version in `Masa.Utils.Ldap.Novell.csproj` from `4.0.0-beta4` to `4.0.0` and added `System.Linq.Async` reference. * chore: remove System.Linq.Async package reference Removed the reference to the `System.Linq.Async` package from the `Masa.Utils.Ldap.Novell.csproj` project file, while keeping other package references intact. * docs(UserAccountControl): add detailed documentation Added comprehensive documentation for the `UserAccountControl` enum in `UserAccountControl.cs`, explaining the purpose and usage of each flag, including deprecated flags. Removed unnecessary `using System.Collections.Generic;` statement in `LdapProvider.cs` and eliminated duplicate `userAccountControl` entry in the `_attributes` array to ensure uniqueness.
1 parent 44ef02c commit 3970cef

File tree

3 files changed

+134
-3
lines changed

3 files changed

+134
-3
lines changed

src/Utils/Ldap/Masa.Utils.Ldap.Novell/Entries/LdapUser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ public class LdapUser
5656
public string Department { get; set; } = string.Empty;
5757

5858
public LdapAddress Address { get; set; } = new();
59+
60+
public UserAccountControl UserAccountControl { get; set; }
5961
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
namespace Masa.Utils.Ldap.Novell.Entries;
5+
6+
/// <summary>
7+
/// Flags that control the behavior of user accounts in Active Directory (LDAP).
8+
/// These values correspond to the userAccountControl attribute and are used as bitwise flags.
9+
/// Some flags are deprecated and should not be used in new code.
10+
/// </summary>
11+
public enum UserAccountControl
12+
{
13+
/// <summary>
14+
/// The logon script will be run.
15+
/// </summary>
16+
Script = 1,
17+
18+
/// <summary>
19+
/// The user account is disabled.
20+
/// </summary>
21+
AccountDisabled = 2,
22+
23+
/// <summary>
24+
/// The home directory is required.
25+
/// </summary>
26+
HomeDirectoryRequired = 8,
27+
28+
/// <summary>
29+
/// The account is locked out. Deprecated: Use lockoutTime attribute instead.
30+
/// </summary>
31+
AccountLockedOut_DEPRECATED = 16,
32+
33+
/// <summary>
34+
/// No password is required.
35+
/// </summary>
36+
PasswordNotRequired = 32,
37+
38+
/// <summary>
39+
/// The user cannot change the password. Deprecated: Use ntSecurityDescriptor instead.
40+
/// </summary>
41+
PasswordCannotChange_DEPRECATED = 64,
42+
43+
/// <summary>
44+
/// The user can use reversible encryption for the password.
45+
/// </summary>
46+
EncryptedTextPasswordAllowed = 128,
47+
48+
/// <summary>
49+
/// This is a temporary duplicate account.
50+
/// </summary>
51+
TempDuplicateAccount = 256,
52+
53+
/// <summary>
54+
/// This is a normal user account.
55+
/// </summary>
56+
NormalAccount = 512,
57+
58+
/// <summary>
59+
/// This is a trust account for a domain.
60+
/// </summary>
61+
InterDomainTrustAccount = 2048,
62+
63+
/// <summary>
64+
/// This is a computer account for a workstation.
65+
/// </summary>
66+
WorkstationTrustAccount = 4096,
67+
68+
/// <summary>
69+
/// This is a computer account for a server.
70+
/// </summary>
71+
ServerTrustAccount = 8192,
72+
73+
/// <summary>
74+
/// The password does not expire.
75+
/// </summary>
76+
PasswordDoesNotExpire = 65536,
77+
78+
/// <summary>
79+
/// This is an MNS logon account.
80+
/// </summary>
81+
MnsLogonAccount = 131072,
82+
83+
/// <summary>
84+
/// Smart card is required for logon.
85+
/// </summary>
86+
SmartCardRequired = 262144,
87+
88+
/// <summary>
89+
/// The account is trusted for Kerberos delegation.
90+
/// </summary>
91+
TrustedForDelegation = 524288,
92+
93+
/// <summary>
94+
/// The account is not trusted for delegation.
95+
/// </summary>
96+
AccountNotDelegated = 1048576,
97+
98+
/// <summary>
99+
/// Use only DES encryption types for this account.
100+
/// </summary>
101+
UseDesKeyOnly = 2097152,
102+
103+
/// <summary>
104+
/// Do not require Kerberos preauthentication.
105+
/// </summary>
106+
DontRequirePreauth = 4194304,
107+
108+
/// <summary>
109+
/// The user's password has expired. Deprecated: Use pwdLastSet attribute instead.
110+
/// </summary>
111+
PasswordExpired_DEPRECATED = 8388608,
112+
113+
/// <summary>
114+
/// The account is trusted to authenticate for delegation.
115+
/// </summary>
116+
TrustedToAuthenticateForDelegation = 16777216,
117+
118+
/// <summary>
119+
/// This is a read-only domain controller account.
120+
/// </summary>
121+
PartialSecretsAccount = 67108864
122+
}

src/Utils/Ldap/Masa.Utils.Ldap.Novell/LdapProvider.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) MASA Stack All rights reserved.
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

4-
using System.Collections.Generic;
5-
64
namespace Masa.Utils.Ldap.Novell;
75

86
public class LdapProvider : ILdapProvider, IDisposable
@@ -14,7 +12,7 @@ public class LdapProvider : ILdapProvider, IDisposable
1412
{
1513
"objectSid", "objectGUID", "objectCategory", "objectClass", "memberOf", "name", "cn", "distinguishedName",
1614
"sAMAccountName", "userPrincipalName", "displayName", "givenName", "sn", "description",
17-
"telephoneNumber", "mail", "streetAddress", "postalCode", "l", "st", "co", "c"
15+
"telephoneNumber", "mail", "streetAddress", "postalCode", "l", "st", "co", "c", "userAccountControl"
1816
};
1917

2018
internal LdapProvider(LdapOptions options)
@@ -233,6 +231,15 @@ private LdapUser CreateUser(string distinguishedName, LdapAttributeSet attribute
233231
ldapUser.Company = attributeSet.GetString("company");
234232
ldapUser.Department = attributeSet.GetString("department");
235233
ldapUser.Title = attributeSet.GetString("title");
234+
235+
if (attributeSet.TryGetValue("userAccountControl", out var userAccountControlAttribute))
236+
{
237+
if (int.TryParse(userAccountControlAttribute.StringValue, out var userAccountControlValue))
238+
{
239+
ldapUser.UserAccountControl = (UserAccountControl)userAccountControlValue;
240+
}
241+
}
242+
236243
ldapUser.Address = new LdapAddress
237244
{
238245
Street = attributeSet.GetString("streetAddress"),

0 commit comments

Comments
 (0)