Skip to content

Commit

Permalink
feat: Add LdapUsersAccountAsync (#1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzh425 authored Jul 22, 2024
1 parent 4b038ed commit d5424a5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

namespace Masa.Auth.Contracts.Admin.Subjects;

public class GetLdapUsersAccountDto
{
public List<Guid> UserIds { get; set; } = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

namespace Masa.Auth.Service.Admin.Application.Subjects.Queries;

public record LdapUsersAccountQuery(List<Guid> UserIds) : Query<Dictionary<Guid, string>>
{
public override Dictionary<Guid, string> Result { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -795,4 +795,24 @@ public async Task GetImpersonatedUserAsync(ImpersonatedUserQuery query)
query.Result = cacheItem;
//await _distributedCacheClient.RemoveAsync(key);
}

[EventHandler]
public async Task GetLdapUsersAccountAsync(LdapUsersAccountQuery query)
{
var identityProvider = await _authDbContext.Set<IdentityProvider>().FirstOrDefaultAsync(x => x.Name == "Ldap");
MasaArgumentException.ThrowIfNull(identityProvider, nameof(IdentityProvider));

var tpUsers = await _thirdPartyUserRepository.GetListAsync(x => x.ThirdPartyIdpId == identityProvider.Id && query.UserIds.Contains(x.UserId));

var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};

query.Result = tpUsers.ToDictionary(x => x.UserId, x =>
{
var ldapUser = JsonSerializer.Deserialize<LdapUser>(x.ExtendedData, options);
return ldapUser?.SamAccountName ?? string.Empty;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public ThirdPartyUserService() : base("api/thirdPartyUser")
{
MapGet(GetAsync, "");
MapPost(RegisterAsync, "register");
MapPost(LdapUsersAccountAsync, "ldapUsersAccount");
}

private async Task<PaginationDto<ThirdPartyUserDto>> GetListAsync(IEventBus eventBus, GetThirdPartyUsersDto tpu)
Expand Down Expand Up @@ -92,4 +93,11 @@ private async Task RemoveByThridPartyIdentityAsync(IEventBus eventBus, [FromBody
{
await eventBus.PublishAsync(new RemoveThirdPartyUserByThridPartyIdentityCommand(dto.ThridPartyIdentity));
}

private async Task<Dictionary<Guid, string>> LdapUsersAccountAsync(IEventBus eventBus, [FromBody] GetLdapUsersAccountDto dto)
{
var query = new LdapUsersAccountQuery(dto.UserIds);
await eventBus.PublishAsync(query);
return query.Result;
}
}

0 comments on commit d5424a5

Please sign in to comment.