-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
312 additions
and
3 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/Contracts/Masa.Auth.Contracts.Admin/Infrastructure/Models/SoaOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Contracts.Admin.Infrastructure.Models; | ||
|
||
public class SoaOptions | ||
{ | ||
public string ServerUrl { get; set; } = ""; | ||
|
||
public readonly static string Key = "$public.Soa"; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Contracts/Masa.Auth.Contracts.Admin/Psso/AbpApiResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Contracts.Admin.Psso; | ||
|
||
public class AbpApiResponse<T> | ||
{ | ||
public bool Success { get; set; } | ||
|
||
public string? Error { get; set; } | ||
|
||
public T? Result { get; set; } | ||
} |
45 changes: 45 additions & 0 deletions
45
src/Contracts/Masa.Auth.Contracts.Admin/Psso/AssignedRoleDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Contracts.Admin.Psso; | ||
|
||
public class AssignedRoleDto | ||
{ | ||
public int? RoleId { set; get; } | ||
public PssoRoleType? RoleType { set; get; } | ||
public string RoleName { set; get; } = string.Empty; | ||
public string AssociatedEntityId { set; get; } = string.Empty; | ||
public string AssociatedEntityName { get; set; } = string.Empty; | ||
} | ||
|
||
public enum PssoRoleType : int | ||
{ | ||
/// <summary> | ||
/// 默认 | ||
/// </summary> | ||
Default = 0, | ||
/// <summary> | ||
/// 经销商 | ||
/// </summary> | ||
Distributor = 1, | ||
/// <summary> | ||
/// 经销公司 | ||
/// </summary> | ||
DistributionCompany = 2, | ||
///供应商 | ||
Supplier = 3, | ||
/// <summary> | ||
/// 服务中心 | ||
/// </summary> | ||
ServiceCenter = 8, | ||
///// <summary> | ||
///// 技工技师 | ||
///// </summary> | ||
//[Display(Name = "技工技师")] | ||
//Worker = 10, | ||
///// <summary> | ||
///// 临时技工技师 | ||
///// </summary> | ||
//[Display(Name = "临时技工技师")] | ||
//TempWorker = 11, | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Contracts/Masa.Auth.Contracts.Admin/Psso/FeatureTreeDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Contracts.Admin.Psso; | ||
|
||
public class FeatureTreeDto | ||
{ | ||
public string Id { set; get; } = string.Empty; | ||
public string Name { get; set; } = string.Empty; | ||
public string Code { get; set; } = string.Empty; | ||
public string Url { get; set; } = string.Empty; | ||
public FeatureType FeatureType { get; set; } | ||
public int OrderIndex { get; set; } | ||
public string Icon { get; set; } = string.Empty; | ||
public string NamePinyin { get; set; } = string.Empty; | ||
/// <summary> | ||
/// 是否折叠 | ||
/// </summary> | ||
public bool? IsCollapse { get; set; } | ||
/// <summary> | ||
/// 是否在演示中显示 | ||
/// </summary> | ||
public bool? IsShowYS { get; set; } | ||
public string ParentCode { set; get; } = string.Empty; | ||
public IEnumerable<FeatureTreeDto> Children { set; get; } = new List<FeatureTreeDto>(); | ||
} | ||
|
||
public enum FeatureType | ||
{ | ||
/// <summary> | ||
/// 隐藏 | ||
/// </summary> | ||
Display = 0, | ||
/// <summary> | ||
/// 应用 | ||
/// </summary> | ||
App = 1, | ||
/// <summary> | ||
/// 模块 | ||
/// </summary> | ||
Module = 2, | ||
/// <summary> | ||
/// 菜单 | ||
/// </summary> | ||
Menu = 3, | ||
/// <summary> | ||
/// 设置 | ||
/// </summary> | ||
Setting = 4, | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Contracts/Masa.Auth.Contracts.Admin/Psso/GetPermissionsByLonsidUserIdOutput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Contracts.Admin.Psso; | ||
|
||
public class GetPermissionsByLonsidUserIdOutput | ||
{ | ||
/// <summary> | ||
/// 用户id | ||
/// </summary> | ||
public Guid? LonsidUserId { set; get; } | ||
/// <summary> | ||
/// 授权权限集合 | ||
/// </summary> | ||
public List<string> Permission { set; get; } = new(); | ||
/// <summary> | ||
/// 用户角色 | ||
/// </summary> | ||
public List<AssignedRoleDto> AssignedRoles { get; set; } = new(); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Contracts/Masa.Auth.Contracts.Admin/Psso/GetUserFavoriteFeatureOutput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Contracts.Admin.Psso; | ||
|
||
public class GetUserFavoriteFeatureOutput | ||
{ | ||
public Guid Id { get; set; } | ||
public Guid LonsidUserId { get; set; } | ||
public long FeatureId { get; set; } | ||
public string FeatureCode { get; set; } = string.Empty; | ||
public string FeatureName { get; set; } = string.Empty; | ||
public string Url { get; set; } = string.Empty; | ||
public string Icon { get; set; } = string.Empty; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Contracts/Masa.Auth.Contracts.Admin/Psso/GetUserInfoOutput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Contracts.Admin.Psso; | ||
|
||
/// <summary> | ||
/// 获取用户信息 | ||
/// </summary> | ||
public class GetUserInfoOutput | ||
{ | ||
public Guid Id { get; set; } | ||
public Guid LonsidUserId { get; set; } | ||
/// <summary> | ||
/// 姓名 | ||
/// </summary> | ||
public string Name { set; get; } = string.Empty; | ||
/// <summary> | ||
/// 租户ID | ||
/// </summary> | ||
public int? TenantId { set; get; } | ||
/// <summary> | ||
/// 部门ID | ||
/// </summary> | ||
public Guid? UnitId { set; get; } | ||
/// <summary> | ||
/// 经销公司ID | ||
/// </summary> | ||
public string CompanyId { set; get; } = string.Empty; | ||
public string CompanyName { get; set; } = string.Empty; | ||
public string SupplierId { get; set; } = string.Empty; | ||
public string SupplierName { get; set; } = string.Empty; | ||
public string DistributorId { get; set; } = string.Empty; | ||
public string DistributorName { get; set; } = string.Empty; | ||
public string DomainName { set; get; } = string.Empty; | ||
public Guid? SystemUserId { get; set; } | ||
public Guid? RegionId { get; set; } | ||
public string RegionName { get; set; } = string.Empty; | ||
public string RegionOwner { get; set; } = string.Empty; | ||
public string ServiceCenterId { get; set; } = string.Empty; | ||
public string ServiceCenterName { get; set; } = string.Empty; | ||
public bool? IsPaymentYS { get; set; } | ||
public bool? IsExclusiveStore { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/Services/Masa.Auth.Service.Admin/Services/PssoService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
using Masa.Auth.Contracts.Admin.Psso; | ||
|
||
namespace Masa.Auth.Service.Admin.Services; | ||
|
||
public class PssoService : ServiceBase | ||
{ | ||
IHttpContextAccessor _httpContextAccessor => GetRequiredService<IHttpContextAccessor>(); | ||
IHttpClientFactory _httpClientFactory => GetRequiredService<IHttpClientFactory>(); | ||
IMasaConfiguration _masaConfiguration => GetRequiredService<IMasaConfiguration>(); | ||
|
||
public PssoService() : base("api/psso") | ||
{ | ||
RouteOptions.DisableAutoMapRoute = false; | ||
} | ||
|
||
private string? GetUserId() | ||
{ | ||
var user = _httpContextAccessor?.HttpContext?.User; | ||
var userId = user?.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier")?.Value; | ||
return userId; | ||
} | ||
|
||
private string? GetUserType() | ||
{ | ||
var user = _httpContextAccessor?.HttpContext?.User; | ||
var userId = user?.FindFirst("http://Lonsid.org/identity/claims/userType")?.Value; | ||
return userId; | ||
} | ||
|
||
private async Task<AbpApiResponse<TResult>> CheckConvertResult<TResult>(HttpResponseMessage response) | ||
{ | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
var errMsg = response.ReasonPhrase.IsNullOrEmpty() ? "Service call failed" : response.ReasonPhrase; | ||
throw new UserFriendlyException(errMsg); | ||
} | ||
|
||
var result = await response.Content.ReadAsStringAsync(); | ||
|
||
if ((int)response.StatusCode == 299) | ||
{ | ||
throw new UserFriendlyException(result); | ||
} | ||
var options = new JsonSerializerOptions | ||
{ | ||
PropertyNameCaseInsensitive = true, | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
ReferenceHandler = ReferenceHandler.Preserve | ||
}; | ||
|
||
return JsonSerializer.Deserialize<AbpApiResponse<TResult>>(result, options)!; | ||
} | ||
|
||
private HttpClient CreateClient() | ||
{ | ||
var soaOptions = _masaConfiguration.ConfigurationApi.GetPublic().GetSection(SoaOptions.Key).Get<SoaOptions>(); | ||
var client = _httpClientFactory.CreateClient(); | ||
client.BaseAddress = new Uri(soaOptions.ServerUrl); | ||
return client; | ||
} | ||
|
||
[AllowAnonymous] | ||
public async Task<GetUserInfoOutput> GetUserInfoAsync() | ||
{ | ||
var client = CreateClient(); | ||
var userId = GetUserId(); | ||
var userType = GetUserType(); | ||
var response = await client.GetAsync($"/api/pssom/lonsidUser/getUserInfo/{userId}?userType={userType}"); | ||
return (await CheckConvertResult<GetUserInfoOutput>(response)).Result!; | ||
} | ||
|
||
public async Task<GetPermissionsByLonsidUserIdOutput> GetPermissionsAsync() | ||
{ | ||
var client = CreateClient(); | ||
var userId = GetUserId(); | ||
var response = await client.GetAsync($"/api/pssom/lonsidUser/getPermissions/{userId}"); | ||
return (await CheckConvertResult<GetPermissionsByLonsidUserIdOutput>(response)).Result!; | ||
} | ||
|
||
public async Task<List<FeatureTreeDto>> GetFeatureTreesByUserAsync(string moduleName) | ||
{ | ||
var client = CreateClient(); | ||
var userId = GetUserId(); | ||
var response = await client.GetAsync($"/api/pssom/role/getFeatureTreesByUser/{userId}?moduleName={moduleName}"); | ||
return (await CheckConvertResult<List<FeatureTreeDto>>(response)).Result!; | ||
} | ||
|
||
public async Task<List<GetUserFavoriteFeatureOutput>> GetUserFavoriteFeatureAsync(string moduleName) | ||
{ | ||
var client = CreateClient(); | ||
var userId = GetUserId(); | ||
var response = await client.GetAsync($"/api/pssom/role/getUserFavoriteFeature/{userId}?moduleName={moduleName}"); | ||
return (await CheckConvertResult<List<GetUserFavoriteFeatureOutput>>(response)).Result!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters