Skip to content

Commit e38ee28

Browse files
author
John Luo
committed
Minor feedback items
1 parent ee2c883 commit e38ee28

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

src/Security/Authentication/Negotiate/src/Internal/LdapAdapter.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate
1212
{
1313
internal static class LdapAdapter
1414
{
15-
public static async Task RetrieveClaimsAsync(LdapOptions options, AuthenticatedContext context, ILogger logger)
15+
public static async Task RetrieveClaimsAsync(LdapOptions options, ClaimsIdentity identity, ILogger logger)
1616
{
1717
if (!options.EnableLdapRoleClaimResolution)
1818
{
1919
return;
2020
}
2121

22-
var user = context.Principal.Identity.Name;
22+
var user = identity.Name;
2323
var userAccountName = user.Substring(0, user.IndexOf('@'));
2424
var distinguishedName = options.Domain.Split('.').Select(name => $"dc={name}").Aggregate((a, b) => $"{a},{b}");
2525

@@ -43,8 +43,6 @@ public static async Task RetrieveClaimsAsync(LdapOptions options, AuthenticatedC
4343
var userFound = searchResponse.Entries[0]; //Get the object that was found on ldap
4444
var memberof = userFound.Attributes["memberof"]; // You can access ldap Attributes with Attributes property
4545

46-
var claimsIdentity = context.Principal.Identity as ClaimsIdentity;
47-
4846
foreach (var group in memberof)
4947
{
5048
// Example distinguished name: CN=TestGroup,DC=KERB,DC=local
@@ -53,11 +51,11 @@ public static async Task RetrieveClaimsAsync(LdapOptions options, AuthenticatedC
5351

5452
if (options.ResolveNestedGroups)
5553
{
56-
GetNestedGroups(options.LdapConnection, claimsIdentity, distinguishedName, groupCN, logger);
54+
GetNestedGroups(options.LdapConnection, identity, distinguishedName, groupCN, logger);
5755
}
5856
else
5957
{
60-
AddRole(claimsIdentity, groupCN);
58+
AddRole(identity, groupCN);
6159
}
6260
}
6361
}

src/Security/Authentication/Negotiate/src/LdapOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class LdapOptions
4040

4141
/// <summary>
4242
/// This option indicates whether nested groups should be examined when
43-
/// resolving AD Roles.
43+
/// resolving Roles. The default is true.
4444
/// </summary>
4545
public bool ResolveNestedGroups { get; set; } = true;
4646

src/Security/Authentication/Negotiate/src/NegotiateHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
331331
};
332332

333333
// TODO: persist results
334-
await LdapAdapter.RetrieveClaimsAsync(Options.LdapOptions, authenticatedContext, Logger);
334+
await LdapAdapter.RetrieveClaimsAsync(Options.LdapOptions, authenticatedContext.Principal.Identity as ClaimsIdentity, Logger);
335335

336336
await Events.Authenticated(authenticatedContext);
337337

src/Security/Authentication/Negotiate/src/NegotiateOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class NegotiateOptions : AuthenticationSchemeOptions
3434
public bool PersistNtlmCredentials { get; set; } = true;
3535

3636
/// <summary>
37-
/// Configuration settings for LDAP connections used to retrieve AD Role claims.
37+
/// Configuration settings for LDAP connections used to retrieve Role claims.
3838
/// This is only used on Linux systems.
3939
/// </summary>
4040
public LdapOptions LdapOptions { get; } = new LdapOptions();

0 commit comments

Comments
 (0)