15 changed files with 1413 additions and 1413 deletions
@ -1,92 +1,92 @@ |
|||||
using LINGYUN.ApiGateway.Data.Filter; |
using LINGYUN.ApiGateway.Data.Filter; |
||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
using Volo.Abp.Data; |
using Volo.Abp.Data; |
||||
|
|
||||
namespace LINGYUN.ApiGateway.Ocelot |
namespace LINGYUN.ApiGateway.Ocelot |
||||
{ |
{ |
||||
[Authorize(ApiGatewayPermissions.RouteGroup.Default)] |
[Authorize(ApiGatewayPermissions.RouteGroup.Default)] |
||||
public class RouteGroupAppService : ApiGatewayApplicationServiceBase, IRouteGroupAppService |
public class RouteGroupAppService : ApiGatewayApplicationServiceBase, IRouteGroupAppService |
||||
{ |
{ |
||||
protected IDataFilter DataFilter => LazyServiceProvider.LazyGetRequiredService<IDataFilter>(); |
protected IDataFilter DataFilter => LazyServiceProvider.LazyGetRequiredService<IDataFilter>(); |
||||
protected IRouteGroupRepository RouterRepository { get; } |
protected IRouteGroupRepository RouterRepository { get; } |
||||
|
|
||||
public RouteGroupAppService( |
public RouteGroupAppService( |
||||
IRouteGroupRepository routerRepository) |
IRouteGroupRepository routerRepository) |
||||
{ |
{ |
||||
RouterRepository = routerRepository; |
RouterRepository = routerRepository; |
||||
} |
} |
||||
|
|
||||
[Authorize(ApiGatewayPermissions.RouteGroup.Create)] |
[Authorize(ApiGatewayPermissions.RouteGroup.Create)] |
||||
public virtual async Task<RouteGroupDto> CreateAsync(RouteGroupCreateDto input) |
public virtual async Task<RouteGroupDto> CreateAsync(RouteGroupCreateDto input) |
||||
{ |
{ |
||||
var router = new RouteGroup(input.AppId, input.AppName, input.AppIpAddress); |
var router = new RouteGroup(input.AppId, input.AppName, input.AppIpAddress); |
||||
router.Name = input.Name; |
router.Name = input.Name; |
||||
router.IsActive = input.IsActive; |
router.IsActive = input.IsActive; |
||||
router.Description = input.Description; |
router.Description = input.Description; |
||||
|
|
||||
router = await RouterRepository.InsertAsync(router, true); |
router = await RouterRepository.InsertAsync(router, true); |
||||
|
|
||||
return ObjectMapper.Map<RouteGroup, RouteGroupDto>(router); |
return ObjectMapper.Map<RouteGroup, RouteGroupDto>(router); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<RouteGroupDto> GetAsync(RouteGroupGetByAppIdInputDto input) |
public virtual async Task<RouteGroupDto> GetAsync(RouteGroupGetByAppIdInputDto input) |
||||
{ |
{ |
||||
using (DataFilter.Disable<IActivation>()) |
using (DataFilter.Disable<IActivation>()) |
||||
{ |
{ |
||||
var router = await RouterRepository.GetByAppIdAsync(input.AppId); |
var router = await RouterRepository.GetByAppIdAsync(input.AppId); |
||||
|
|
||||
return ObjectMapper.Map<RouteGroup, RouteGroupDto>(router); |
return ObjectMapper.Map<RouteGroup, RouteGroupDto>(router); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ListResultDto<RouteGroupAppIdsDto>> GetActivedAsync() |
public virtual async Task<ListResultDto<RouteGroupAppIdsDto>> GetActivedAsync() |
||||
{ |
{ |
||||
var appIdsDto = new List<RouteGroupAppIdsDto>(); |
var appIdsDto = new List<RouteGroupAppIdsDto>(); |
||||
var appKeys = await RouterRepository.GetActivedAppsAsync(); |
var appKeys = await RouterRepository.GetActivedAppsAsync(); |
||||
|
|
||||
foreach(var app in appKeys) |
foreach(var app in appKeys) |
||||
{ |
{ |
||||
appIdsDto.Add(new RouteGroupAppIdsDto(app.AppId, app.AppName)); |
appIdsDto.Add(new RouteGroupAppIdsDto(app.AppId, app.AppName)); |
||||
} |
} |
||||
|
|
||||
return new ListResultDto<RouteGroupAppIdsDto>(appIdsDto); |
return new ListResultDto<RouteGroupAppIdsDto>(appIdsDto); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<PagedResultDto<RouteGroupDto>> GetAsync(RouteGroupGetByPagedInputDto input) |
public virtual async Task<PagedResultDto<RouteGroupDto>> GetAsync(RouteGroupGetByPagedInputDto input) |
||||
{ |
{ |
||||
using (DataFilter.Disable<IActivation>()) |
using (DataFilter.Disable<IActivation>()) |
||||
{ |
{ |
||||
var (Routers, TotalCount) = await RouterRepository.GetPagedListAsync(input.Filter, |
var (Routers, TotalCount) = await RouterRepository.GetPagedListAsync(input.Filter, |
||||
input.Sorting, input.SkipCount, input.MaxResultCount); |
input.Sorting, input.SkipCount, input.MaxResultCount); |
||||
var routers = ObjectMapper.Map<List<RouteGroup>, List<RouteGroupDto>>(Routers); |
var routers = ObjectMapper.Map<List<RouteGroup>, List<RouteGroupDto>>(Routers); |
||||
|
|
||||
return new PagedResultDto<RouteGroupDto>(TotalCount, routers); |
return new PagedResultDto<RouteGroupDto>(TotalCount, routers); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
[Authorize(ApiGatewayPermissions.RouteGroup.Update)] |
[Authorize(ApiGatewayPermissions.RouteGroup.Update)] |
||||
public virtual async Task<RouteGroupDto> UpdateAsync(RouteGroupUpdateDto input) |
public virtual async Task<RouteGroupDto> UpdateAsync(RouteGroupUpdateDto input) |
||||
{ |
{ |
||||
var router = await RouterRepository.GetByAppIdAsync(input.AppId); |
var router = await RouterRepository.GetByAppIdAsync(input.AppId); |
||||
router.Name = input.Name; |
router.Name = input.Name; |
||||
router.IsActive = input.IsActive; |
router.IsActive = input.IsActive; |
||||
router.Description = input.Description; |
router.Description = input.Description; |
||||
router.SwitchApp(input.AppName, input.AppIpAddress); |
router.SwitchApp(input.AppName, input.AppIpAddress); |
||||
|
|
||||
await RouterRepository.UpdateAsync(router); |
await RouterRepository.UpdateAsync(router); |
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
return ObjectMapper.Map<RouteGroup, RouteGroupDto>(router); |
return ObjectMapper.Map<RouteGroup, RouteGroupDto>(router); |
||||
} |
} |
||||
|
|
||||
[Authorize(ApiGatewayPermissions.RouteGroup.Delete)] |
[Authorize(ApiGatewayPermissions.RouteGroup.Delete)] |
||||
public virtual async Task DeleteAsync(RouteGroupGetByAppIdInputDto input) |
public virtual async Task DeleteAsync(RouteGroupGetByAppIdInputDto input) |
||||
{ |
{ |
||||
var router = await RouterRepository.GetByAppIdAsync(input.AppId); |
var router = await RouterRepository.GetByAppIdAsync(input.AppId); |
||||
await RouterRepository.DeleteAsync(router); |
await RouterRepository.DeleteAsync(router); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,129 +1,129 @@ |
|||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
using System; |
using System; |
||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp; |
using Volo.Abp; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
using Volo.Abp.Identity; |
using Volo.Abp.Identity; |
||||
|
|
||||
namespace LINGYUN.Abp.Identity |
namespace LINGYUN.Abp.Identity |
||||
{ |
{ |
||||
[Authorize(IdentityPermissions.IdentityClaimType.Default)] |
[Authorize(IdentityPermissions.IdentityClaimType.Default)] |
||||
public class IdentityClaimTypeAppService : IdentityAppServiceBase, IIdentityClaimTypeAppService |
public class IdentityClaimTypeAppService : IdentityAppServiceBase, IIdentityClaimTypeAppService |
||||
{ |
{ |
||||
protected IdentityClaimTypeManager IdentityClaimTypeManager { get; } |
protected IdentityClaimTypeManager IdentityClaimTypeManager { get; } |
||||
|
|
||||
protected IIdentityClaimTypeRepository IdentityClaimTypeRepository { get; } |
protected IIdentityClaimTypeRepository IdentityClaimTypeRepository { get; } |
||||
|
|
||||
public IdentityClaimTypeAppService( |
public IdentityClaimTypeAppService( |
||||
IdentityClaimTypeManager identityClaimTypeManager, |
IdentityClaimTypeManager identityClaimTypeManager, |
||||
IIdentityClaimTypeRepository identityClaimTypeRepository) |
IIdentityClaimTypeRepository identityClaimTypeRepository) |
||||
{ |
{ |
||||
IdentityClaimTypeManager = identityClaimTypeManager; |
IdentityClaimTypeManager = identityClaimTypeManager; |
||||
IdentityClaimTypeRepository = identityClaimTypeRepository; |
IdentityClaimTypeRepository = identityClaimTypeRepository; |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.IdentityClaimType.Create)] |
[Authorize(IdentityPermissions.IdentityClaimType.Create)] |
||||
public virtual async Task<IdentityClaimTypeDto> CreateAsync(IdentityClaimTypeCreateDto input) |
public virtual async Task<IdentityClaimTypeDto> CreateAsync(IdentityClaimTypeCreateDto input) |
||||
{ |
{ |
||||
if (await IdentityClaimTypeRepository.AnyAsync(input.Name)) |
if (await IdentityClaimTypeRepository.AnyAsync(input.Name)) |
||||
{ |
{ |
||||
throw new UserFriendlyException(L["IdentityClaimTypeAlreadyExists", input.Name]); |
throw new UserFriendlyException(L["IdentityClaimTypeAlreadyExists", input.Name]); |
||||
} |
} |
||||
var identityClaimType = new IdentityClaimType( |
var identityClaimType = new IdentityClaimType( |
||||
GuidGenerator.Create(), |
GuidGenerator.Create(), |
||||
input.Name, |
input.Name, |
||||
input.Required, |
input.Required, |
||||
input.IsStatic, |
input.IsStatic, |
||||
input.Regex, |
input.Regex, |
||||
input.RegexDescription, |
input.RegexDescription, |
||||
input.Description, |
input.Description, |
||||
input.ValueType |
input.ValueType |
||||
); |
); |
||||
identityClaimType = await IdentityClaimTypeManager.CreateAsync(identityClaimType); |
identityClaimType = await IdentityClaimTypeManager.CreateAsync(identityClaimType); |
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
return ObjectMapper.Map<IdentityClaimType, IdentityClaimTypeDto>(identityClaimType); |
return ObjectMapper.Map<IdentityClaimType, IdentityClaimTypeDto>(identityClaimType); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.IdentityClaimType.Delete)] |
[Authorize(IdentityPermissions.IdentityClaimType.Delete)] |
||||
public virtual async Task DeleteAsync(Guid id) |
public virtual async Task DeleteAsync(Guid id) |
||||
{ |
{ |
||||
var identityClaimType = await IdentityClaimTypeRepository.FindAsync(id); |
var identityClaimType = await IdentityClaimTypeRepository.FindAsync(id); |
||||
if (identityClaimType == null) |
if (identityClaimType == null) |
||||
{ |
{ |
||||
return; |
return; |
||||
} |
} |
||||
CheckDeletionClaimType(identityClaimType); |
CheckDeletionClaimType(identityClaimType); |
||||
await IdentityClaimTypeRepository.DeleteAsync(identityClaimType); |
await IdentityClaimTypeRepository.DeleteAsync(identityClaimType); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<IdentityClaimTypeDto> GetAsync(Guid id) |
public virtual async Task<IdentityClaimTypeDto> GetAsync(Guid id) |
||||
{ |
{ |
||||
var identityClaimType = await IdentityClaimTypeRepository.FindAsync(id); |
var identityClaimType = await IdentityClaimTypeRepository.FindAsync(id); |
||||
|
|
||||
return ObjectMapper.Map<IdentityClaimType, IdentityClaimTypeDto>(identityClaimType); |
return ObjectMapper.Map<IdentityClaimType, IdentityClaimTypeDto>(identityClaimType); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ListResultDto<IdentityClaimTypeDto>> GetAllListAsync() |
public virtual async Task<ListResultDto<IdentityClaimTypeDto>> GetAllListAsync() |
||||
{ |
{ |
||||
var identityClaimTypes = await IdentityClaimTypeRepository |
var identityClaimTypes = await IdentityClaimTypeRepository |
||||
.GetListAsync(); |
.GetListAsync(); |
||||
|
|
||||
return new ListResultDto<IdentityClaimTypeDto>( |
return new ListResultDto<IdentityClaimTypeDto>( |
||||
ObjectMapper.Map<List<IdentityClaimType>, List<IdentityClaimTypeDto>>(identityClaimTypes)); |
ObjectMapper.Map<List<IdentityClaimType>, List<IdentityClaimTypeDto>>(identityClaimTypes)); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<PagedResultDto<IdentityClaimTypeDto>> GetListAsync(IdentityClaimTypeGetByPagedDto input) |
public virtual async Task<PagedResultDto<IdentityClaimTypeDto>> GetListAsync(IdentityClaimTypeGetByPagedDto input) |
||||
{ |
{ |
||||
var identityClaimTypeCount = await IdentityClaimTypeRepository.GetCountAsync(input.Filter); |
var identityClaimTypeCount = await IdentityClaimTypeRepository.GetCountAsync(input.Filter); |
||||
|
|
||||
var identityClaimTypes = await IdentityClaimTypeRepository |
var identityClaimTypes = await IdentityClaimTypeRepository |
||||
.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter); |
.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter); |
||||
|
|
||||
return new PagedResultDto<IdentityClaimTypeDto>(identityClaimTypeCount, |
return new PagedResultDto<IdentityClaimTypeDto>(identityClaimTypeCount, |
||||
ObjectMapper.Map<List<IdentityClaimType>, List<IdentityClaimTypeDto>>(identityClaimTypes)); |
ObjectMapper.Map<List<IdentityClaimType>, List<IdentityClaimTypeDto>>(identityClaimTypes)); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.IdentityClaimType.Update)] |
[Authorize(IdentityPermissions.IdentityClaimType.Update)] |
||||
public virtual async Task<IdentityClaimTypeDto> UpdateAsync(Guid id, IdentityClaimTypeUpdateDto input) |
public virtual async Task<IdentityClaimTypeDto> UpdateAsync(Guid id, IdentityClaimTypeUpdateDto input) |
||||
{ |
{ |
||||
var identityClaimType = await IdentityClaimTypeRepository.GetAsync(id); |
var identityClaimType = await IdentityClaimTypeRepository.GetAsync(id); |
||||
CheckChangingClaimType(identityClaimType); |
CheckChangingClaimType(identityClaimType); |
||||
identityClaimType.Required = input.Required; |
identityClaimType.Required = input.Required; |
||||
if (!string.Equals(identityClaimType.Regex, input.Regex, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(identityClaimType.Regex, input.Regex, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
identityClaimType.Regex = input.Regex; |
identityClaimType.Regex = input.Regex; |
||||
} |
} |
||||
if (!string.Equals(identityClaimType.RegexDescription, input.RegexDescription, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(identityClaimType.RegexDescription, input.RegexDescription, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
identityClaimType.RegexDescription = input.RegexDescription; |
identityClaimType.RegexDescription = input.RegexDescription; |
||||
} |
} |
||||
if (!string.Equals(identityClaimType.Description, input.Description, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(identityClaimType.Description, input.Description, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
identityClaimType.Description = input.Description; |
identityClaimType.Description = input.Description; |
||||
} |
} |
||||
|
|
||||
identityClaimType = await IdentityClaimTypeManager.UpdateAsync(identityClaimType); |
identityClaimType = await IdentityClaimTypeManager.UpdateAsync(identityClaimType); |
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
return ObjectMapper.Map<IdentityClaimType, IdentityClaimTypeDto>(identityClaimType); |
return ObjectMapper.Map<IdentityClaimType, IdentityClaimTypeDto>(identityClaimType); |
||||
} |
} |
||||
|
|
||||
protected virtual void CheckChangingClaimType(IdentityClaimType claimType) |
protected virtual void CheckChangingClaimType(IdentityClaimType claimType) |
||||
{ |
{ |
||||
if (claimType.IsStatic) |
if (claimType.IsStatic) |
||||
{ |
{ |
||||
throw new BusinessException(IdentityErrorCodes.StaticClaimTypeChange); |
throw new BusinessException(IdentityErrorCodes.StaticClaimTypeChange); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
protected virtual void CheckDeletionClaimType(IdentityClaimType claimType) |
protected virtual void CheckDeletionClaimType(IdentityClaimType claimType) |
||||
{ |
{ |
||||
if (claimType.IsStatic) |
if (claimType.IsStatic) |
||||
{ |
{ |
||||
throw new BusinessException(IdentityErrorCodes.StaticClaimTypeDeletion); |
throw new BusinessException(IdentityErrorCodes.StaticClaimTypeDeletion); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,123 +1,123 @@ |
|||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
using System; |
using System; |
||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.Linq; |
using System.Linq; |
||||
using System.Security.Claims; |
using System.Security.Claims; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp; |
using Volo.Abp; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
using Volo.Abp.Identity; |
using Volo.Abp.Identity; |
||||
|
|
||||
namespace LINGYUN.Abp.Identity |
namespace LINGYUN.Abp.Identity |
||||
{ |
{ |
||||
[Authorize(Volo.Abp.Identity.IdentityPermissions.Roles.Default)] |
[Authorize(Volo.Abp.Identity.IdentityPermissions.Roles.Default)] |
||||
public class IdentityRoleAppService : IdentityAppServiceBase, IIdentityRoleAppService |
public class IdentityRoleAppService : IdentityAppServiceBase, IIdentityRoleAppService |
||||
{ |
{ |
||||
protected IIdentityRoleRepository IdentityRoleRepository { get; } |
protected IIdentityRoleRepository IdentityRoleRepository { get; } |
||||
protected OrganizationUnitManager OrganizationUnitManager { get; } |
protected OrganizationUnitManager OrganizationUnitManager { get; } |
||||
protected IOrganizationUnitRepository OrganizationUnitRepository { get; } |
protected IOrganizationUnitRepository OrganizationUnitRepository { get; } |
||||
public IdentityRoleAppService( |
public IdentityRoleAppService( |
||||
IIdentityRoleRepository roleRepository, |
IIdentityRoleRepository roleRepository, |
||||
OrganizationUnitManager organizationUnitManager) |
OrganizationUnitManager organizationUnitManager) |
||||
{ |
{ |
||||
OrganizationUnitManager = organizationUnitManager; |
OrganizationUnitManager = organizationUnitManager; |
||||
IdentityRoleRepository = roleRepository; |
IdentityRoleRepository = roleRepository; |
||||
} |
} |
||||
|
|
||||
#region OrganizationUnit
|
#region OrganizationUnit
|
||||
|
|
||||
[Authorize(IdentityPermissions.Roles.ManageOrganizationUnits)] |
[Authorize(IdentityPermissions.Roles.ManageOrganizationUnits)] |
||||
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetOrganizationUnitsAsync(Guid id) |
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetOrganizationUnitsAsync(Guid id) |
||||
{ |
{ |
||||
var origanizationUnits = await IdentityRoleRepository.GetOrganizationUnitsAsync(id); |
var origanizationUnits = await IdentityRoleRepository.GetOrganizationUnitsAsync(id); |
||||
|
|
||||
return new ListResultDto<OrganizationUnitDto>( |
return new ListResultDto<OrganizationUnitDto>( |
||||
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnits)); |
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnits)); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.Roles.ManageOrganizationUnits)] |
[Authorize(IdentityPermissions.Roles.ManageOrganizationUnits)] |
||||
public virtual async Task SetOrganizationUnitsAsync(Guid id, IdentityRoleAddOrRemoveOrganizationUnitDto input) |
public virtual async Task SetOrganizationUnitsAsync(Guid id, IdentityRoleAddOrRemoveOrganizationUnitDto input) |
||||
{ |
{ |
||||
var origanizationUnits = await IdentityRoleRepository.GetOrganizationUnitsAsync(id, true); |
var origanizationUnits = await IdentityRoleRepository.GetOrganizationUnitsAsync(id, true); |
||||
|
|
||||
var notInRoleOuIds = input.OrganizationUnitIds.Where(ouid => !origanizationUnits.Any(ou => ou.Id.Equals(ouid))); |
var notInRoleOuIds = input.OrganizationUnitIds.Where(ouid => !origanizationUnits.Any(ou => ou.Id.Equals(ouid))); |
||||
|
|
||||
foreach (var ouId in notInRoleOuIds) |
foreach (var ouId in notInRoleOuIds) |
||||
{ |
{ |
||||
await OrganizationUnitManager.AddRoleToOrganizationUnitAsync(id, ouId); |
await OrganizationUnitManager.AddRoleToOrganizationUnitAsync(id, ouId); |
||||
} |
} |
||||
|
|
||||
var removeRoleOriganzationUnits = origanizationUnits.Where(ou => !input.OrganizationUnitIds.Contains(ou.Id)); |
var removeRoleOriganzationUnits = origanizationUnits.Where(ou => !input.OrganizationUnitIds.Contains(ou.Id)); |
||||
foreach (var origanzationUnit in removeRoleOriganzationUnits) |
foreach (var origanzationUnit in removeRoleOriganzationUnits) |
||||
{ |
{ |
||||
origanzationUnit.RemoveRole(id); |
origanzationUnit.RemoveRole(id); |
||||
} |
} |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.Roles.ManageOrganizationUnits)] |
[Authorize(IdentityPermissions.Roles.ManageOrganizationUnits)] |
||||
public virtual async Task RemoveOrganizationUnitsAsync(Guid id, Guid ouId) |
public virtual async Task RemoveOrganizationUnitsAsync(Guid id, Guid ouId) |
||||
{ |
{ |
||||
await OrganizationUnitManager.RemoveRoleFromOrganizationUnitAsync(id, ouId); |
await OrganizationUnitManager.RemoveRoleFromOrganizationUnitAsync(id, ouId); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
} |
} |
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
#region ClaimType
|
#region ClaimType
|
||||
|
|
||||
public virtual async Task<ListResultDto<IdentityClaimDto>> GetClaimsAsync(Guid id) |
public virtual async Task<ListResultDto<IdentityClaimDto>> GetClaimsAsync(Guid id) |
||||
{ |
{ |
||||
var role = await IdentityRoleRepository.GetAsync(id); |
var role = await IdentityRoleRepository.GetAsync(id); |
||||
|
|
||||
return new ListResultDto<IdentityClaimDto>(ObjectMapper.Map<ICollection<IdentityRoleClaim>, List<IdentityClaimDto>>(role.Claims)); |
return new ListResultDto<IdentityClaimDto>(ObjectMapper.Map<ICollection<IdentityRoleClaim>, List<IdentityClaimDto>>(role.Claims)); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.Roles.ManageClaims)] |
[Authorize(IdentityPermissions.Roles.ManageClaims)] |
||||
public virtual async Task AddClaimAsync(Guid id, IdentityRoleClaimCreateDto input) |
public virtual async Task AddClaimAsync(Guid id, IdentityRoleClaimCreateDto input) |
||||
{ |
{ |
||||
var role = await IdentityRoleRepository.GetAsync(id); |
var role = await IdentityRoleRepository.GetAsync(id); |
||||
var claim = new Claim(input.ClaimType, input.ClaimValue); |
var claim = new Claim(input.ClaimType, input.ClaimValue); |
||||
if (role.FindClaim(claim) != null) |
if (role.FindClaim(claim) != null) |
||||
{ |
{ |
||||
throw new UserFriendlyException(L["RoleClaimAlreadyExists"]); |
throw new UserFriendlyException(L["RoleClaimAlreadyExists"]); |
||||
} |
} |
||||
|
|
||||
role.AddClaim(GuidGenerator, claim); |
role.AddClaim(GuidGenerator, claim); |
||||
await IdentityRoleRepository.UpdateAsync(role); |
await IdentityRoleRepository.UpdateAsync(role); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.Roles.ManageClaims)] |
[Authorize(IdentityPermissions.Roles.ManageClaims)] |
||||
public virtual async Task UpdateClaimAsync(Guid id, IdentityRoleClaimUpdateDto input) |
public virtual async Task UpdateClaimAsync(Guid id, IdentityRoleClaimUpdateDto input) |
||||
{ |
{ |
||||
var role = await IdentityRoleRepository.GetAsync(id); |
var role = await IdentityRoleRepository.GetAsync(id); |
||||
var oldClaim = role.FindClaim(new Claim(input.ClaimType, input.ClaimValue)); |
var oldClaim = role.FindClaim(new Claim(input.ClaimType, input.ClaimValue)); |
||||
if (oldClaim != null) |
if (oldClaim != null) |
||||
{ |
{ |
||||
role.RemoveClaim(oldClaim.ToClaim()); |
role.RemoveClaim(oldClaim.ToClaim()); |
||||
role.AddClaim(GuidGenerator, new Claim(input.ClaimType, input.NewClaimValue)); |
role.AddClaim(GuidGenerator, new Claim(input.ClaimType, input.NewClaimValue)); |
||||
|
|
||||
await IdentityRoleRepository.UpdateAsync(role); |
await IdentityRoleRepository.UpdateAsync(role); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.Roles.ManageClaims)] |
[Authorize(IdentityPermissions.Roles.ManageClaims)] |
||||
public virtual async Task DeleteClaimAsync(Guid id, IdentityRoleClaimDeleteDto input) |
public virtual async Task DeleteClaimAsync(Guid id, IdentityRoleClaimDeleteDto input) |
||||
{ |
{ |
||||
var role = await IdentityRoleRepository.GetAsync(id); |
var role = await IdentityRoleRepository.GetAsync(id); |
||||
role.RemoveClaim(new Claim(input.ClaimType, input.ClaimValue)); |
role.RemoveClaim(new Claim(input.ClaimType, input.ClaimValue)); |
||||
|
|
||||
await IdentityRoleRepository.UpdateAsync(role); |
await IdentityRoleRepository.UpdateAsync(role); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
} |
} |
||||
|
|
||||
#endregion
|
#endregion
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,236 +1,236 @@ |
|||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
using System; |
using System; |
||||
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.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
using Volo.Abp.Identity; |
using Volo.Abp.Identity; |
||||
using Volo.Abp.ObjectExtending; |
using Volo.Abp.ObjectExtending; |
||||
|
|
||||
namespace LINGYUN.Abp.Identity |
namespace LINGYUN.Abp.Identity |
||||
{ |
{ |
||||
[Authorize(IdentityPermissions.OrganizationUnits.Default)] |
[Authorize(IdentityPermissions.OrganizationUnits.Default)] |
||||
public class OrganizationUnitAppService : IdentityAppServiceBase, IOrganizationUnitAppService |
public class OrganizationUnitAppService : IdentityAppServiceBase, IOrganizationUnitAppService |
||||
{ |
{ |
||||
protected OrganizationUnitManager OrganizationUnitManager { get; } |
protected OrganizationUnitManager OrganizationUnitManager { get; } |
||||
protected IOrganizationUnitRepository OrganizationUnitRepository { get; } |
protected IOrganizationUnitRepository OrganizationUnitRepository { get; } |
||||
|
|
||||
protected IdentityUserManager UserManager { get; } |
protected IdentityUserManager UserManager { get; } |
||||
protected IIdentityRoleRepository RoleRepository { get; } |
protected IIdentityRoleRepository RoleRepository { get; } |
||||
protected IIdentityUserRepository UserRepository { get; } |
protected IIdentityUserRepository UserRepository { get; } |
||||
|
|
||||
public OrganizationUnitAppService( |
public OrganizationUnitAppService( |
||||
IdentityUserManager userManager, |
IdentityUserManager userManager, |
||||
IIdentityRoleRepository roleRepository, |
IIdentityRoleRepository roleRepository, |
||||
IIdentityUserRepository userRepository, |
IIdentityUserRepository userRepository, |
||||
OrganizationUnitManager organizationUnitManager, |
OrganizationUnitManager organizationUnitManager, |
||||
IOrganizationUnitRepository organizationUnitRepository) |
IOrganizationUnitRepository organizationUnitRepository) |
||||
{ |
{ |
||||
UserManager = userManager; |
UserManager = userManager; |
||||
RoleRepository = roleRepository; |
RoleRepository = roleRepository; |
||||
UserRepository = userRepository; |
UserRepository = userRepository; |
||||
OrganizationUnitManager = organizationUnitManager; |
OrganizationUnitManager = organizationUnitManager; |
||||
OrganizationUnitRepository = organizationUnitRepository; |
OrganizationUnitRepository = organizationUnitRepository; |
||||
|
|
||||
ObjectMapperContext = typeof(AbpIdentityApplicationModule); |
ObjectMapperContext = typeof(AbpIdentityApplicationModule); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.Create)] |
[Authorize(IdentityPermissions.OrganizationUnits.Create)] |
||||
public virtual async Task<OrganizationUnitDto> CreateAsync(OrganizationUnitCreateDto input) |
public virtual async Task<OrganizationUnitDto> CreateAsync(OrganizationUnitCreateDto input) |
||||
{ |
{ |
||||
var origanizationUnit = new OrganizationUnit( |
var origanizationUnit = new OrganizationUnit( |
||||
GuidGenerator.Create(), input.DisplayName, input.ParentId, CurrentTenant.Id) |
GuidGenerator.Create(), input.DisplayName, input.ParentId, CurrentTenant.Id) |
||||
{ |
{ |
||||
CreationTime = Clock.Now |
CreationTime = Clock.Now |
||||
}; |
}; |
||||
input.MapExtraPropertiesTo(origanizationUnit); |
input.MapExtraPropertiesTo(origanizationUnit); |
||||
|
|
||||
await OrganizationUnitManager.CreateAsync(origanizationUnit); |
await OrganizationUnitManager.CreateAsync(origanizationUnit); |
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
return ObjectMapper.Map<OrganizationUnit, OrganizationUnitDto>(origanizationUnit); |
return ObjectMapper.Map<OrganizationUnit, OrganizationUnitDto>(origanizationUnit); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.Delete)] |
[Authorize(IdentityPermissions.OrganizationUnits.Delete)] |
||||
public virtual async Task DeleteAsync(Guid id) |
public virtual async Task DeleteAsync(Guid id) |
||||
{ |
{ |
||||
var origanizationUnit = await OrganizationUnitRepository.FindAsync(id); |
var origanizationUnit = await OrganizationUnitRepository.FindAsync(id); |
||||
if (origanizationUnit == null) |
if (origanizationUnit == null) |
||||
{ |
{ |
||||
return; |
return; |
||||
} |
} |
||||
await OrganizationUnitManager.DeleteAsync(id); |
await OrganizationUnitManager.DeleteAsync(id); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetRootAsync() |
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetRootAsync() |
||||
{ |
{ |
||||
var rootOriganizationUnits = await OrganizationUnitManager.FindChildrenAsync(null, recursive: false); |
var rootOriganizationUnits = await OrganizationUnitManager.FindChildrenAsync(null, recursive: false); |
||||
|
|
||||
return new ListResultDto<OrganizationUnitDto>( |
return new ListResultDto<OrganizationUnitDto>( |
||||
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(rootOriganizationUnits)); |
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(rootOriganizationUnits)); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ListResultDto<OrganizationUnitDto>> FindChildrenAsync(OrganizationUnitGetChildrenDto input) |
public virtual async Task<ListResultDto<OrganizationUnitDto>> FindChildrenAsync(OrganizationUnitGetChildrenDto input) |
||||
{ |
{ |
||||
var origanizationUnitChildren = await OrganizationUnitManager.FindChildrenAsync(input.Id, input.Recursive); |
var origanizationUnitChildren = await OrganizationUnitManager.FindChildrenAsync(input.Id, input.Recursive); |
||||
|
|
||||
return new ListResultDto<OrganizationUnitDto>( |
return new ListResultDto<OrganizationUnitDto>( |
||||
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnitChildren)); |
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnitChildren)); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<OrganizationUnitDto> GetAsync(Guid id) |
public virtual async Task<OrganizationUnitDto> GetAsync(Guid id) |
||||
{ |
{ |
||||
var origanizationUnit = await OrganizationUnitRepository.FindAsync(id); |
var origanizationUnit = await OrganizationUnitRepository.FindAsync(id); |
||||
|
|
||||
return ObjectMapper.Map<OrganizationUnit, OrganizationUnitDto>(origanizationUnit); |
return ObjectMapper.Map<OrganizationUnit, OrganizationUnitDto>(origanizationUnit); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<OrganizationUnitDto> GetLastChildOrNullAsync(Guid? parentId) |
public virtual async Task<OrganizationUnitDto> GetLastChildOrNullAsync(Guid? parentId) |
||||
{ |
{ |
||||
var origanizationUnitLastChildren = await OrganizationUnitManager.GetLastChildOrNullAsync(parentId); |
var origanizationUnitLastChildren = await OrganizationUnitManager.GetLastChildOrNullAsync(parentId); |
||||
|
|
||||
return ObjectMapper.Map<OrganizationUnit, OrganizationUnitDto>(origanizationUnitLastChildren); |
return ObjectMapper.Map<OrganizationUnit, OrganizationUnitDto>(origanizationUnitLastChildren); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetAllListAsync() |
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetAllListAsync() |
||||
{ |
{ |
||||
var origanizationUnits = await OrganizationUnitRepository.GetListAsync(false); |
var origanizationUnits = await OrganizationUnitRepository.GetListAsync(false); |
||||
|
|
||||
return new ListResultDto<OrganizationUnitDto>( |
return new ListResultDto<OrganizationUnitDto>( |
||||
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnits)); |
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnits)); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<PagedResultDto<OrganizationUnitDto>> GetListAsync(OrganizationUnitGetByPagedDto input) |
public virtual async Task<PagedResultDto<OrganizationUnitDto>> GetListAsync(OrganizationUnitGetByPagedDto input) |
||||
{ |
{ |
||||
var origanizationUnitCount = await OrganizationUnitRepository.GetCountAsync(); |
var origanizationUnitCount = await OrganizationUnitRepository.GetCountAsync(); |
||||
var origanizationUnits = await OrganizationUnitRepository |
var origanizationUnits = await OrganizationUnitRepository |
||||
.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, false); |
.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, false); |
||||
|
|
||||
return new PagedResultDto<OrganizationUnitDto>(origanizationUnitCount, |
return new PagedResultDto<OrganizationUnitDto>(origanizationUnitCount, |
||||
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnits)); |
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnits)); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.ManageRoles)] |
[Authorize(IdentityPermissions.OrganizationUnits.ManageRoles)] |
||||
public virtual async Task<ListResultDto<string>> GetRoleNamesAsync(Guid id) |
public virtual async Task<ListResultDto<string>> GetRoleNamesAsync(Guid id) |
||||
{ |
{ |
||||
var inOrignizationUnitRoleNames = await UserRepository.GetRoleNamesInOrganizationUnitAsync(id); |
var inOrignizationUnitRoleNames = await UserRepository.GetRoleNamesInOrganizationUnitAsync(id); |
||||
return new ListResultDto<string>(inOrignizationUnitRoleNames); |
return new ListResultDto<string>(inOrignizationUnitRoleNames); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.ManageRoles)] |
[Authorize(IdentityPermissions.OrganizationUnits.ManageRoles)] |
||||
public virtual async Task<PagedResultDto<IdentityRoleDto>> GetUnaddedRolesAsync(Guid id, OrganizationUnitGetUnaddedRoleByPagedDto input) |
public virtual async Task<PagedResultDto<IdentityRoleDto>> GetUnaddedRolesAsync(Guid id, OrganizationUnitGetUnaddedRoleByPagedDto input) |
||||
{ |
{ |
||||
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
||||
|
|
||||
var origanizationUnitRoleCount = await OrganizationUnitRepository |
var origanizationUnitRoleCount = await OrganizationUnitRepository |
||||
.GetUnaddedRolesCountAsync(origanizationUnit, input.Filter); |
.GetUnaddedRolesCountAsync(origanizationUnit, input.Filter); |
||||
|
|
||||
var origanizationUnitRoles = await OrganizationUnitRepository |
var origanizationUnitRoles = await OrganizationUnitRepository |
||||
.GetUnaddedRolesAsync(origanizationUnit, |
.GetUnaddedRolesAsync(origanizationUnit, |
||||
input.Sorting, input.MaxResultCount, |
input.Sorting, input.MaxResultCount, |
||||
input.SkipCount, input.Filter); |
input.SkipCount, input.Filter); |
||||
|
|
||||
return new PagedResultDto<IdentityRoleDto>(origanizationUnitRoleCount, |
return new PagedResultDto<IdentityRoleDto>(origanizationUnitRoleCount, |
||||
ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(origanizationUnitRoles)); |
ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(origanizationUnitRoles)); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.ManageRoles)] |
[Authorize(IdentityPermissions.OrganizationUnits.ManageRoles)] |
||||
public virtual async Task<PagedResultDto<IdentityRoleDto>> GetRolesAsync(Guid id, PagedAndSortedResultRequestDto input) |
public virtual async Task<PagedResultDto<IdentityRoleDto>> GetRolesAsync(Guid id, PagedAndSortedResultRequestDto input) |
||||
{ |
{ |
||||
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
||||
|
|
||||
var origanizationUnitRoleCount = await OrganizationUnitRepository |
var origanizationUnitRoleCount = await OrganizationUnitRepository |
||||
.GetRolesCountAsync(origanizationUnit); |
.GetRolesCountAsync(origanizationUnit); |
||||
|
|
||||
var origanizationUnitRoles = await OrganizationUnitRepository |
var origanizationUnitRoles = await OrganizationUnitRepository |
||||
.GetRolesAsync(origanizationUnit, |
.GetRolesAsync(origanizationUnit, |
||||
input.Sorting, input.MaxResultCount, |
input.Sorting, input.MaxResultCount, |
||||
input.SkipCount); |
input.SkipCount); |
||||
|
|
||||
return new PagedResultDto<IdentityRoleDto>(origanizationUnitRoleCount, |
return new PagedResultDto<IdentityRoleDto>(origanizationUnitRoleCount, |
||||
ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(origanizationUnitRoles)); |
ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(origanizationUnitRoles)); |
||||
} |
} |
||||
|
|
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.ManageUsers)] |
[Authorize(IdentityPermissions.OrganizationUnits.ManageUsers)] |
||||
public virtual async Task<PagedResultDto<IdentityUserDto>> GetUnaddedUsersAsync(Guid id, OrganizationUnitGetUnaddedUserByPagedDto input) |
public virtual async Task<PagedResultDto<IdentityUserDto>> GetUnaddedUsersAsync(Guid id, OrganizationUnitGetUnaddedUserByPagedDto input) |
||||
{ |
{ |
||||
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
||||
|
|
||||
var origanizationUnitUserCount = await OrganizationUnitRepository |
var origanizationUnitUserCount = await OrganizationUnitRepository |
||||
.GetUnaddedUsersCountAsync(origanizationUnit, input.Filter); |
.GetUnaddedUsersCountAsync(origanizationUnit, input.Filter); |
||||
var origanizationUnitUsers = await OrganizationUnitRepository |
var origanizationUnitUsers = await OrganizationUnitRepository |
||||
.GetUnaddedUsersAsync(origanizationUnit, |
.GetUnaddedUsersAsync(origanizationUnit, |
||||
input.Sorting, input.MaxResultCount, |
input.Sorting, input.MaxResultCount, |
||||
input.SkipCount, input.Filter); |
input.SkipCount, input.Filter); |
||||
|
|
||||
return new PagedResultDto<IdentityUserDto>(origanizationUnitUserCount, |
return new PagedResultDto<IdentityUserDto>(origanizationUnitUserCount, |
||||
ObjectMapper.Map<List<IdentityUser>, List<IdentityUserDto>>(origanizationUnitUsers)); |
ObjectMapper.Map<List<IdentityUser>, List<IdentityUserDto>>(origanizationUnitUsers)); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.ManageUsers)] |
[Authorize(IdentityPermissions.OrganizationUnits.ManageUsers)] |
||||
public virtual async Task<PagedResultDto<IdentityUserDto>> GetUsersAsync(Guid id, GetIdentityUsersInput input) |
public virtual async Task<PagedResultDto<IdentityUserDto>> GetUsersAsync(Guid id, GetIdentityUsersInput input) |
||||
{ |
{ |
||||
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
||||
|
|
||||
var origanizationUnitUserCount = await OrganizationUnitRepository |
var origanizationUnitUserCount = await OrganizationUnitRepository |
||||
.GetMembersCountAsync(origanizationUnit, input.Filter); |
.GetMembersCountAsync(origanizationUnit, input.Filter); |
||||
var origanizationUnitUsers = await OrganizationUnitRepository |
var origanizationUnitUsers = await OrganizationUnitRepository |
||||
.GetMembersAsync(origanizationUnit, |
.GetMembersAsync(origanizationUnit, |
||||
input.Sorting, input.MaxResultCount, |
input.Sorting, input.MaxResultCount, |
||||
input.SkipCount, input.Filter); |
input.SkipCount, input.Filter); |
||||
|
|
||||
return new PagedResultDto<IdentityUserDto>(origanizationUnitUserCount, |
return new PagedResultDto<IdentityUserDto>(origanizationUnitUserCount, |
||||
ObjectMapper.Map<List<IdentityUser>, List<IdentityUserDto>>(origanizationUnitUsers)); |
ObjectMapper.Map<List<IdentityUser>, List<IdentityUserDto>>(origanizationUnitUsers)); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.Update)] |
[Authorize(IdentityPermissions.OrganizationUnits.Update)] |
||||
public virtual async Task MoveAsync(Guid id, OrganizationUnitMoveDto input) |
public virtual async Task MoveAsync(Guid id, OrganizationUnitMoveDto input) |
||||
{ |
{ |
||||
await OrganizationUnitManager.MoveAsync(id, input.ParentId); |
await OrganizationUnitManager.MoveAsync(id, input.ParentId); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.Update)] |
[Authorize(IdentityPermissions.OrganizationUnits.Update)] |
||||
public virtual async Task<OrganizationUnitDto> UpdateAsync(Guid id, OrganizationUnitUpdateDto input) |
public virtual async Task<OrganizationUnitDto> UpdateAsync(Guid id, OrganizationUnitUpdateDto input) |
||||
{ |
{ |
||||
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
||||
origanizationUnit.DisplayName = input.DisplayName; |
origanizationUnit.DisplayName = input.DisplayName; |
||||
input.MapExtraPropertiesTo(origanizationUnit); |
input.MapExtraPropertiesTo(origanizationUnit); |
||||
|
|
||||
await OrganizationUnitManager.UpdateAsync(origanizationUnit); |
await OrganizationUnitManager.UpdateAsync(origanizationUnit); |
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
return ObjectMapper.Map<OrganizationUnit, OrganizationUnitDto>(origanizationUnit); |
return ObjectMapper.Map<OrganizationUnit, OrganizationUnitDto>(origanizationUnit); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.ManageUsers)] |
[Authorize(IdentityPermissions.OrganizationUnits.ManageUsers)] |
||||
public virtual async Task AddUsersAsync(Guid id, OrganizationUnitAddUserDto input) |
public virtual async Task AddUsersAsync(Guid id, OrganizationUnitAddUserDto input) |
||||
{ |
{ |
||||
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
||||
var users = await UserRepository.GetListByIdListAsync(input.UserIds, includeDetails: true); |
var users = await UserRepository.GetListByIdListAsync(input.UserIds, includeDetails: true); |
||||
|
|
||||
// 调用内部方法设置用户组织机构
|
// 调用内部方法设置用户组织机构
|
||||
foreach (var user in users) |
foreach (var user in users) |
||||
{ |
{ |
||||
await UserManager.AddToOrganizationUnitAsync(user, origanizationUnit); |
await UserManager.AddToOrganizationUnitAsync(user, origanizationUnit); |
||||
} |
} |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
} |
} |
||||
|
|
||||
[Authorize(IdentityPermissions.OrganizationUnits.ManageRoles)] |
[Authorize(IdentityPermissions.OrganizationUnits.ManageRoles)] |
||||
public virtual async Task AddRolesAsync(Guid id, OrganizationUnitAddRoleDto input) |
public virtual async Task AddRolesAsync(Guid id, OrganizationUnitAddRoleDto input) |
||||
{ |
{ |
||||
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
var origanizationUnit = await OrganizationUnitRepository.GetAsync(id); |
||||
|
|
||||
var roles = await RoleRepository.GetListByIdListAsync(input.RoleIds, includeDetails: true); |
var roles = await RoleRepository.GetListByIdListAsync(input.RoleIds, includeDetails: true); |
||||
|
|
||||
foreach (var role in roles) |
foreach (var role in roles) |
||||
{ |
{ |
||||
await OrganizationUnitManager.AddRoleToOrganizationUnitAsync(role, origanizationUnit); |
await OrganizationUnitManager.AddRoleToOrganizationUnitAsync(role, origanizationUnit); |
||||
} |
} |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,142 +1,142 @@ |
|||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
using System; |
using System; |
||||
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; |
using Volo.Abp; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
using Volo.Abp.IdentityServer.ApiScopes; |
using Volo.Abp.IdentityServer.ApiScopes; |
||||
|
|
||||
namespace LINGYUN.Abp.IdentityServer.ApiScopes |
namespace LINGYUN.Abp.IdentityServer.ApiScopes |
||||
{ |
{ |
||||
[Authorize(AbpIdentityServerPermissions.ApiScopes.Default)] |
[Authorize(AbpIdentityServerPermissions.ApiScopes.Default)] |
||||
public class ApiScopeAppService : AbpIdentityServerAppServiceBase, IApiScopeAppService |
public class ApiScopeAppService : AbpIdentityServerAppServiceBase, IApiScopeAppService |
||||
{ |
{ |
||||
protected IApiScopeRepository ApiScopeRepository { get; } |
protected IApiScopeRepository ApiScopeRepository { get; } |
||||
|
|
||||
public ApiScopeAppService( |
public ApiScopeAppService( |
||||
IApiScopeRepository apiScopeRepository) |
IApiScopeRepository apiScopeRepository) |
||||
{ |
{ |
||||
ApiScopeRepository = apiScopeRepository; |
ApiScopeRepository = apiScopeRepository; |
||||
} |
} |
||||
|
|
||||
[Authorize(AbpIdentityServerPermissions.ApiScopes.Create)] |
[Authorize(AbpIdentityServerPermissions.ApiScopes.Create)] |
||||
public virtual async Task<ApiScopeDto> CreateAsync(ApiScopeCreateDto input) |
public virtual async Task<ApiScopeDto> CreateAsync(ApiScopeCreateDto input) |
||||
{ |
{ |
||||
if (await ApiScopeRepository.CheckNameExistAsync(input.Name)) |
if (await ApiScopeRepository.CheckNameExistAsync(input.Name)) |
||||
{ |
{ |
||||
throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.ApiScopeNameExisted, input.Name]); |
throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.ApiScopeNameExisted, input.Name]); |
||||
} |
} |
||||
var apiScope = new ApiScope( |
var apiScope = new ApiScope( |
||||
GuidGenerator.Create(), |
GuidGenerator.Create(), |
||||
input.Name, |
input.Name, |
||||
input.DisplayName, |
input.DisplayName, |
||||
input.Description, |
input.Description, |
||||
input.Enabled, |
input.Enabled, |
||||
input.Required, |
input.Required, |
||||
input.Emphasize, |
input.Emphasize, |
||||
input.ShowInDiscoveryDocument); |
input.ShowInDiscoveryDocument); |
||||
|
|
||||
await UpdateApiScopeByInputAsync(apiScope, input); |
await UpdateApiScopeByInputAsync(apiScope, input); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
apiScope = await ApiScopeRepository.InsertAsync(apiScope); |
apiScope = await ApiScopeRepository.InsertAsync(apiScope); |
||||
|
|
||||
return ObjectMapper.Map<ApiScope, ApiScopeDto>(apiScope); |
return ObjectMapper.Map<ApiScope, ApiScopeDto>(apiScope); |
||||
} |
} |
||||
|
|
||||
[Authorize(AbpIdentityServerPermissions.ApiScopes.Delete)] |
[Authorize(AbpIdentityServerPermissions.ApiScopes.Delete)] |
||||
public virtual async Task DeleteAsync(Guid id) |
public virtual async Task DeleteAsync(Guid id) |
||||
{ |
{ |
||||
var apiScope = await ApiScopeRepository.GetAsync(id); |
var apiScope = await ApiScopeRepository.GetAsync(id); |
||||
|
|
||||
await ApiScopeRepository.DeleteAsync(apiScope); |
await ApiScopeRepository.DeleteAsync(apiScope); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ApiScopeDto> GetAsync(Guid id) |
public virtual async Task<ApiScopeDto> GetAsync(Guid id) |
||||
{ |
{ |
||||
var apiScope = await ApiScopeRepository.GetAsync(id); |
var apiScope = await ApiScopeRepository.GetAsync(id); |
||||
|
|
||||
return ObjectMapper.Map<ApiScope, ApiScopeDto>(apiScope); |
return ObjectMapper.Map<ApiScope, ApiScopeDto>(apiScope); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<PagedResultDto<ApiScopeDto>> GetListAsync(GetApiScopeInput input) |
public virtual async Task<PagedResultDto<ApiScopeDto>> GetListAsync(GetApiScopeInput input) |
||||
{ |
{ |
||||
var totalCount = await ApiScopeRepository |
var totalCount = await ApiScopeRepository |
||||
.GetCountAsync(input.Filter); |
.GetCountAsync(input.Filter); |
||||
|
|
||||
var apiScopes = await ApiScopeRepository |
var apiScopes = await ApiScopeRepository |
||||
.GetListAsync( |
.GetListAsync( |
||||
input.Sorting, |
input.Sorting, |
||||
input.SkipCount, input.MaxResultCount, |
input.SkipCount, input.MaxResultCount, |
||||
input.Filter); |
input.Filter); |
||||
|
|
||||
return new PagedResultDto<ApiScopeDto>(totalCount, |
return new PagedResultDto<ApiScopeDto>(totalCount, |
||||
ObjectMapper.Map<List<ApiScope>, List<ApiScopeDto>>(apiScopes)); |
ObjectMapper.Map<List<ApiScope>, List<ApiScopeDto>>(apiScopes)); |
||||
} |
} |
||||
|
|
||||
[Authorize(AbpIdentityServerPermissions.ApiScopes.Update)] |
[Authorize(AbpIdentityServerPermissions.ApiScopes.Update)] |
||||
public virtual async Task<ApiScopeDto> UpdateAsync(Guid id, ApiScopeUpdateDto input) |
public virtual async Task<ApiScopeDto> UpdateAsync(Guid id, ApiScopeUpdateDto input) |
||||
{ |
{ |
||||
var apiScope = await ApiScopeRepository.GetAsync(id); |
var apiScope = await ApiScopeRepository.GetAsync(id); |
||||
|
|
||||
await UpdateApiScopeByInputAsync(apiScope, input); |
await UpdateApiScopeByInputAsync(apiScope, input); |
||||
apiScope = await ApiScopeRepository.UpdateAsync(apiScope); |
apiScope = await ApiScopeRepository.UpdateAsync(apiScope); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
return ObjectMapper.Map<ApiScope, ApiScopeDto>(apiScope); |
return ObjectMapper.Map<ApiScope, ApiScopeDto>(apiScope); |
||||
} |
} |
||||
|
|
||||
protected virtual async Task UpdateApiScopeByInputAsync(ApiScope apiScope, ApiScopeCreateOrUpdateDto input) |
protected virtual async Task UpdateApiScopeByInputAsync(ApiScope apiScope, ApiScopeCreateOrUpdateDto input) |
||||
{ |
{ |
||||
if (!string.Equals(apiScope.Description, input.Description, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(apiScope.Description, input.Description, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
apiScope.Description = input.Description; |
apiScope.Description = input.Description; |
||||
} |
} |
||||
if (!string.Equals(apiScope.DisplayName, input.DisplayName, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(apiScope.DisplayName, input.DisplayName, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
apiScope.DisplayName = input.DisplayName; |
apiScope.DisplayName = input.DisplayName; |
||||
} |
} |
||||
apiScope.Emphasize = input.Emphasize; |
apiScope.Emphasize = input.Emphasize; |
||||
apiScope.Enabled = input.Enabled; |
apiScope.Enabled = input.Enabled; |
||||
apiScope.Required = input.Required; |
apiScope.Required = input.Required; |
||||
apiScope.ShowInDiscoveryDocument = input.ShowInDiscoveryDocument; |
apiScope.ShowInDiscoveryDocument = input.ShowInDiscoveryDocument; |
||||
|
|
||||
if (await IsGrantAsync(AbpIdentityServerPermissions.ApiScopes.ManageClaims)) |
if (await IsGrantAsync(AbpIdentityServerPermissions.ApiScopes.ManageClaims)) |
||||
{ |
{ |
||||
// 删除不存在的UserClaim
|
// 删除不存在的UserClaim
|
||||
apiScope.UserClaims.RemoveAll(claim => !input.UserClaims.Any(inputClaim => claim.Type == inputClaim.Type)); |
apiScope.UserClaims.RemoveAll(claim => !input.UserClaims.Any(inputClaim => claim.Type == inputClaim.Type)); |
||||
foreach (var inputClaim in input.UserClaims) |
foreach (var inputClaim in input.UserClaims) |
||||
{ |
{ |
||||
var userClaim = apiScope.FindClaim(inputClaim.Type); |
var userClaim = apiScope.FindClaim(inputClaim.Type); |
||||
if (userClaim == null) |
if (userClaim == null) |
||||
{ |
{ |
||||
apiScope.AddUserClaim(inputClaim.Type); |
apiScope.AddUserClaim(inputClaim.Type); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
if (await IsGrantAsync(AbpIdentityServerPermissions.ApiScopes.ManageProperties)) |
if (await IsGrantAsync(AbpIdentityServerPermissions.ApiScopes.ManageProperties)) |
||||
{ |
{ |
||||
// 删除不存在的Property
|
// 删除不存在的Property
|
||||
apiScope.Properties.RemoveAll(prop => !input.Properties.Any(inputProp => prop.Key == inputProp.Key)); |
apiScope.Properties.RemoveAll(prop => !input.Properties.Any(inputProp => prop.Key == inputProp.Key)); |
||||
foreach (var inputProp in input.Properties) |
foreach (var inputProp in input.Properties) |
||||
{ |
{ |
||||
var identityResourceProperty = apiScope.FindProperty(inputProp.Key); |
var identityResourceProperty = apiScope.FindProperty(inputProp.Key); |
||||
if (identityResourceProperty == null) |
if (identityResourceProperty == null) |
||||
{ |
{ |
||||
apiScope.AddProperty(inputProp.Key, inputProp.Value); |
apiScope.AddProperty(inputProp.Key, inputProp.Value); |
||||
} |
} |
||||
else |
else |
||||
{ |
{ |
||||
identityResourceProperty.Value = inputProp.Value; |
identityResourceProperty.Value = inputProp.Value; |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,483 +1,483 @@ |
|||||
using LINGYUN.Abp.IdentityServer.ApiResources; |
using LINGYUN.Abp.IdentityServer.ApiResources; |
||||
using LINGYUN.Abp.IdentityServer.IdentityResources; |
using LINGYUN.Abp.IdentityServer.IdentityResources; |
||||
using IdentityServer4; |
using IdentityServer4; |
||||
using IdentityServer4.Models; |
using IdentityServer4.Models; |
||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
using System; |
using System; |
||||
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; |
using Volo.Abp; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
using Volo.Abp.IdentityServer.Clients; |
using Volo.Abp.IdentityServer.Clients; |
||||
using Client = Volo.Abp.IdentityServer.Clients.Client; |
using Client = Volo.Abp.IdentityServer.Clients.Client; |
||||
|
|
||||
namespace LINGYUN.Abp.IdentityServer.Clients |
namespace LINGYUN.Abp.IdentityServer.Clients |
||||
{ |
{ |
||||
[Authorize(AbpIdentityServerPermissions.Clients.Default)] |
[Authorize(AbpIdentityServerPermissions.Clients.Default)] |
||||
public class ClientAppService : AbpIdentityServerAppServiceBase, IClientAppService |
public class ClientAppService : AbpIdentityServerAppServiceBase, IClientAppService |
||||
{ |
{ |
||||
protected IClientRepository ClientRepository { get; } |
protected IClientRepository ClientRepository { get; } |
||||
protected IApiResourceRepository ApiResourceRepository { get; } |
protected IApiResourceRepository ApiResourceRepository { get; } |
||||
protected IIdentityResourceRepository IdentityResourceRepository { get; } |
protected IIdentityResourceRepository IdentityResourceRepository { get; } |
||||
|
|
||||
public ClientAppService( |
public ClientAppService( |
||||
IClientRepository clientRepository, |
IClientRepository clientRepository, |
||||
IApiResourceRepository apiResourceRepository, |
IApiResourceRepository apiResourceRepository, |
||||
IIdentityResourceRepository identityResourceRepository) |
IIdentityResourceRepository identityResourceRepository) |
||||
{ |
{ |
||||
ClientRepository = clientRepository; |
ClientRepository = clientRepository; |
||||
ApiResourceRepository = apiResourceRepository; |
ApiResourceRepository = apiResourceRepository; |
||||
IdentityResourceRepository = identityResourceRepository; |
IdentityResourceRepository = identityResourceRepository; |
||||
} |
} |
||||
|
|
||||
[Authorize(AbpIdentityServerPermissions.Clients.Create)] |
[Authorize(AbpIdentityServerPermissions.Clients.Create)] |
||||
public virtual async Task<ClientDto> CreateAsync(ClientCreateDto clientCreate) |
public virtual async Task<ClientDto> CreateAsync(ClientCreateDto clientCreate) |
||||
{ |
{ |
||||
var clientIdExists = await ClientRepository.CheckClientIdExistAsync(clientCreate.ClientId); |
var clientIdExists = await ClientRepository.CheckClientIdExistAsync(clientCreate.ClientId); |
||||
if(clientIdExists) |
if(clientIdExists) |
||||
{ |
{ |
||||
throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.ClientIdExisted, clientCreate.ClientId]); |
throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.ClientIdExisted, clientCreate.ClientId]); |
||||
} |
} |
||||
var client = new Client(GuidGenerator.Create(), clientCreate.ClientId) |
var client = new Client(GuidGenerator.Create(), clientCreate.ClientId) |
||||
{ |
{ |
||||
ClientName = clientCreate.ClientName, |
ClientName = clientCreate.ClientName, |
||||
Description = clientCreate.Description |
Description = clientCreate.Description |
||||
}; |
}; |
||||
foreach (var inputGrantType in clientCreate.AllowedGrantTypes) |
foreach (var inputGrantType in clientCreate.AllowedGrantTypes) |
||||
{ |
{ |
||||
client.AddGrantType(inputGrantType.GrantType); |
client.AddGrantType(inputGrantType.GrantType); |
||||
} |
} |
||||
|
|
||||
client = await ClientRepository.InsertAsync(client); |
client = await ClientRepository.InsertAsync(client); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
return ObjectMapper.Map<Client, ClientDto>(client); |
return ObjectMapper.Map<Client, ClientDto>(client); |
||||
} |
} |
||||
|
|
||||
[Authorize(AbpIdentityServerPermissions.Clients.Delete)] |
[Authorize(AbpIdentityServerPermissions.Clients.Delete)] |
||||
public virtual async Task DeleteAsync(Guid id) |
public virtual async Task DeleteAsync(Guid id) |
||||
{ |
{ |
||||
var client = await ClientRepository.GetAsync(id); |
var client = await ClientRepository.GetAsync(id); |
||||
await ClientRepository.DeleteAsync(client); |
await ClientRepository.DeleteAsync(client); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ClientDto> GetAsync(Guid id) |
public virtual async Task<ClientDto> GetAsync(Guid id) |
||||
{ |
{ |
||||
var client = await ClientRepository.GetAsync(id); |
var client = await ClientRepository.GetAsync(id); |
||||
|
|
||||
return ObjectMapper.Map<Client, ClientDto>(client); |
return ObjectMapper.Map<Client, ClientDto>(client); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<PagedResultDto<ClientDto>> GetListAsync(ClientGetByPagedDto input) |
public virtual async Task<PagedResultDto<ClientDto>> GetListAsync(ClientGetByPagedDto input) |
||||
{ |
{ |
||||
var clients = await ClientRepository.GetListAsync(input.Sorting, |
var clients = await ClientRepository.GetListAsync(input.Sorting, |
||||
input.SkipCount, input.MaxResultCount, |
input.SkipCount, input.MaxResultCount, |
||||
input.Filter); |
input.Filter); |
||||
|
|
||||
var clientCount = await ClientRepository.GetCountAsync(); |
var clientCount = await ClientRepository.GetCountAsync(); |
||||
|
|
||||
return new PagedResultDto<ClientDto>(clientCount, |
return new PagedResultDto<ClientDto>(clientCount, |
||||
ObjectMapper.Map<List<Client>, List<ClientDto>>(clients)); |
ObjectMapper.Map<List<Client>, List<ClientDto>>(clients)); |
||||
} |
} |
||||
|
|
||||
[Authorize(AbpIdentityServerPermissions.Clients.Update)] |
[Authorize(AbpIdentityServerPermissions.Clients.Update)] |
||||
public virtual async Task<ClientDto> UpdateAsync(Guid id, ClientUpdateDto input) |
public virtual async Task<ClientDto> UpdateAsync(Guid id, ClientUpdateDto input) |
||||
{ |
{ |
||||
var client = await ClientRepository.GetAsync(id); |
var client = await ClientRepository.GetAsync(id); |
||||
|
|
||||
#region Basic
|
#region Basic
|
||||
if (!string.Equals(client.ClientId, input.ClientId, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.ClientId, input.ClientId, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.ClientId = input.ClientId; |
client.ClientId = input.ClientId; |
||||
} |
} |
||||
if (!string.Equals(client.ClientUri, input.ClientUri, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.ClientUri, input.ClientUri, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.ClientUri = input.ClientUri; |
client.ClientUri = input.ClientUri; |
||||
} |
} |
||||
if (!string.Equals(client.ClientName, input.ClientName, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.ClientName, input.ClientName, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.ClientName = input.ClientName; |
client.ClientName = input.ClientName; |
||||
} |
} |
||||
if (!string.Equals(client.BackChannelLogoutUri, input.BackChannelLogoutUri, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.BackChannelLogoutUri, input.BackChannelLogoutUri, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.BackChannelLogoutUri = input.BackChannelLogoutUri; |
client.BackChannelLogoutUri = input.BackChannelLogoutUri; |
||||
} |
} |
||||
if (!string.Equals(client.FrontChannelLogoutUri, input.FrontChannelLogoutUri, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.FrontChannelLogoutUri, input.FrontChannelLogoutUri, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.FrontChannelLogoutUri = input.FrontChannelLogoutUri; |
client.FrontChannelLogoutUri = input.FrontChannelLogoutUri; |
||||
} |
} |
||||
if (!string.Equals(client.ClientClaimsPrefix, input.ClientClaimsPrefix, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.ClientClaimsPrefix, input.ClientClaimsPrefix, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.ClientClaimsPrefix = input.ClientClaimsPrefix; |
client.ClientClaimsPrefix = input.ClientClaimsPrefix; |
||||
} |
} |
||||
if (!string.Equals(client.Description, input.Description, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.Description, input.Description, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.Description = input.Description; |
client.Description = input.Description; |
||||
} |
} |
||||
if (!string.Equals(client.LogoUri, input.LogoUri, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.LogoUri, input.LogoUri, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.LogoUri = input.LogoUri; |
client.LogoUri = input.LogoUri; |
||||
} |
} |
||||
if (!string.Equals(client.UserCodeType, input.UserCodeType, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.UserCodeType, input.UserCodeType, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.UserCodeType = input.UserCodeType; |
client.UserCodeType = input.UserCodeType; |
||||
} |
} |
||||
if (!string.Equals(client.PairWiseSubjectSalt, input.PairWiseSubjectSalt, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.PairWiseSubjectSalt, input.PairWiseSubjectSalt, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.PairWiseSubjectSalt = input.PairWiseSubjectSalt; |
client.PairWiseSubjectSalt = input.PairWiseSubjectSalt; |
||||
} |
} |
||||
if (!string.Equals(client.ProtocolType, input.ProtocolType, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.ProtocolType, input.ProtocolType, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.ProtocolType = input.ProtocolType; |
client.ProtocolType = input.ProtocolType; |
||||
} |
} |
||||
if (!string.Equals(client.AllowedIdentityTokenSigningAlgorithms, input.AllowedIdentityTokenSigningAlgorithms, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(client.AllowedIdentityTokenSigningAlgorithms, input.AllowedIdentityTokenSigningAlgorithms, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
client.AllowedIdentityTokenSigningAlgorithms = input.AllowedIdentityTokenSigningAlgorithms; |
client.AllowedIdentityTokenSigningAlgorithms = input.AllowedIdentityTokenSigningAlgorithms; |
||||
} |
} |
||||
|
|
||||
client.AbsoluteRefreshTokenLifetime = input.AbsoluteRefreshTokenLifetime; |
client.AbsoluteRefreshTokenLifetime = input.AbsoluteRefreshTokenLifetime; |
||||
client.AccessTokenLifetime = input.AccessTokenLifetime; |
client.AccessTokenLifetime = input.AccessTokenLifetime; |
||||
client.AccessTokenType = input.AccessTokenType; |
client.AccessTokenType = input.AccessTokenType; |
||||
client.AllowAccessTokensViaBrowser = input.AllowAccessTokensViaBrowser; |
client.AllowAccessTokensViaBrowser = input.AllowAccessTokensViaBrowser; |
||||
client.AllowOfflineAccess = input.AllowOfflineAccess; |
client.AllowOfflineAccess = input.AllowOfflineAccess; |
||||
client.AllowPlainTextPkce = input.AllowPlainTextPkce; |
client.AllowPlainTextPkce = input.AllowPlainTextPkce; |
||||
client.AllowRememberConsent = input.AllowRememberConsent; |
client.AllowRememberConsent = input.AllowRememberConsent; |
||||
client.AlwaysIncludeUserClaimsInIdToken = input.AlwaysIncludeUserClaimsInIdToken; |
client.AlwaysIncludeUserClaimsInIdToken = input.AlwaysIncludeUserClaimsInIdToken; |
||||
client.AlwaysSendClientClaims = input.AlwaysSendClientClaims; |
client.AlwaysSendClientClaims = input.AlwaysSendClientClaims; |
||||
client.AuthorizationCodeLifetime = input.AuthorizationCodeLifetime; |
client.AuthorizationCodeLifetime = input.AuthorizationCodeLifetime; |
||||
client.BackChannelLogoutSessionRequired = input.BackChannelLogoutSessionRequired; |
client.BackChannelLogoutSessionRequired = input.BackChannelLogoutSessionRequired; |
||||
client.DeviceCodeLifetime = input.DeviceCodeLifetime; |
client.DeviceCodeLifetime = input.DeviceCodeLifetime; |
||||
client.ConsentLifetime = input.ConsentLifetime ?? client.ConsentLifetime; |
client.ConsentLifetime = input.ConsentLifetime ?? client.ConsentLifetime; |
||||
client.Enabled = input.Enabled; |
client.Enabled = input.Enabled; |
||||
client.RequireRequestObject = input.RequireRequestObject; |
client.RequireRequestObject = input.RequireRequestObject; |
||||
client.EnableLocalLogin = input.EnableLocalLogin; |
client.EnableLocalLogin = input.EnableLocalLogin; |
||||
client.FrontChannelLogoutSessionRequired = input.FrontChannelLogoutSessionRequired; |
client.FrontChannelLogoutSessionRequired = input.FrontChannelLogoutSessionRequired; |
||||
client.IdentityTokenLifetime = input.IdentityTokenLifetime; |
client.IdentityTokenLifetime = input.IdentityTokenLifetime; |
||||
client.IncludeJwtId = input.IncludeJwtId; |
client.IncludeJwtId = input.IncludeJwtId; |
||||
client.RefreshTokenExpiration = input.RefreshTokenExpiration; |
client.RefreshTokenExpiration = input.RefreshTokenExpiration; |
||||
client.RefreshTokenUsage = input.RefreshTokenUsage; |
client.RefreshTokenUsage = input.RefreshTokenUsage; |
||||
client.RequireClientSecret = input.RequireClientSecret; |
client.RequireClientSecret = input.RequireClientSecret; |
||||
client.RequireConsent = input.RequireConsent; |
client.RequireConsent = input.RequireConsent; |
||||
client.RequirePkce = input.RequirePkce; |
client.RequirePkce = input.RequirePkce; |
||||
client.SlidingRefreshTokenLifetime = input.SlidingRefreshTokenLifetime; |
client.SlidingRefreshTokenLifetime = input.SlidingRefreshTokenLifetime; |
||||
client.UpdateAccessTokenClaimsOnRefresh = input.UpdateAccessTokenClaimsOnRefresh; |
client.UpdateAccessTokenClaimsOnRefresh = input.UpdateAccessTokenClaimsOnRefresh; |
||||
client.UserSsoLifetime = input.UserSsoLifetime ?? client.UserSsoLifetime; |
client.UserSsoLifetime = input.UserSsoLifetime ?? client.UserSsoLifetime; |
||||
#endregion
|
#endregion
|
||||
|
|
||||
#region AllowScope
|
#region AllowScope
|
||||
// 删除未在身份资源和Api资源中的作用域
|
// 删除未在身份资源和Api资源中的作用域
|
||||
client.AllowedScopes.RemoveAll(scope => !input.AllowedScopes.Any(inputScope => scope.Scope == inputScope.Scope)); |
client.AllowedScopes.RemoveAll(scope => !input.AllowedScopes.Any(inputScope => scope.Scope == inputScope.Scope)); |
||||
foreach (var inputScope in input.AllowedScopes) |
foreach (var inputScope in input.AllowedScopes) |
||||
{ |
{ |
||||
if (client.FindScope(inputScope.Scope) == null) |
if (client.FindScope(inputScope.Scope) == null) |
||||
{ |
{ |
||||
client.AddScope(inputScope.Scope); |
client.AddScope(inputScope.Scope); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
#region RedirectUris
|
#region RedirectUris
|
||||
// 删除不存在的uri
|
// 删除不存在的uri
|
||||
client.RedirectUris.RemoveAll(uri => !input.RedirectUris.Any(inputRedirectUri => uri.RedirectUri == inputRedirectUri.RedirectUri)); |
client.RedirectUris.RemoveAll(uri => !input.RedirectUris.Any(inputRedirectUri => uri.RedirectUri == inputRedirectUri.RedirectUri)); |
||||
foreach (var inputRedirectUri in input.RedirectUris) |
foreach (var inputRedirectUri in input.RedirectUris) |
||||
{ |
{ |
||||
if (client.FindRedirectUri(inputRedirectUri.RedirectUri) == null) |
if (client.FindRedirectUri(inputRedirectUri.RedirectUri) == null) |
||||
{ |
{ |
||||
client.AddRedirectUri(inputRedirectUri.RedirectUri); |
client.AddRedirectUri(inputRedirectUri.RedirectUri); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
#region AllowedGrantTypes
|
#region AllowedGrantTypes
|
||||
// 删除不存在的验证类型
|
// 删除不存在的验证类型
|
||||
client.AllowedGrantTypes.RemoveAll(grantType => !input.AllowedGrantTypes.Any(inputGrantType => grantType.GrantType == inputGrantType.GrantType)); |
client.AllowedGrantTypes.RemoveAll(grantType => !input.AllowedGrantTypes.Any(inputGrantType => grantType.GrantType == inputGrantType.GrantType)); |
||||
foreach (var inputGrantType in input.AllowedGrantTypes) |
foreach (var inputGrantType in input.AllowedGrantTypes) |
||||
{ |
{ |
||||
if (client.FindGrantType(inputGrantType.GrantType) == null) |
if (client.FindGrantType(inputGrantType.GrantType) == null) |
||||
{ |
{ |
||||
client.AddGrantType(inputGrantType.GrantType); |
client.AddGrantType(inputGrantType.GrantType); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
#region AllowedCorsOrigins
|
#region AllowedCorsOrigins
|
||||
// 删除不存在的同源域名
|
// 删除不存在的同源域名
|
||||
client.AllowedCorsOrigins.RemoveAll(corsOrigin => !input.AllowedCorsOrigins.Any(inputCorsOrigin => corsOrigin.Origin == inputCorsOrigin.Origin)); |
client.AllowedCorsOrigins.RemoveAll(corsOrigin => !input.AllowedCorsOrigins.Any(inputCorsOrigin => corsOrigin.Origin == inputCorsOrigin.Origin)); |
||||
foreach (var inputCorsOrigin in input.AllowedCorsOrigins) |
foreach (var inputCorsOrigin in input.AllowedCorsOrigins) |
||||
{ |
{ |
||||
if (client.FindCorsOrigin(inputCorsOrigin.Origin) == null) |
if (client.FindCorsOrigin(inputCorsOrigin.Origin) == null) |
||||
{ |
{ |
||||
client.AddCorsOrigin(inputCorsOrigin.Origin); |
client.AddCorsOrigin(inputCorsOrigin.Origin); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
#region PostLogoutRedirectUris
|
#region PostLogoutRedirectUris
|
||||
|
|
||||
// 删除不存在的登录重定向域名
|
// 删除不存在的登录重定向域名
|
||||
client.PostLogoutRedirectUris.RemoveAll(uri => |
client.PostLogoutRedirectUris.RemoveAll(uri => |
||||
!input.PostLogoutRedirectUris.Any(inputLogoutRedirectUri => uri.PostLogoutRedirectUri == inputLogoutRedirectUri.PostLogoutRedirectUri)); |
!input.PostLogoutRedirectUris.Any(inputLogoutRedirectUri => uri.PostLogoutRedirectUri == inputLogoutRedirectUri.PostLogoutRedirectUri)); |
||||
foreach (var inputLogoutRedirectUri in input.PostLogoutRedirectUris) |
foreach (var inputLogoutRedirectUri in input.PostLogoutRedirectUris) |
||||
{ |
{ |
||||
if (client.FindPostLogoutRedirectUri(inputLogoutRedirectUri.PostLogoutRedirectUri) == null) |
if (client.FindPostLogoutRedirectUri(inputLogoutRedirectUri.PostLogoutRedirectUri) == null) |
||||
{ |
{ |
||||
client.AddPostLogoutRedirectUri(inputLogoutRedirectUri.PostLogoutRedirectUri); |
client.AddPostLogoutRedirectUri(inputLogoutRedirectUri.PostLogoutRedirectUri); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
#region IdentityProviderRestrictions
|
#region IdentityProviderRestrictions
|
||||
|
|
||||
// 删除身份认证限制提供商
|
// 删除身份认证限制提供商
|
||||
client.IdentityProviderRestrictions.RemoveAll(provider => |
client.IdentityProviderRestrictions.RemoveAll(provider => |
||||
!input.IdentityProviderRestrictions.Any(inputProvider => provider.Provider == inputProvider.Provider)); |
!input.IdentityProviderRestrictions.Any(inputProvider => provider.Provider == inputProvider.Provider)); |
||||
foreach (var inputProvider in input.IdentityProviderRestrictions) |
foreach (var inputProvider in input.IdentityProviderRestrictions) |
||||
{ |
{ |
||||
if (client.FindIdentityProviderRestriction(inputProvider.Provider) == null) |
if (client.FindIdentityProviderRestriction(inputProvider.Provider) == null) |
||||
{ |
{ |
||||
client.AddIdentityProviderRestriction(inputProvider.Provider); |
client.AddIdentityProviderRestriction(inputProvider.Provider); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
#region Secrets
|
#region Secrets
|
||||
|
|
||||
if (await IsGrantAsync(AbpIdentityServerPermissions.Clients.ManageSecrets)) |
if (await IsGrantAsync(AbpIdentityServerPermissions.Clients.ManageSecrets)) |
||||
{ |
{ |
||||
// 移除已经不存在的客户端密钥
|
// 移除已经不存在的客户端密钥
|
||||
client.ClientSecrets.RemoveAll(secret => !input.ClientSecrets.Any(inputSecret => secret.Value == inputSecret.Value && secret.Type == inputSecret.Type)); |
client.ClientSecrets.RemoveAll(secret => !input.ClientSecrets.Any(inputSecret => secret.Value == inputSecret.Value && secret.Type == inputSecret.Type)); |
||||
foreach (var inputSecret in input.ClientSecrets) |
foreach (var inputSecret in input.ClientSecrets) |
||||
{ |
{ |
||||
// 先对加密过的进行过滤
|
// 先对加密过的进行过滤
|
||||
if (client.FindSecret(inputSecret.Value, inputSecret.Type) != null) |
if (client.FindSecret(inputSecret.Value, inputSecret.Type) != null) |
||||
{ |
{ |
||||
continue; |
continue; |
||||
} |
} |
||||
var inputSecretValue = inputSecret.Value.Sha256(); // TODO: 通过可选配置来加密
|
var inputSecretValue = inputSecret.Value.Sha256(); // TODO: 通过可选配置来加密
|
||||
|
|
||||
var clientSecret = client.FindSecret(inputSecretValue, inputSecret.Type); |
var clientSecret = client.FindSecret(inputSecretValue, inputSecret.Type); |
||||
if (clientSecret == null) |
if (clientSecret == null) |
||||
{ |
{ |
||||
client.AddSecret(inputSecretValue, inputSecret.Expiration, inputSecret.Type, inputSecret.Description); |
client.AddSecret(inputSecretValue, inputSecret.Expiration, inputSecret.Type, inputSecret.Description); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
#region Properties
|
#region Properties
|
||||
|
|
||||
if (await IsGrantAsync(AbpIdentityServerPermissions.Clients.ManageProperties)) |
if (await IsGrantAsync(AbpIdentityServerPermissions.Clients.ManageProperties)) |
||||
{ |
{ |
||||
// 移除不存在的属性
|
// 移除不存在的属性
|
||||
client.Properties.RemoveAll(prop => !input.Properties.Any(inputProp => prop.Key == inputProp.Key)); |
client.Properties.RemoveAll(prop => !input.Properties.Any(inputProp => prop.Key == inputProp.Key)); |
||||
foreach (var inputProp in input.Properties) |
foreach (var inputProp in input.Properties) |
||||
{ |
{ |
||||
if (client.FindProperty(inputProp.Key, inputProp.Value) == null) |
if (client.FindProperty(inputProp.Key, inputProp.Value) == null) |
||||
{ |
{ |
||||
client.AddProperty(inputProp.Key, inputProp.Value); |
client.AddProperty(inputProp.Key, inputProp.Value); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
#region Claims
|
#region Claims
|
||||
|
|
||||
if (await IsGrantAsync(AbpIdentityServerPermissions.Clients.ManageClaims)) |
if (await IsGrantAsync(AbpIdentityServerPermissions.Clients.ManageClaims)) |
||||
{ |
{ |
||||
// 移除已经不存在的客户端声明
|
// 移除已经不存在的客户端声明
|
||||
client.Claims.RemoveAll(secret => !input.Claims.Any(inputClaim => secret.Value == inputClaim.Value && secret.Type == inputClaim.Type)); |
client.Claims.RemoveAll(secret => !input.Claims.Any(inputClaim => secret.Value == inputClaim.Value && secret.Type == inputClaim.Type)); |
||||
foreach (var inputClaim in input.Claims) |
foreach (var inputClaim in input.Claims) |
||||
{ |
{ |
||||
if (client.FindClaim(inputClaim.Value, inputClaim.Type) == null) |
if (client.FindClaim(inputClaim.Value, inputClaim.Type) == null) |
||||
{ |
{ |
||||
client.AddClaim(inputClaim.Value, inputClaim.Type); |
client.AddClaim(inputClaim.Value, inputClaim.Type); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
client = await ClientRepository.UpdateAsync(client); |
client = await ClientRepository.UpdateAsync(client); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
return ObjectMapper.Map<Client, ClientDto>(client); |
return ObjectMapper.Map<Client, ClientDto>(client); |
||||
} |
} |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// 克隆客户端
|
/// 克隆客户端
|
||||
/// </summary>
|
/// </summary>
|
||||
/// <remarks>
|
/// <remarks>
|
||||
/// 实现参考 Skoruba.IdentityServer4.Admin 项目
|
/// 实现参考 Skoruba.IdentityServer4.Admin 项目
|
||||
/// https://github.com/skoruba/IdentityServer4.Admin.git
|
/// https://github.com/skoruba/IdentityServer4.Admin.git
|
||||
/// </remarks>
|
/// </remarks>
|
||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
/// <returns></returns>
|
||||
[Authorize(AbpIdentityServerPermissions.Clients.Clone)] |
[Authorize(AbpIdentityServerPermissions.Clients.Clone)] |
||||
public virtual async Task<ClientDto> CloneAsync(Guid id, ClientCloneDto input) |
public virtual async Task<ClientDto> CloneAsync(Guid id, ClientCloneDto input) |
||||
{ |
{ |
||||
var clientIdExists = await ClientRepository.CheckClientIdExistAsync(input.ClientId); |
var clientIdExists = await ClientRepository.CheckClientIdExistAsync(input.ClientId); |
||||
if (clientIdExists) |
if (clientIdExists) |
||||
{ |
{ |
||||
throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.ClientIdExisted, input.ClientId]); |
throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.ClientIdExisted, input.ClientId]); |
||||
} |
} |
||||
var srcClient = await ClientRepository.GetAsync(id); |
var srcClient = await ClientRepository.GetAsync(id); |
||||
|
|
||||
var client = new Client(GuidGenerator.Create(), input.ClientId) |
var client = new Client(GuidGenerator.Create(), input.ClientId) |
||||
{ |
{ |
||||
ClientName = input.ClientName, |
ClientName = input.ClientName, |
||||
Description = input.Description, |
Description = input.Description, |
||||
AbsoluteRefreshTokenLifetime = srcClient.AbsoluteRefreshTokenLifetime, |
AbsoluteRefreshTokenLifetime = srcClient.AbsoluteRefreshTokenLifetime, |
||||
AccessTokenLifetime = srcClient.AccessTokenLifetime, |
AccessTokenLifetime = srcClient.AccessTokenLifetime, |
||||
AccessTokenType = srcClient.AccessTokenType, |
AccessTokenType = srcClient.AccessTokenType, |
||||
AllowAccessTokensViaBrowser = srcClient.AllowAccessTokensViaBrowser, |
AllowAccessTokensViaBrowser = srcClient.AllowAccessTokensViaBrowser, |
||||
AllowOfflineAccess = srcClient.AllowOfflineAccess, |
AllowOfflineAccess = srcClient.AllowOfflineAccess, |
||||
AllowPlainTextPkce = srcClient.AllowPlainTextPkce, |
AllowPlainTextPkce = srcClient.AllowPlainTextPkce, |
||||
AllowRememberConsent = srcClient.AllowRememberConsent, |
AllowRememberConsent = srcClient.AllowRememberConsent, |
||||
AlwaysIncludeUserClaimsInIdToken = srcClient.AlwaysIncludeUserClaimsInIdToken, |
AlwaysIncludeUserClaimsInIdToken = srcClient.AlwaysIncludeUserClaimsInIdToken, |
||||
AlwaysSendClientClaims = srcClient.AlwaysSendClientClaims, |
AlwaysSendClientClaims = srcClient.AlwaysSendClientClaims, |
||||
AuthorizationCodeLifetime = srcClient.AuthorizationCodeLifetime, |
AuthorizationCodeLifetime = srcClient.AuthorizationCodeLifetime, |
||||
BackChannelLogoutSessionRequired = srcClient.BackChannelLogoutSessionRequired, |
BackChannelLogoutSessionRequired = srcClient.BackChannelLogoutSessionRequired, |
||||
|
|
||||
BackChannelLogoutUri = srcClient.BackChannelLogoutUri, |
BackChannelLogoutUri = srcClient.BackChannelLogoutUri, |
||||
ClientClaimsPrefix = srcClient.ClientClaimsPrefix, |
ClientClaimsPrefix = srcClient.ClientClaimsPrefix, |
||||
ConsentLifetime = srcClient.ConsentLifetime, |
ConsentLifetime = srcClient.ConsentLifetime, |
||||
DeviceCodeLifetime = srcClient.DeviceCodeLifetime, |
DeviceCodeLifetime = srcClient.DeviceCodeLifetime, |
||||
Enabled = srcClient.Enabled, |
Enabled = srcClient.Enabled, |
||||
EnableLocalLogin = srcClient.EnableLocalLogin, |
EnableLocalLogin = srcClient.EnableLocalLogin, |
||||
FrontChannelLogoutSessionRequired = srcClient.FrontChannelLogoutSessionRequired, |
FrontChannelLogoutSessionRequired = srcClient.FrontChannelLogoutSessionRequired, |
||||
FrontChannelLogoutUri = srcClient.FrontChannelLogoutUri, |
FrontChannelLogoutUri = srcClient.FrontChannelLogoutUri, |
||||
|
|
||||
IdentityTokenLifetime = srcClient.IdentityTokenLifetime, |
IdentityTokenLifetime = srcClient.IdentityTokenLifetime, |
||||
IncludeJwtId = srcClient.IncludeJwtId, |
IncludeJwtId = srcClient.IncludeJwtId, |
||||
LogoUri = srcClient.LogoUri, |
LogoUri = srcClient.LogoUri, |
||||
PairWiseSubjectSalt = srcClient.PairWiseSubjectSalt, |
PairWiseSubjectSalt = srcClient.PairWiseSubjectSalt, |
||||
ProtocolType = srcClient.ProtocolType, |
ProtocolType = srcClient.ProtocolType, |
||||
RefreshTokenExpiration = srcClient.RefreshTokenExpiration, |
RefreshTokenExpiration = srcClient.RefreshTokenExpiration, |
||||
RefreshTokenUsage = srcClient.RefreshTokenUsage, |
RefreshTokenUsage = srcClient.RefreshTokenUsage, |
||||
RequireClientSecret = srcClient.RequireClientSecret, |
RequireClientSecret = srcClient.RequireClientSecret, |
||||
RequireConsent = srcClient.RequireConsent, |
RequireConsent = srcClient.RequireConsent, |
||||
|
|
||||
RequirePkce = srcClient.RequirePkce, |
RequirePkce = srcClient.RequirePkce, |
||||
SlidingRefreshTokenLifetime = srcClient.SlidingRefreshTokenLifetime, |
SlidingRefreshTokenLifetime = srcClient.SlidingRefreshTokenLifetime, |
||||
UpdateAccessTokenClaimsOnRefresh = srcClient.UpdateAccessTokenClaimsOnRefresh, |
UpdateAccessTokenClaimsOnRefresh = srcClient.UpdateAccessTokenClaimsOnRefresh, |
||||
|
|
||||
UserCodeType = srcClient.UserCodeType, |
UserCodeType = srcClient.UserCodeType, |
||||
UserSsoLifetime = srcClient.UserSsoLifetime |
UserSsoLifetime = srcClient.UserSsoLifetime |
||||
}; |
}; |
||||
|
|
||||
if (input.CopyAllowedCorsOrigin) |
if (input.CopyAllowedCorsOrigin) |
||||
{ |
{ |
||||
foreach(var corsOrigin in srcClient.AllowedCorsOrigins) |
foreach(var corsOrigin in srcClient.AllowedCorsOrigins) |
||||
{ |
{ |
||||
client.AddCorsOrigin(corsOrigin.Origin); |
client.AddCorsOrigin(corsOrigin.Origin); |
||||
} |
} |
||||
} |
} |
||||
if (input.CopyAllowedGrantType) |
if (input.CopyAllowedGrantType) |
||||
{ |
{ |
||||
foreach (var grantType in srcClient.AllowedGrantTypes) |
foreach (var grantType in srcClient.AllowedGrantTypes) |
||||
{ |
{ |
||||
client.AddGrantType(grantType.GrantType); |
client.AddGrantType(grantType.GrantType); |
||||
} |
} |
||||
} |
} |
||||
if (input.CopyAllowedScope) |
if (input.CopyAllowedScope) |
||||
{ |
{ |
||||
foreach (var scope in srcClient.AllowedScopes) |
foreach (var scope in srcClient.AllowedScopes) |
||||
{ |
{ |
||||
client.AddScope(scope.Scope); |
client.AddScope(scope.Scope); |
||||
} |
} |
||||
} |
} |
||||
if (input.CopyClaim) |
if (input.CopyClaim) |
||||
{ |
{ |
||||
foreach (var claim in srcClient.Claims) |
foreach (var claim in srcClient.Claims) |
||||
{ |
{ |
||||
client.AddClaim(claim.Value, claim.Type); |
client.AddClaim(claim.Value, claim.Type); |
||||
} |
} |
||||
} |
} |
||||
if (input.CopySecret) |
if (input.CopySecret) |
||||
{ |
{ |
||||
foreach (var secret in srcClient.ClientSecrets) |
foreach (var secret in srcClient.ClientSecrets) |
||||
{ |
{ |
||||
client.AddSecret(secret.Value, secret.Expiration, secret.Type, secret.Description); |
client.AddSecret(secret.Value, secret.Expiration, secret.Type, secret.Description); |
||||
} |
} |
||||
} |
} |
||||
if (input.CopyIdentityProviderRestriction) |
if (input.CopyIdentityProviderRestriction) |
||||
{ |
{ |
||||
foreach (var provider in srcClient.IdentityProviderRestrictions) |
foreach (var provider in srcClient.IdentityProviderRestrictions) |
||||
{ |
{ |
||||
client.AddIdentityProviderRestriction(provider.Provider); |
client.AddIdentityProviderRestriction(provider.Provider); |
||||
} |
} |
||||
} |
} |
||||
if (input.CopyPostLogoutRedirectUri) |
if (input.CopyPostLogoutRedirectUri) |
||||
{ |
{ |
||||
foreach (var uri in srcClient.PostLogoutRedirectUris) |
foreach (var uri in srcClient.PostLogoutRedirectUris) |
||||
{ |
{ |
||||
client.AddPostLogoutRedirectUri(uri.PostLogoutRedirectUri); |
client.AddPostLogoutRedirectUri(uri.PostLogoutRedirectUri); |
||||
} |
} |
||||
} |
} |
||||
if (input.CopyPropertie) |
if (input.CopyPropertie) |
||||
{ |
{ |
||||
foreach (var property in srcClient.Properties) |
foreach (var property in srcClient.Properties) |
||||
{ |
{ |
||||
client.AddProperty(property.Key, property.Value); |
client.AddProperty(property.Key, property.Value); |
||||
} |
} |
||||
} |
} |
||||
if (input.CopyRedirectUri) |
if (input.CopyRedirectUri) |
||||
{ |
{ |
||||
foreach (var uri in srcClient.RedirectUris) |
foreach (var uri in srcClient.RedirectUris) |
||||
{ |
{ |
||||
client.AddRedirectUri(uri.RedirectUri); |
client.AddRedirectUri(uri.RedirectUri); |
||||
} |
} |
||||
} |
} |
||||
client = await ClientRepository.InsertAsync(client); |
client = await ClientRepository.InsertAsync(client); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
return ObjectMapper.Map<Client, ClientDto>(client); |
return ObjectMapper.Map<Client, ClientDto>(client); |
||||
} |
} |
||||
/// <summary>
|
/// <summary>
|
||||
/// 查询可用的Api资源
|
/// 查询可用的Api资源
|
||||
/// </summary>
|
/// </summary>
|
||||
/// <returns></returns>
|
/// <returns></returns>
|
||||
public virtual async Task<ListResultDto<string>> GetAssignableApiResourcesAsync() |
public virtual async Task<ListResultDto<string>> GetAssignableApiResourcesAsync() |
||||
{ |
{ |
||||
var resourceNames = await ApiResourceRepository.GetNamesAsync(); |
var resourceNames = await ApiResourceRepository.GetNamesAsync(); |
||||
|
|
||||
return new ListResultDto<string>(resourceNames); |
return new ListResultDto<string>(resourceNames); |
||||
} |
} |
||||
/// <summary>
|
/// <summary>
|
||||
/// 查询可用的身份资源
|
/// 查询可用的身份资源
|
||||
/// </summary>
|
/// </summary>
|
||||
/// <returns></returns>
|
/// <returns></returns>
|
||||
public virtual async Task<ListResultDto<string>> GetAssignableIdentityResourcesAsync() |
public virtual async Task<ListResultDto<string>> GetAssignableIdentityResourcesAsync() |
||||
{ |
{ |
||||
var resourceNames = await IdentityResourceRepository.GetNamesAsync(); |
var resourceNames = await IdentityResourceRepository.GetNamesAsync(); |
||||
|
|
||||
return new ListResultDto<string>(resourceNames); |
return new ListResultDto<string>(resourceNames); |
||||
} |
} |
||||
/// <summary>
|
/// <summary>
|
||||
/// 查询所有不重复的跨域地址
|
/// 查询所有不重复的跨域地址
|
||||
/// </summary>
|
/// </summary>
|
||||
/// <returns></returns>
|
/// <returns></returns>
|
||||
public virtual async Task<ListResultDto<string>> GetAllDistinctAllowedCorsOriginsAsync() |
public virtual async Task<ListResultDto<string>> GetAllDistinctAllowedCorsOriginsAsync() |
||||
{ |
{ |
||||
var corsOrigins = await ClientRepository.GetAllDistinctAllowedCorsOriginsAsync(); |
var corsOrigins = await ClientRepository.GetAllDistinctAllowedCorsOriginsAsync(); |
||||
|
|
||||
return new ListResultDto<string>(corsOrigins); |
return new ListResultDto<string>(corsOrigins); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,52 +1,52 @@ |
|||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
using System; |
using System; |
||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
using Volo.Abp.IdentityServer.Grants; |
using Volo.Abp.IdentityServer.Grants; |
||||
|
|
||||
namespace LINGYUN.Abp.IdentityServer.Grants |
namespace LINGYUN.Abp.IdentityServer.Grants |
||||
{ |
{ |
||||
[Authorize(AbpIdentityServerPermissions.Grants.Default)] |
[Authorize(AbpIdentityServerPermissions.Grants.Default)] |
||||
public class PersistedGrantAppService : AbpIdentityServerAppServiceBase, IPersistedGrantAppService |
public class PersistedGrantAppService : AbpIdentityServerAppServiceBase, IPersistedGrantAppService |
||||
{ |
{ |
||||
protected IPersistentGrantRepository PersistentGrantRepository { get; } |
protected IPersistentGrantRepository PersistentGrantRepository { get; } |
||||
|
|
||||
public PersistedGrantAppService( |
public PersistedGrantAppService( |
||||
IPersistentGrantRepository persistentGrantRepository) |
IPersistentGrantRepository persistentGrantRepository) |
||||
{ |
{ |
||||
PersistentGrantRepository = persistentGrantRepository; |
PersistentGrantRepository = persistentGrantRepository; |
||||
} |
} |
||||
|
|
||||
[Authorize(AbpIdentityServerPermissions.Grants.Delete)] |
[Authorize(AbpIdentityServerPermissions.Grants.Delete)] |
||||
public virtual async Task DeleteAsync(Guid id) |
public virtual async Task DeleteAsync(Guid id) |
||||
{ |
{ |
||||
var persistedGrant = await PersistentGrantRepository.GetAsync(id); |
var persistedGrant = await PersistentGrantRepository.GetAsync(id); |
||||
|
|
||||
await PersistentGrantRepository.DeleteAsync(persistedGrant); |
await PersistentGrantRepository.DeleteAsync(persistedGrant); |
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<PersistedGrantDto> GetAsync(Guid id) |
public virtual async Task<PersistedGrantDto> GetAsync(Guid id) |
||||
{ |
{ |
||||
var persistedGrant = await PersistentGrantRepository.GetAsync(id); |
var persistedGrant = await PersistentGrantRepository.GetAsync(id); |
||||
|
|
||||
return ObjectMapper.Map<PersistedGrant, PersistedGrantDto>(persistedGrant); |
return ObjectMapper.Map<PersistedGrant, PersistedGrantDto>(persistedGrant); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<PagedResultDto<PersistedGrantDto>> GetListAsync(GetPersistedGrantInput input) |
public virtual async Task<PagedResultDto<PersistedGrantDto>> GetListAsync(GetPersistedGrantInput input) |
||||
{ |
{ |
||||
var persistenGrantCount = await PersistentGrantRepository |
var persistenGrantCount = await PersistentGrantRepository |
||||
.GetCountAsync( |
.GetCountAsync( |
||||
input.SubjectId, input.Filter); |
input.SubjectId, input.Filter); |
||||
|
|
||||
var persistenGrants = await PersistentGrantRepository |
var persistenGrants = await PersistentGrantRepository |
||||
.GetListAsync( |
.GetListAsync( |
||||
input.SubjectId, input.Filter, input.Sorting, |
input.SubjectId, input.Filter, input.Sorting, |
||||
input.SkipCount, input.MaxResultCount); |
input.SkipCount, input.MaxResultCount); |
||||
|
|
||||
return new PagedResultDto<PersistedGrantDto>(persistenGrantCount, |
return new PagedResultDto<PersistedGrantDto>(persistenGrantCount, |
||||
ObjectMapper.Map<List<PersistedGrant>, List<PersistedGrantDto>>(persistenGrants)); |
ObjectMapper.Map<List<PersistedGrant>, List<PersistedGrantDto>>(persistenGrants)); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,131 +1,131 @@ |
|||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
using System; |
using System; |
||||
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; |
using Volo.Abp; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
using Volo.Abp.IdentityServer.IdentityResources; |
using Volo.Abp.IdentityServer.IdentityResources; |
||||
|
|
||||
namespace LINGYUN.Abp.IdentityServer.IdentityResources |
namespace LINGYUN.Abp.IdentityServer.IdentityResources |
||||
{ |
{ |
||||
[Authorize(AbpIdentityServerPermissions.IdentityResources.Default)] |
[Authorize(AbpIdentityServerPermissions.IdentityResources.Default)] |
||||
public class IdentityResourceAppService : AbpIdentityServerAppServiceBase, IIdentityResourceAppService |
public class IdentityResourceAppService : AbpIdentityServerAppServiceBase, IIdentityResourceAppService |
||||
{ |
{ |
||||
protected IIdentityResourceRepository IdentityResourceRepository { get; } |
protected IIdentityResourceRepository IdentityResourceRepository { get; } |
||||
|
|
||||
public IdentityResourceAppService( |
public IdentityResourceAppService( |
||||
IIdentityResourceRepository identityResourceRepository) |
IIdentityResourceRepository identityResourceRepository) |
||||
{ |
{ |
||||
IdentityResourceRepository = identityResourceRepository; |
IdentityResourceRepository = identityResourceRepository; |
||||
} |
} |
||||
|
|
||||
public virtual async Task<IdentityResourceDto> GetAsync(Guid id) |
public virtual async Task<IdentityResourceDto> GetAsync(Guid id) |
||||
{ |
{ |
||||
var identityResource = await IdentityResourceRepository.GetAsync(id); |
var identityResource = await IdentityResourceRepository.GetAsync(id); |
||||
|
|
||||
return ObjectMapper.Map<IdentityResource, IdentityResourceDto>(identityResource); |
return ObjectMapper.Map<IdentityResource, IdentityResourceDto>(identityResource); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<PagedResultDto<IdentityResourceDto>> GetListAsync(IdentityResourceGetByPagedDto input) |
public virtual async Task<PagedResultDto<IdentityResourceDto>> GetListAsync(IdentityResourceGetByPagedDto input) |
||||
{ |
{ |
||||
var identityResources = await IdentityResourceRepository.GetListAsync(input.Sorting, |
var identityResources = await IdentityResourceRepository.GetListAsync(input.Sorting, |
||||
input.SkipCount, input.MaxResultCount, |
input.SkipCount, input.MaxResultCount, |
||||
input.Filter); |
input.Filter); |
||||
var identityResourceCount = await IdentityResourceRepository.GetCountAsync(); |
var identityResourceCount = await IdentityResourceRepository.GetCountAsync(); |
||||
|
|
||||
return new PagedResultDto<IdentityResourceDto>(identityResourceCount, |
return new PagedResultDto<IdentityResourceDto>(identityResourceCount, |
||||
ObjectMapper.Map<List<IdentityResource>, List<IdentityResourceDto>>(identityResources)); |
ObjectMapper.Map<List<IdentityResource>, List<IdentityResourceDto>>(identityResources)); |
||||
} |
} |
||||
|
|
||||
[Authorize(AbpIdentityServerPermissions.IdentityResources.Create)] |
[Authorize(AbpIdentityServerPermissions.IdentityResources.Create)] |
||||
public virtual async Task<IdentityResourceDto> CreateAsync(IdentityResourceCreateOrUpdateDto input) |
public virtual async Task<IdentityResourceDto> CreateAsync(IdentityResourceCreateOrUpdateDto input) |
||||
{ |
{ |
||||
var identityResourceExists = await IdentityResourceRepository.CheckNameExistAsync(input.Name); |
var identityResourceExists = await IdentityResourceRepository.CheckNameExistAsync(input.Name); |
||||
if (identityResourceExists) |
if (identityResourceExists) |
||||
{ |
{ |
||||
throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.IdentityResourceNameExisted, input.Name]); |
throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.IdentityResourceNameExisted, input.Name]); |
||||
} |
} |
||||
var identityResource = new IdentityResource(GuidGenerator.Create(), input.Name, input.DisplayName, |
var identityResource = new IdentityResource(GuidGenerator.Create(), input.Name, input.DisplayName, |
||||
input.Description, input.Enabled, input.Required, input.Emphasize, |
input.Description, input.Enabled, input.Required, input.Emphasize, |
||||
input.ShowInDiscoveryDocument); |
input.ShowInDiscoveryDocument); |
||||
await UpdateApiResourceByInputAsync(identityResource, input); |
await UpdateApiResourceByInputAsync(identityResource, input); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
identityResource = await IdentityResourceRepository.InsertAsync(identityResource); |
identityResource = await IdentityResourceRepository.InsertAsync(identityResource); |
||||
|
|
||||
return ObjectMapper.Map<IdentityResource, IdentityResourceDto>(identityResource); |
return ObjectMapper.Map<IdentityResource, IdentityResourceDto>(identityResource); |
||||
} |
} |
||||
|
|
||||
[Authorize(AbpIdentityServerPermissions.IdentityResources.Update)] |
[Authorize(AbpIdentityServerPermissions.IdentityResources.Update)] |
||||
public virtual async Task<IdentityResourceDto> UpdateAsync(Guid id, IdentityResourceCreateOrUpdateDto input) |
public virtual async Task<IdentityResourceDto> UpdateAsync(Guid id, IdentityResourceCreateOrUpdateDto input) |
||||
{ |
{ |
||||
var identityResource = await IdentityResourceRepository.GetAsync(id); |
var identityResource = await IdentityResourceRepository.GetAsync(id); |
||||
await UpdateApiResourceByInputAsync(identityResource, input); |
await UpdateApiResourceByInputAsync(identityResource, input); |
||||
identityResource = await IdentityResourceRepository.UpdateAsync(identityResource); |
identityResource = await IdentityResourceRepository.UpdateAsync(identityResource); |
||||
|
|
||||
await CurrentUnitOfWork.SaveChangesAsync(); |
await CurrentUnitOfWork.CompleteAsync(); |
||||
|
|
||||
return ObjectMapper.Map<IdentityResource, IdentityResourceDto>(identityResource); |
return ObjectMapper.Map<IdentityResource, IdentityResourceDto>(identityResource); |
||||
} |
} |
||||
|
|
||||
[Authorize(AbpIdentityServerPermissions.IdentityResources.Delete)] |
[Authorize(AbpIdentityServerPermissions.IdentityResources.Delete)] |
||||
public virtual async Task DeleteAsync(Guid id) |
public virtual async Task DeleteAsync(Guid id) |
||||
{ |
{ |
||||
await IdentityResourceRepository.DeleteAsync(id); |
await IdentityResourceRepository.DeleteAsync(id); |
||||
} |
} |
||||
|
|
||||
protected virtual async Task UpdateApiResourceByInputAsync(IdentityResource identityResource, IdentityResourceCreateOrUpdateDto input) |
protected virtual async Task UpdateApiResourceByInputAsync(IdentityResource identityResource, IdentityResourceCreateOrUpdateDto input) |
||||
{ |
{ |
||||
if (!string.Equals(identityResource.Name, input.Name, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(identityResource.Name, input.Name, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
identityResource.Name = input.Name; |
identityResource.Name = input.Name; |
||||
} |
} |
||||
if (!string.Equals(identityResource.Description, input.Description, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(identityResource.Description, input.Description, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
identityResource.Description = input.Description; |
identityResource.Description = input.Description; |
||||
} |
} |
||||
if (!string.Equals(identityResource.DisplayName, input.DisplayName, StringComparison.InvariantCultureIgnoreCase)) |
if (!string.Equals(identityResource.DisplayName, input.DisplayName, StringComparison.InvariantCultureIgnoreCase)) |
||||
{ |
{ |
||||
identityResource.DisplayName = input.DisplayName; |
identityResource.DisplayName = input.DisplayName; |
||||
} |
} |
||||
identityResource.Emphasize = input.Emphasize; |
identityResource.Emphasize = input.Emphasize; |
||||
identityResource.Enabled = input.Enabled; |
identityResource.Enabled = input.Enabled; |
||||
identityResource.Required = input.Required; |
identityResource.Required = input.Required; |
||||
identityResource.ShowInDiscoveryDocument = input.ShowInDiscoveryDocument; |
identityResource.ShowInDiscoveryDocument = input.ShowInDiscoveryDocument; |
||||
|
|
||||
if (await IsGrantAsync(AbpIdentityServerPermissions.IdentityResources.ManageClaims)) |
if (await IsGrantAsync(AbpIdentityServerPermissions.IdentityResources.ManageClaims)) |
||||
{ |
{ |
||||
// 删除不存在的UserClaim
|
// 删除不存在的UserClaim
|
||||
identityResource.UserClaims.RemoveAll(claim => input.UserClaims.Any(inputClaim => claim.Type == inputClaim.Type)); |
identityResource.UserClaims.RemoveAll(claim => input.UserClaims.Any(inputClaim => claim.Type == inputClaim.Type)); |
||||
foreach (var inputClaim in input.UserClaims) |
foreach (var inputClaim in input.UserClaims) |
||||
{ |
{ |
||||
var userClaim = identityResource.FindUserClaim(inputClaim.Type); |
var userClaim = identityResource.FindUserClaim(inputClaim.Type); |
||||
if (userClaim == null) |
if (userClaim == null) |
||||
{ |
{ |
||||
identityResource.AddUserClaim(inputClaim.Type); |
identityResource.AddUserClaim(inputClaim.Type); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
if (await IsGrantAsync(AbpIdentityServerPermissions.IdentityResources.ManageProperties)) |
if (await IsGrantAsync(AbpIdentityServerPermissions.IdentityResources.ManageProperties)) |
||||
{ |
{ |
||||
// 删除不存在的Property
|
// 删除不存在的Property
|
||||
identityResource.Properties.RemoveAll(prop => !input.Properties.Any(inputProp => prop.Key == inputProp.Key)); |
identityResource.Properties.RemoveAll(prop => !input.Properties.Any(inputProp => prop.Key == inputProp.Key)); |
||||
foreach (var inputProp in input.Properties) |
foreach (var inputProp in input.Properties) |
||||
{ |
{ |
||||
var identityResourceProperty = identityResource.FindProperty(inputProp.Key); |
var identityResourceProperty = identityResource.FindProperty(inputProp.Key); |
||||
if (identityResourceProperty == null) |
if (identityResourceProperty == null) |
||||
{ |
{ |
||||
identityResource.AddProperty(inputProp.Key, inputProp.Value); |
identityResource.AddProperty(inputProp.Key, inputProp.Value); |
||||
} |
} |
||||
else |
else |
||||
{ |
{ |
||||
identityResourceProperty.Value = inputProp.Value; |
identityResourceProperty.Value = inputProp.Value; |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue