Skip to content

Commit

Permalink
fix: Fix ldap user sync error and execute in the background (#1285)
Browse files Browse the repository at this point in the history
* fix: Domain account synchronization backend execution and logic adjustment

* close popups
  • Loading branch information
wzh425 authored Apr 25, 2024
1 parent 4e08233 commit 99ac087
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 5 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.Service.Admin.Application.Subjects.Jobs;

public class SyncLdapUserArgs
{
public List<LdapUser> LdapUsers { get; set; } = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.Jobs;

public class SyncLdapUserJob : BackgroundJobBase<SyncLdapUserArgs>
{
private readonly LdapDomainService _ldapDomainService;
public SyncLdapUserJob(LdapDomainService ldapDomainService)
{
_ldapDomainService = ldapDomainService;
}

protected override async Task ExecutingAsync(SyncLdapUserArgs args)
{
await _ldapDomainService.SyncLdapUserAsync(args.LdapUsers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public async Task LdapUpsertAsync(LdapUpsertCommand ldapUpsertCommand)

await _unitOfWork.SaveChangesAsync();
var ldapUsers = await ldapProvider.GetAllUserAsync().ToListAsync();
await _ldapDomainService.SyncLdapUserAsync(ldapUsers);

var args = new SyncLdapUserArgs()
{
LdapUsers = ldapUsers
};

await BackgroundJobManager.EnqueueAsync(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ public async Task SyncLdapUserAsync(IList<LdapUser> ldapUsers)
if (ldapUser != null)
{
tpu.User.UpdateBasicInfo(ldapUser.Name, ldapUser.DisplayName, GenderTypes.Male, "", "", "", "", new());
tpu.User.Staff!.UpdateBasicInfo(ldapUser.Name, ldapUser.DisplayName, GenderTypes.Male, ldapUser.Phone, ldapUser.EmailAddress);

if (tpu.User.Staff == null)
{
tpu.User.Bind(new Staff(ldapUser.Name, ldapUser.DisplayName, "", "", ldapUser.Company, GenderTypes.Male, ldapUser.Phone, ldapUser.EmailAddress, GetRelativeId(ldapUser.ObjectSid), null, StaffTypes.Internal, true));
}
else
{
tpu.User.Staff.UpdateBasicInfo(ldapUser.Name, ldapUser.DisplayName, GenderTypes.Male, ldapUser.Phone, ldapUser.EmailAddress);
}
}
});
await _userDomainService.UpdateRangeAsync(thirdPartyUsers.Select(tpu => tpu.User).ToList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<PackageReference Include="Masa.Contrib.Ddd.Domain.Repository.EFCore" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Dispatcher.IntegrationEvents.Dapr" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Dispatcher.IntegrationEvents.EventLogs.EFCore" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Extensions.BackgroundJobs.Memory" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Isolation" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.Isolation.MultiEnvironment" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.ReadWriteSplitting.Cqrs" Version="$(MasaFrameworkPackageVersion)" />
Expand Down
4 changes: 4 additions & 0 deletions src/Services/Masa.Auth.Service.Admin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
.AddElasticsearchAutoComplete();
//todo when scheduler is unready, this code should not run
await builder.Services.AddSchedulerJobAsync();
builder.Services.AddBackgroundJob(options =>
{
options.UseInMemoryDatabase();
});

builder.Services
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
Expand Down
2 changes: 2 additions & 0 deletions src/Services/Masa.Auth.Service.Admin/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
global using Masa.Auth.Service.Admin.Application.Sso.Queries;
global using Masa.Auth.Service.Admin.Application.Subjects.Commands;
global using Masa.Auth.Service.Admin.Application.Subjects.Queries;
global using Masa.Auth.Service.Admin.Application.Subjects.Jobs;
global using Masa.Auth.Service.Admin.Application.Webhooks.Commands;
global using Masa.Auth.Service.Admin.Application.Webhooks.Queries;
global using Masa.Auth.Service.Admin.Domain.Logs.Aggregates;
Expand Down Expand Up @@ -86,6 +87,7 @@
global using Masa.BuildingBlocks.Ddd.Domain.Values;
global using Masa.BuildingBlocks.Dispatcher.Events;
global using Masa.BuildingBlocks.Dispatcher.IntegrationEvents;
global using Masa.BuildingBlocks.Extensions.BackgroundJobs;
global using Masa.BuildingBlocks.Isolation;
global using Masa.BuildingBlocks.ReadWriteSplitting.Cqrs.Commands;
global using Masa.BuildingBlocks.ReadWriteSplitting.Cqrs.Queries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
try
{
await ThirdPartyIdpService.LdapUpsertAsync(_ldapDetailDto);
OpenSuccessMessage(T("LDAP Account Synchroniz Success"));

OpenSuccessMessage(T("LDAPAccountSynchronizPrompt"));
_visible = false;
if (OnSubmitted != null)
{
await OnSubmitted.Invoke();
Expand Down
5 changes: 4 additions & 1 deletion src/Web/Masa.Auth.Web.Admin.Rcl/wwwroot/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,8 @@
"MatchPattern": "Match Pattern",
"MatchPatternTip": "Used in special cases when auto-match left menu is highlighted"
},
"RepeatAdd": "Add Repeatedly"
"RepeatAdd": "Add Repeatedly",
"ThirdPartyIdpBlock": {
"LDAPAccountSynchronizPrompt": "LDAP account synchronization has been executed in the background, please check later"
}
}
1 change: 1 addition & 0 deletions src/Web/Masa.Auth.Web.Admin.Rcl/wwwroot/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"Connect Success": "连接成功",
"Connect Error": "连接失败",
"LDAP Account Synchroniz Success": "域账户同步成功",
"LDAPAccountSynchronizPrompt": "域账户同步已在后台执行,请稍后查看",
"AuthenticationType": "认证类型",
"PlatformType": "平台类型",
"Icon": "图标",
Expand Down

0 comments on commit 99ac087

Please sign in to comment.