Skip to content

Commit

Permalink
feat: 添加登录日志
Browse files Browse the repository at this point in the history
  • Loading branch information
WangJunZzz committed Oct 9, 2023
1 parent 58e04c9 commit 5dda1dd
Show file tree
Hide file tree
Showing 29 changed files with 15,790 additions and 15,137 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Lion.AbpPro.BasicManagement.IdentitySecurityLogs;

public interface IIdentitySecurityLogAppService : IApplicationService
{
/// <summary>
/// 分页获取登录日志
/// </summary>
Task<PagedResultDto<PagingIdentitySecurityLogOutput>> GetListAsync(PagingIdentitySecurityLogInput input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace Lion.AbpPro.BasicManagement.IdentitySecurityLogs;

public class PagingIdentitySecurityLogInput: PagingBase
{
/// <summary>
/// 排序
/// </summary>
public string Sorting { get; set; }

/// <summary>
/// 开始时间
/// </summary>
public DateTime? StartTime { get; set; }

/// <summary>
/// 结束时间
/// </summary>
public DateTime? EndTime { get; set; }

public string Identity { get; set; }

/// <summary>
/// 请求地址
/// </summary>
public string Action { get; set; }

/// <summary>
/// 用户Id
/// </summary>
public Guid? UserId { get; set; }

/// <summary>
/// 用户名
/// </summary>
public string UserName { get; set; }

/// <summary>
/// 应用程序名称
/// </summary>
public string ApplicationName { get; set; }

/// <summary>
/// RequestId
/// </summary>
public string CorrelationId { get; set; }

/// <summary>
/// ClientId
/// </summary>
public string ClientId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Lion.AbpPro.BasicManagement.IdentitySecurityLogs;

public class PagingIdentitySecurityLogOutput
{
public Guid Id { get; set; }

public Guid? TenantId { get; set; }

public string ApplicationName { get; set; }

public string Identity { get; set; }

public string Action { get; set; }

public Guid? UserId { get; set; }

public string UserName { get; set; }

public string TenantName { get; set; }

public string ClientId { get; set; }

public string CorrelationId { get; set; }

public string ClientIpAddress { get; set; }

public string BrowserInfo { get; set; }

public DateTime CreationTime { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public override void Define(IPermissionDefinitionContext context)

var auditManagement =
abpIdentityGroup.AddPermission(BasicManagementPermissions.SystemManagement.AuditLog, L("Permission:AuditLogManagement"), multiTenancySide: MultiTenancySides.Both);
var settingManagement = abpIdentityGroup.AddPermission(BasicManagementPermissions.SystemManagement.Setting, L("Permission:SettingManagement"), multiTenancySide: MultiTenancySides.Both);
abpIdentityGroup.AddPermission(BasicManagementPermissions.SystemManagement.Setting, L("Permission:SettingManagement"), multiTenancySide: MultiTenancySides.Both);
abpIdentityGroup.AddPermission(BasicManagementPermissions.SystemManagement.IdentitySecurityLog, L("Permission:IdentitySecurityLog"), multiTenancySide: MultiTenancySides.Both);
var organizationUnitManagement = abpIdentityGroup.AddPermission(BasicManagementPermissions.SystemManagement.OrganizationUnit, L("Permission:OrganizationUnitManagement"), multiTenancySide: MultiTenancySides.Both);
organizationUnitManagement.AddChild
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class SystemManagement
public const string UserExport = Default + ".Users.Export";
public const string AuditLog = Default + ".AuditLog";
public const string Setting = Default + ".Setting";
public const string IdentitySecurityLog = Default + ".IdentitySecurityLogs";
public const string OrganizationUnit = Default + ".OrganizationUnitManagement";
public static class OrganizationUnitManagement
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoMapper;
using Lion.AbpPro.BasicManagement.AuditLogs;
using Lion.AbpPro.BasicManagement.IdentitySecurityLogs;
using Lion.AbpPro.BasicManagement.Users.Dtos;

namespace Lion.AbpPro.BasicManagement;
Expand Down Expand Up @@ -32,5 +33,6 @@ public BasicManagementApplicationAutoMapperProfile()
CreateMap<IdentityUser, GetUnAddUserOutput>();
CreateMap<IdentityRole, GetOrganizationUnitRoleOutput>();
CreateMap<IdentityRole, GetUnAddRoleOutput>();
CreateMap<IdentitySecurityLog, PagingIdentitySecurityLogOutput>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace Lion.AbpPro.BasicManagement.IdentitySecurityLogs;

public class IdentitySecurityLogAppService : BasicManagementAppService, IIdentitySecurityLogAppService
{
private readonly IIdentitySecurityLogRepository _identitySecurityLogRepository;

public IdentitySecurityLogAppService(IIdentitySecurityLogRepository identitySecurityLogRepository)
{
_identitySecurityLogRepository = identitySecurityLogRepository;
}

[Authorize(Policy = BasicManagementPermissions.SystemManagement.IdentitySecurityLog)]
public virtual async Task<PagedResultDto<PagingIdentitySecurityLogOutput>> GetListAsync(PagingIdentitySecurityLogInput input)
{
var totalCount = await _identitySecurityLogRepository.GetCountAsync(
input.StartTime,
input.EndTime,
input.ApplicationName,
input.Identity,
input.Action,
input.UserId,
input.UserName,
input.ClientId,
input.CorrelationId);
if (totalCount == 0)
{
return new PagedResultDto<PagingIdentitySecurityLogOutput>();
}

var list = await _identitySecurityLogRepository.GetListAsync(
input.Sorting,
input.PageSize,
input.SkipCount,
input.StartTime,
input.EndTime,
input.ApplicationName,
input.Identity,
input.Action,
input.UserId,
input.UserName,
input.ClientId,
input.CorrelationId);

return new PagedResultDto<PagingIdentitySecurityLogOutput>(totalCount, ObjectMapper.Map<List<IdentitySecurityLog>, List<PagingIdentitySecurityLogOutput>>(list));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using IdentityModel;
using Lion.AbpPro.BasicManagement.ConfigurationOptions;
using Lion.AbpPro.BasicManagement.Users.Dtos;
using Microsoft.AspNetCore.Http;
using Microsoft.IdentityModel.Tokens;
using Volo.Abp.Identity.AspNetCore;
using Volo.Abp.Security.Claims;

namespace Lion.AbpPro.BasicManagement.Users
Expand All @@ -13,15 +15,20 @@ public class AccountAppService : BasicManagementAppService, IAccountAppService
{
private readonly IdentityUserManager _userManager;
private readonly JwtOptions _jwtOptions;
private readonly Microsoft.AspNetCore.Identity.SignInManager<IdentityUser> _signInManager;

//private readonly Microsoft.AspNetCore.Identity.SignInManager<IdentityUser> _signInManager;
private readonly IdentitySecurityLogManager _identitySecurityLogManager;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly AbpSignInManager _signInManager;
public AccountAppService(
IdentityUserManager userManager,
IOptionsSnapshot<JwtOptions> jwtOptions,
Microsoft.AspNetCore.Identity.SignInManager<IdentityUser> signInManager)
IdentitySecurityLogManager identitySecurityLogManager,
IHttpContextAccessor httpContextAccessor, AbpSignInManager signInManager)
{
_userManager = userManager;
_jwtOptions = jwtOptions.Value;
_identitySecurityLogManager = identitySecurityLogManager;
_httpContextAccessor = httpContextAccessor;
_signInManager = signInManager;
}

Expand All @@ -41,6 +48,13 @@ public virtual async Task<LoginOutput> LoginAsync(LoginInput input)
}

var user = await _userManager.FindByNameAsync(input.Name);

await _identitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Action = _httpContextAccessor.HttpContext?.Request.Path,
UserName = input.Name,
Identity = "Bearer"
});
return await BuildResult(user);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"Permission:AuditLogManagement": "AuditLog",
"Permission:HangfireManagement": "BackgroundTask",
"Permission:SettingManagement": "SettingManagement",
"Permission:IdentitySecurityLog": "IdentitySecurityLog",
"Permission:OrganizationUnitManagement": "OrganizationUnitManagement",
"Setting.Group.System": "System",
"Lion.AbpPro.BasicManagement:100001": "OrganizationUnit Not Exist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"Permission:SystemManagement": "系统管理",
"Permission:HangfireManagement": "后台任务",
"Permission:SettingManagement": "设置管理",
"Permission:IdentitySecurityLog": "登录日志",
"Permission:OrganizationUnitManagement": "组织结构管理",

"Setting.Group.System": "系统",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Global using directives

global using Lion.AbpPro.BasicManagement.AuditLogs;
global using Lion.AbpPro.BasicManagement.IdentitySecurityLogs;
global using Lion.AbpPro.BasicManagement.OrganizationUnits;
global using Lion.AbpPro.BasicManagement.OrganizationUnits.Dto;
global using Lion.AbpPro.BasicManagement.Roles;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Lion.AbpPro.BasicManagement.Systems;

[Route("IdentitySecurityLogs")]
public class IdentitySecurityLogController : BasicManagementController, IIdentitySecurityLogAppService
{
private readonly IIdentitySecurityLogAppService _identitySecurityLogAppService;

public IdentitySecurityLogController(IIdentitySecurityLogAppService identitySecurityLogAppService)
{
_identitySecurityLogAppService = identitySecurityLogAppService;
}

[HttpPost("page")]
[SwaggerOperation(summary: "分页获取登录日志信息", Tags = new[] { "IdentitySecurityLogs" })]
public Task<PagedResultDto<PagingIdentitySecurityLogOutput>> GetListAsync(PagingIdentitySecurityLogInput input)
{
return _identitySecurityLogAppService.GetListAsync(input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,12 @@ export default {
organizationUnit: 'OrganizationUnit',
member: 'Member',
role: 'Role',
identitySecurityLog: 'IdentitySecurityLog',
identitySecurityLog_ApplicationName: 'ApplicationName',
identitySecurityLog_Identity: 'Identity',
identitySecurityLog_Action: 'Action',
identitySecurityLog_UserName: 'UserName',
identitySecurityLog_CorrelationId: 'CorrelationId',
identitySecurityLog_ClientIpAddress: 'ClientIpAddress',
identitySecurityLog_CreationTime: 'LoginTime',
};
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,12 @@ export default {
organizationUnit: '组织机构',
member: '成员',
role: '角色',
identitySecurityLog: '登录日志',
identitySecurityLog_ApplicationName: '应用程序名称',
identitySecurityLog_Identity: '登录方式',
identitySecurityLog_Action: '登录地址',
identitySecurityLog_UserName: '用户名',
identitySecurityLog_CorrelationId: 'CorrelationId',
identitySecurityLog_ClientIpAddress: '客户端IP',
identitySecurityLog_CreationTime: '登录时间',
};
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ const admin: AppRouteModule = {
icon: 'ant-design:snippets-twotone',
},
},
{
path: 'identitySecurityLogs',
name: 'IdentitySecurityLogs',
component: () => import('/@/views/admin/identitySecurityLog/Index.vue'),
meta: {
title: t('routes.admin.identitySecurityLog'),
policy: 'AbpIdentity.IdentitySecurityLogs',
icon: 'ant-design:file-protect-outlined',
},
},
{
path: 'dataDictionary',
name: 'dataDictionary',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {FormSchema} from '/src/components/Table';
import {BasicColumn} from '/src/components/Table';
import {useI18n} from '/src/hooks/web/useI18n';
import { formatToDateTime, dateUtil } from '/src/utils/dateUtil';
const {t} = useI18n();
import {
IdentitySecurityLogsServiceProxy,
PageIdentitySecurityLogInput,
} from '/src/services/ServiceProxies';

// 分页表格登录日志 BasicColumn
export const tableColumns: BasicColumn[] = [
{
title: t('routes.admin.identitySecurityLog_ApplicationName'),
dataIndex: 'applicationName',
},
{
title: t('routes.admin.identitySecurityLog_Identity'),
dataIndex: 'identity',
},
{
title: t('routes.admin.identitySecurityLog_Action'),
dataIndex: 'action',
},
{
title: t('routes.admin.identitySecurityLog_UserName'),
dataIndex: 'userName',
},
{
title: t('routes.admin.identitySecurityLog_CorrelationId'),
dataIndex: 'correlationId',
},
{
title: t('routes.admin.identitySecurityLog_ClientIpAddress'),
dataIndex: 'clientIpAddress',
},
{
title: t('routes.admin.identitySecurityLog_CreationTime'),
dataIndex: 'creationTime',
customRender: ({ text }) => {
return formatToDateTime(text);
},
},
];

// 分页查询登录日志 FormSchema
export const searchFormSchema: FormSchema[] = [
{
field: 'time',
component: 'RangePicker',
label: t('routes.admin.audit_executeTime'),
colProps: {
span: 4,
},
defaultValue: [dateUtil().subtract(7, 'days'), dateUtil().add(1, 'days')],
},
{
field: 'userName',
label: t('routes.admin.identitySecurityLog_UserName'),
component: 'Input',
colProps: { span: 3 },
},
{
field: 'correlationId',
label: 'CorrelationId',
labelWidth: 95,
component: 'Input',
colProps: { span: 4 },
}
];


/**
* 分页查询登录日志
*/
export async function pageAsync(params: PageIdentitySecurityLogInput,
) {
const identitySecurityLogServiceProxy = new IdentitySecurityLogsServiceProxy();
return identitySecurityLogServiceProxy.page(params);
}
Loading

0 comments on commit 5dda1dd

Please sign in to comment.