|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
|
|
using Myshipping.Core.Entity;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
@ -20,19 +21,25 @@ namespace Myshipping.Core
|
|
|
|
|
{
|
|
|
|
|
if (metadata.GetType() == typeof(ApiUserAttribute))
|
|
|
|
|
{
|
|
|
|
|
if (context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_KEY)
|
|
|
|
|
&& context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_SECRET))
|
|
|
|
|
//if (context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_KEY)
|
|
|
|
|
//&& context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_SECRET))
|
|
|
|
|
{
|
|
|
|
|
var httpContext = App.GetService<IHttpContextAccessor>().HttpContext;
|
|
|
|
|
|
|
|
|
|
var repTenant = App.GetService<SqlSugarRepository<SysTenant>>();
|
|
|
|
|
var repUser = App.GetService<SqlSugarRepository<SysUser>>();
|
|
|
|
|
|
|
|
|
|
var tenant = repTenant.AsQueryable().Filter(null, true).First(x => x.Id == 142307070918780L);
|
|
|
|
|
var user = repUser.AsQueryable().Filter(null, true).First(x => x.Id == 142307070910551L);
|
|
|
|
|
|
|
|
|
|
ClaimsIdentity identity = new ClaimsIdentity("AuthenticationTypes.Federation");
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_USERID, value: "111"));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.TENANT_ID, value: "10"));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_ACCOUNT, value: "admin"));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_NAME, value: "管理员"));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_SUPERADMIN, value: AdminType.Admin.ToString()));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_TENANT_TYPE, value: TenantTypeEnum.SYSTEM.ToString()));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.TENANT_NAME, value: "测试"));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_USERID, value: user.Id.ToString()));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_ACCOUNT, value: user.Account));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_NAME, value: user.Name));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_SUPERADMIN, value: ((int)user.AdminType).ToString()));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_TENANT_TYPE, value: tenant.TenantType.ToString()));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.TENANT_ID, value: tenant.Id.ToString()));
|
|
|
|
|
identity.AddClaim(new Claim(type: ClaimConst.TENANT_NAME, value: tenant.Name));
|
|
|
|
|
ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity);
|
|
|
|
|
httpContext.User = claimsPrincipal;
|
|
|
|
|
}
|
|
|
|
|