Skip to content

Commit

Permalink
Minor feedback items
Browse files Browse the repository at this point in the history
  • Loading branch information
John Luo committed Aug 21, 2020
1 parent ee2c883 commit e38ee28
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate
{
internal static class LdapAdapter
{
public static async Task RetrieveClaimsAsync(LdapOptions options, AuthenticatedContext context, ILogger logger)
public static async Task RetrieveClaimsAsync(LdapOptions options, ClaimsIdentity identity, ILogger logger)
{
if (!options.EnableLdapRoleClaimResolution)
{
return;
}

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

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

var claimsIdentity = context.Principal.Identity as ClaimsIdentity;

foreach (var group in memberof)
{
// Example distinguished name: CN=TestGroup,DC=KERB,DC=local
Expand All @@ -53,11 +51,11 @@ public static async Task RetrieveClaimsAsync(LdapOptions options, AuthenticatedC

if (options.ResolveNestedGroups)
{
GetNestedGroups(options.LdapConnection, claimsIdentity, distinguishedName, groupCN, logger);
GetNestedGroups(options.LdapConnection, identity, distinguishedName, groupCN, logger);
}
else
{
AddRole(claimsIdentity, groupCN);
AddRole(identity, groupCN);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Security/Authentication/Negotiate/src/LdapOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class LdapOptions

/// <summary>
/// This option indicates whether nested groups should be examined when
/// resolving AD Roles.
/// resolving Roles. The default is true.
/// </summary>
public bool ResolveNestedGroups { get; set; } = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
};

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

await Events.Authenticated(authenticatedContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class NegotiateOptions : AuthenticationSchemeOptions
public bool PersistNtlmCredentials { get; set; } = true;

/// <summary>
/// Configuration settings for LDAP connections used to retrieve AD Role claims.
/// Configuration settings for LDAP connections used to retrieve Role claims.
/// This is only used on Linux systems.
/// </summary>
public LdapOptions LdapOptions { get; } = new LdapOptions();
Expand Down

0 comments on commit e38ee28

Please sign in to comment.