Skip to content

Commit

Permalink
Merge pull request #48 from AlphaYu/dev
Browse files Browse the repository at this point in the history
v0.9.2.4
  • Loading branch information
AlphaYu authored Jun 23, 2022
2 parents c0478cd + e02f9ca commit 8dbfe22
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 51 deletions.
6 changes: 0 additions & 6 deletions src/ServerApi/Adnc.sln
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Shared.Application", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bulid", "Bulid", "{5F46F98A-6505-4767-82A7-95B0E12060AC}"
ProjectSection(SolutionItems) = preProject
build\00_g_ocelot_runner.bat = build\00_g_ocelot_runner.bat
build\01_usr_runner.bat = build\01_usr_runner.bat
build\02_maint_runner.bat = build\02_maint_runner.bat
build\03_cust_runner.bat = build\03_cust_runner.bat
build\04_ord_runner.bat = build\04_ord_runner.bat
build\05_whse_runner.bat = build\05_whse_runner.bat
build\common.props = build\common.props
build\version.props = build\version.props
EndProjectSection
Expand Down
97 changes: 97 additions & 0 deletions src/ServerApi/Infrastructures/Adnc.Infra.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32526.322
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Core", "Adnc.Infra.Core\Adnc.Infra.Core.csproj", "{6324C421-1F64-49DD-8750-8397ABB18C53}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Helper", "Adnc.Infra.Helper\Adnc.Infra.Helper.csproj", "{0B10CD96-6730-4891-9D1C-2A866515D599}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Caching", "Adnc.Infra.Caching\Adnc.Infra.Caching.csproj", "{FFAE8233-0F59-4500-BCA8-1F017C931CF0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Consul", "Adnc.Infra.Consul\Adnc.Infra.Consul.csproj", "{BC6481A6-09B5-4B15-86AF-87D192DE36D6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Repository", "Adnc.Infra.Repository\Adnc.Infra.Repository.csproj", "{A559E53C-51BA-495D-BAD9-82920D38DD47}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Mapper", "Adnc.Infra.Mapper\Adnc.Infra.Mapper.csproj", "{28342DDE-0AC6-4088-B4FF-9BBC3D7860DF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Repository.Dapper", "Adnc.Infra.Dapper\Adnc.Infra.Repository.Dapper.csproj", "{6CFA4455-51FA-43D1-ADB4-9C0011DEC647}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.EventBus", "Adnc.Infra.EventBus\Adnc.Infra.EventBus.csproj", "{D7942274-BF2B-4C63-B75C-262644983F35}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Repository.EfCore.MySql", "Adnc.Infra.EfCore.MySQL\Adnc.Infra.Repository.EfCore.MySql.csproj", "{5CBF2FCA-FCD4-4FCA-B99A-99F2AC792BB9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Repository.Mongo", "Adnc.Infra.Mongo\Adnc.Infra.Repository.Mongo.csproj", "{6893C528-01CB-4C4C-AFD6-8350749BEAE5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Repository.EfCore.SqlServer", "Adnc.Infra.EfCore.SQLServer\Adnc.Infra.Repository.EfCore.SqlServer.csproj", "{D880B5F5-B438-4AE7-9198-AEDB4A4CBD79}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.IdGenerater", "Adnc.Infra.IdGenerater\Adnc.Infra.IdGenerater.csproj", "{E5EDD471-192A-4812-97F9-A129BF0D5DE7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adnc.Infra.Repository.EfCore", "Adnc.Infra.EfCore\Adnc.Infra.Repository.EfCore.csproj", "{93CB8D34-DEC6-493A-9D5E-6951380EC21C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6324C421-1F64-49DD-8750-8397ABB18C53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6324C421-1F64-49DD-8750-8397ABB18C53}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6324C421-1F64-49DD-8750-8397ABB18C53}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6324C421-1F64-49DD-8750-8397ABB18C53}.Release|Any CPU.Build.0 = Release|Any CPU
{0B10CD96-6730-4891-9D1C-2A866515D599}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B10CD96-6730-4891-9D1C-2A866515D599}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B10CD96-6730-4891-9D1C-2A866515D599}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B10CD96-6730-4891-9D1C-2A866515D599}.Release|Any CPU.Build.0 = Release|Any CPU
{FFAE8233-0F59-4500-BCA8-1F017C931CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FFAE8233-0F59-4500-BCA8-1F017C931CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFAE8233-0F59-4500-BCA8-1F017C931CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FFAE8233-0F59-4500-BCA8-1F017C931CF0}.Release|Any CPU.Build.0 = Release|Any CPU
{BC6481A6-09B5-4B15-86AF-87D192DE36D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC6481A6-09B5-4B15-86AF-87D192DE36D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC6481A6-09B5-4B15-86AF-87D192DE36D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC6481A6-09B5-4B15-86AF-87D192DE36D6}.Release|Any CPU.Build.0 = Release|Any CPU
{A559E53C-51BA-495D-BAD9-82920D38DD47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A559E53C-51BA-495D-BAD9-82920D38DD47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A559E53C-51BA-495D-BAD9-82920D38DD47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A559E53C-51BA-495D-BAD9-82920D38DD47}.Release|Any CPU.Build.0 = Release|Any CPU
{28342DDE-0AC6-4088-B4FF-9BBC3D7860DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28342DDE-0AC6-4088-B4FF-9BBC3D7860DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28342DDE-0AC6-4088-B4FF-9BBC3D7860DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28342DDE-0AC6-4088-B4FF-9BBC3D7860DF}.Release|Any CPU.Build.0 = Release|Any CPU
{6CFA4455-51FA-43D1-ADB4-9C0011DEC647}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CFA4455-51FA-43D1-ADB4-9C0011DEC647}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CFA4455-51FA-43D1-ADB4-9C0011DEC647}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CFA4455-51FA-43D1-ADB4-9C0011DEC647}.Release|Any CPU.Build.0 = Release|Any CPU
{D7942274-BF2B-4C63-B75C-262644983F35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7942274-BF2B-4C63-B75C-262644983F35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7942274-BF2B-4C63-B75C-262644983F35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7942274-BF2B-4C63-B75C-262644983F35}.Release|Any CPU.Build.0 = Release|Any CPU
{5CBF2FCA-FCD4-4FCA-B99A-99F2AC792BB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5CBF2FCA-FCD4-4FCA-B99A-99F2AC792BB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5CBF2FCA-FCD4-4FCA-B99A-99F2AC792BB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5CBF2FCA-FCD4-4FCA-B99A-99F2AC792BB9}.Release|Any CPU.Build.0 = Release|Any CPU
{6893C528-01CB-4C4C-AFD6-8350749BEAE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6893C528-01CB-4C4C-AFD6-8350749BEAE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6893C528-01CB-4C4C-AFD6-8350749BEAE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6893C528-01CB-4C4C-AFD6-8350749BEAE5}.Release|Any CPU.Build.0 = Release|Any CPU
{D880B5F5-B438-4AE7-9198-AEDB4A4CBD79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D880B5F5-B438-4AE7-9198-AEDB4A4CBD79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D880B5F5-B438-4AE7-9198-AEDB4A4CBD79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D880B5F5-B438-4AE7-9198-AEDB4A4CBD79}.Release|Any CPU.Build.0 = Release|Any CPU
{E5EDD471-192A-4812-97F9-A129BF0D5DE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5EDD471-192A-4812-97F9-A129BF0D5DE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5EDD471-192A-4812-97F9-A129BF0D5DE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5EDD471-192A-4812-97F9-A129BF0D5DE7}.Release|Any CPU.Build.0 = Release|Any CPU
{93CB8D34-DEC6-493A-9D5E-6951380EC21C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93CB8D34-DEC6-493A-9D5E-6951380EC21C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93CB8D34-DEC6-493A-9D5E-6951380EC21C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93CB8D34-DEC6-493A-9D5E-6951380EC21C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8747D210-D783-4C72-8513-7E46C1859738}
EndGlobalSection
EndGlobal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Adnc.Usr.Application.Contracts.Services
{
/// <summary>
/// 账户服务
/// 认证服务
/// </summary>
public interface IAccountAppService : IAppService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace Adnc.Usr.WebApi.Authentication;

public class AuthenticationHandlerLocal : AbstracAuthenticationHandler
public class BearerAuthenticationLocalProcessor : AbstracAuthenticationProcessor
{
private readonly IAccountAppService _accountAppService;

public AuthenticationHandlerLocal(IAccountAppService accountAppService) => _accountAppService = accountAppService;
public BearerAuthenticationLocalProcessor(IAccountAppService accountAppService) => _accountAppService = accountAppService;

protected override async Task<(string ValidationVersion, int Status)> GetValidatedInfoAsync(long userId)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace Adnc.Usr.WebApi.Authorization;

public sealed class PermissionHandlerLocal : AbstractPermissionHandler
public sealed class PermissionLocalHandler : AbstractPermissionHandler
{
private readonly IUserAppService _userAppService;

public PermissionHandlerLocal(IUserAppService userAppService) => _userAppService = userAppService;
public PermissionLocalHandler(IUserAppService userAppService) => _userAppService = userAppService;

protected override async Task<bool> CheckUserPermissions(long userId, IEnumerable<string> requestPermissions, string userBelongsRoleIds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public UsrWebApiDependencyRegistrar(IServiceCollection services)

public override void AddAdnc()
{
AddWebApiDefault<AuthenticationHandlerLocal, PermissionHandlerLocal>();
AddWebApiDefault<BearerAuthenticationLocalProcessor, PermissionLocalHandler>();
Services.AddGrpc();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ public BasicTokenGenerator(IHttpContextAccessor httpContextAccessor)

public virtual string Create()
{
var userName =
_userContext is null
? $"{BasicTokenValidator.InternalCaller}-0"
: $"{BasicTokenValidator.InternalCaller}-{_userContext.Id}"
;
long userId;
if (_userContext is null)
userId = 0;
else if (_userContext.Id == 0)
userId = _userContext.ExationId;
else
userId = _userContext.Id;

var userName = $"{BasicTokenValidator.InternalCaller}-{userId}";
var token = BasicTokenValidator.PackToBase64(userName);
return token;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public interface IAuthRestClient : IRestClient
/// </summary>
/// <returns></returns>
[Get("/auth/session")]
[Headers("Authorization: Bearer", "Cache: 10000")]
[Headers("Authorization: Basic", "Cache: 10000")]
Task<ApiResponse<UserValidatedInfoRto>> GetValidatedInfoAsync();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Adnc.Shared.WebApi.Authentication;

public abstract class AbstracAuthenticationHandler
public abstract class AbstracAuthenticationProcessor
{
public async Task<Claim[]> ValidateAsync(string securityToken)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
/// </summary>
public class BearerAuthenticationHandler : AuthenticationHandler<BearerSchemeOptions>
{
private AbstracAuthenticationHandler _authenticationHandler;
private AbstracAuthenticationProcessor _authenticationProcessor;

public BearerAuthenticationHandler(
IOptionsMonitor<BearerSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock,
AbstracAuthenticationHandler authenticationHandler
AbstracAuthenticationProcessor authenticationProcessor
) : base(options, logger, encoder, clock)
{
_authenticationHandler = authenticationHandler;
_authenticationProcessor = authenticationProcessor;
}

protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
Expand All @@ -33,7 +33,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
return await Task.FromResult(authResult);
}

var claims = await _authenticationHandler.ValidateAsync(token);
var claims = await _authenticationProcessor.ValidateAsync(token);

if (claims.IsNotNullOrEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Adnc.Shared.WebApi.Authentication;

public class BearerAuthenticationRemoteProcessor : AbstracAuthenticationProcessor
{
private IHttpContextAccessor _contextAccessor;
private IAuthRestClient _authRestClient;

public BearerAuthenticationRemoteProcessor(
IHttpContextAccessor contextAccessor,
IAuthRestClient authRestClient
)
{
_contextAccessor = contextAccessor;
_authRestClient = authRestClient;
}

protected override async Task<(string ValidationVersion, int Status)> GetValidatedInfoAsync(long userId)
{
var userContext = _contextAccessor.HttpContext.RequestServices.GetService<UserContext>();
userContext.ExationId = userId;

var apiReuslt = await _authRestClient.GetValidatedInfoAsync();
if (!apiReuslt.IsSuccessStatusCode)
return (null, 0);

return (apiReuslt.Content.ValidationVersion, apiReuslt.Content.Status);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Adnc.Shared.Rpc.Rest.Services;
namespace Adnc.Shared.WebApi.Authentication;

namespace Adnc.Shared.WebApi.Authentication;

public sealed class PermissionHandlerRemote : AbstractPermissionHandler
public sealed class PermissionRemoteHandler : AbstractPermissionHandler
{
private readonly IUsrRestClient _usrRestClient;

public PermissionHandlerRemote(IUsrRestClient usrRestClient) => _usrRestClient = usrRestClient;
public PermissionRemoteHandler(IUsrRestClient usrRestClient) => _usrRestClient = usrRestClient;

protected override async Task<bool> CheckUserPermissions(long userId, IEnumerable<string> requestPermissions, string userBelongsRoleIds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ protected AbstractWebApiDependencyRegistrar(IServiceCollection services)
/// 注册Webapi通用的服务
/// </summary>
/// <typeparam name="THandler"></typeparam>
protected virtual void AddWebApiDefault() => AddWebApiDefault<AuthenticationHandlerRemote,PermissionHandlerRemote>();
protected virtual void AddWebApiDefault() => AddWebApiDefault<BearerAuthenticationRemoteProcessor, PermissionRemoteHandler>();

/// <summary>
/// 注册Webapi通用的服务
/// </summary>
/// <typeparam name="THandler"></typeparam>
protected virtual void AddWebApiDefault<TAuthenticationHandler,TAuthorizationHandler>()
where TAuthenticationHandler : AbstracAuthenticationHandler
where TAuthenticationHandler : AbstracAuthenticationProcessor
where TAuthorizationHandler : AbstractPermissionHandler
{
Services.AddHttpContextAccessor();
Expand Down Expand Up @@ -139,11 +139,11 @@ protected virtual void AddControllers()
/// 注册身份认证组件
/// </summary>
protected virtual void AddAuthentication<TAuthenticationHandler>()
where TAuthenticationHandler : AbstracAuthenticationHandler
where TAuthenticationHandler : AbstracAuthenticationProcessor
{
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
Services
.AddScoped<AbstracAuthenticationHandler, TAuthenticationHandler>();
.AddScoped<AbstracAuthenticationProcessor, TAuthenticationHandler>();
Services
.AddAuthentication(HybridDefaults.AuthenticationScheme)
.AddHybrid()
Expand Down
Loading

0 comments on commit 8dbfe22

Please sign in to comment.