Browse Source

feat(data-protected): 增加未授权数据访问异常

pull/1013/head
colin 1 year ago
parent
commit
148c295e70
  1. 5
      aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection.EntityFrameworkCore/LINGYUN/Abp/DataProtection/EntityFrameworkCore/AbpDataProtectedWriteEntityInterceptor.cs
  2. 14
      aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/AbpDataAccessDeniedException.cs
  3. 3
      aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/IDataAuthorizationServiceExtensions.cs

5
aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection.EntityFrameworkCore/LINGYUN/Abp/DataProtection/EntityFrameworkCore/AbpDataProtectedWriteEntityInterceptor.cs

@ -7,7 +7,6 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Authorization;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
@ -40,7 +39,7 @@ public class AbpDataProtectedWriteEntityInterceptor : SaveChangesInterceptor, IT
var entityKeys = updateEntites var entityKeys = updateEntites
.Select(entity => (entity is IEntity abpEntity ? abpEntity.GetKeys() : new string[1] { entity.ToString() }).ToString()) .Select(entity => (entity is IEntity abpEntity ? abpEntity.GetKeys() : new string[1] { entity.ToString() }).ToString())
.JoinAsString(";"); .JoinAsString(";");
throw new AbpAuthorizationException( throw new AbpDataAccessDeniedException(
$"Delete data permission not granted to entity {updateEntites.First().GetType()} for data {entityKeys}!"); $"Delete data permission not granted to entity {updateEntites.First().GetType()} for data {entityKeys}!");
} }
} }
@ -56,7 +55,7 @@ public class AbpDataProtectedWriteEntityInterceptor : SaveChangesInterceptor, IT
var entityKeys = deleteEntites var entityKeys = deleteEntites
.Select(entity => (entity is IEntity abpEntity ? abpEntity.GetKeys() : new string[1] { entity.ToString() }).ToString()) .Select(entity => (entity is IEntity abpEntity ? abpEntity.GetKeys() : new string[1] { entity.ToString() }).ToString())
.JoinAsString(";"); .JoinAsString(";");
throw new AbpAuthorizationException( throw new AbpDataAccessDeniedException(
$"Delete data permission not granted to entity {deleteEntites.First().GetType()} for data {entityKeys}!"); $"Delete data permission not granted to entity {deleteEntites.First().GetType()} for data {entityKeys}!");
} }
} }

14
aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/AbpDataAccessDeniedException.cs

@ -0,0 +1,14 @@
using Volo.Abp;
namespace LINGYUN.Abp.DataProtection;
public class AbpDataAccessDeniedException : BusinessException
{
public AbpDataAccessDeniedException()
{
}
public AbpDataAccessDeniedException(string message)
: base("DataProtection:010001", message)
{
}
}

3
aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/IDataAuthorizationServiceExtensions.cs

@ -1,7 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Authorization;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
namespace LINGYUN.Abp.DataProtection; namespace LINGYUN.Abp.DataProtection;
@ -13,7 +12,7 @@ public static class IDataAuthorizationServiceExtensions
if (!result.Succeeded) if (!result.Succeeded)
{ {
var entityKeys = entities.Select(x => x.ToString()).JoinAsString(";"); var entityKeys = entities.Select(x => x.ToString()).JoinAsString(";");
throw new AbpAuthorizationException( throw new AbpDataAccessDeniedException(
$"The {operation} operation with entity type {typeof(Entity)} identified as {entityKeys} is not allowed!"); $"The {operation} operation with entity type {typeof(Entity)} identified as {entityKeys} is not allowed!");
} }
} }

Loading…
Cancel
Save