大版本更新

This commit is contained in:
橙子
2022-04-09 16:16:32 +08:00
parent 6d63c0cc59
commit ef8dc26125
34 changed files with 314 additions and 187 deletions

Binary file not shown.

View File

@@ -10,7 +10,7 @@
</summary>
<typeparam name="T"></typeparam>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Get(System.Object)">
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Get(System.Int64)">
<summary>
主键查询
</summary>
@@ -44,12 +44,30 @@
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.DeleteList(System.Collections.Generic.List{System.Guid})">
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.DeleteList(System.Collections.Generic.List{System.Int64})">
<summary>
列表删除
</summary>
<param name="ids"></param>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.LocalTest">
<summary>
国际化测试
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.PermissionTest">
<summary>
权限测试
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.AutnTest">
<summary>
策略授权测试
</summary>
<returns></returns>
</member>
</members>
</doc>

View File

@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Language;
using Yi.Framework.Model.Models;
using Yi.Framework.Model.Query;
using Yi.Framework.Repository;
@@ -19,7 +21,6 @@ namespace Yi.Framework.ApiMicroservice.Controllers
public readonly ILogger<T> _logger;
public IBaseService<T> _baseService;
public IRepository<T> _repository;
public BaseCrudController(ILogger<T> logger, IBaseService<T> iBaseService)
{
_logger = logger;
@@ -34,7 +35,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
/// <returns></returns>
[Permission($"{nameof(T)}:get:one")]
[HttpGet]
public async Task<Result> Get(object id)
public async Task<Result> Get(long id)
{
return Result.Success().SetData(await _repository.GetByIdAsync(id));
}
@@ -71,7 +72,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
[HttpPost]
public async Task<Result> Add(T entity)
{
return Result.Success().SetData(await _repository.InsertReturnEntityAsync(entity));
return Result.Success().SetData(await _repository.InsertReturnSnowflakeIdAsync(entity));
}
/// <summary>
@@ -93,7 +94,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
/// <returns></returns>
[Permission($"{nameof(T)}:delete:list")]
[HttpDelete]
public async Task<Result> DeleteList(List<Guid> ids)
public async Task<Result> DeleteList(List<long> ids)
{
return Result.Success().SetStatus(await _repository.DeleteByLogic(ids));
}

View File

@@ -1,26 +0,0 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AttributeExtend;
using Yi.Framework.WebCore.AuthorizationPolicy;
namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
public class TenantController : BaseCrudController<TenantEntity>
{
public TenantController(ILogger<TenantEntity> logger, ITenantService iTenantService) : base(logger, iTenantService)
{
}
}
}

View File

@@ -0,0 +1,61 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Language;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AttributeExtend;
using Yi.Framework.WebCore.AuthorizationPolicy;
namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
public class TestController : ControllerBase
{
private IStringLocalizer<LocalLanguage> _local;
public TestController(ILogger<UserEntity> logger, IUserService iUserService, IStringLocalizer<LocalLanguage> local)
{
_local = local;
}
/// <summary>
/// 国际化测试
/// </summary>
/// <returns></returns>
[HttpGet]
public Result LocalTest()
{
return Result.Success().SetData(_local["succeed"]);
}
/// <summary>
/// 权限测试
/// </summary>
/// <returns></returns>
[HttpGet]
[Permission("user:get:test")]
public Result PermissionTest()
{
return Result.Success();
}
/// <summary>
/// 策略授权测试
/// </summary>
/// <returns></returns>
[HttpGet]
[Authorize(PolicyName.Sid)]
public Result AutnTest()
{
return Result.Success();
}
}
}

View File

@@ -108,7 +108,6 @@ builder.Services.AddCAPService();
builder.Services.AddLocalizerService();
//-----------------------------------------------------------------------------------------------------------
var app = builder.Build();
#region
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#endregion

View File

@@ -31,6 +31,7 @@
},
"DbConn": {
//"WriteUrl": "DataSource=yi-sqlsugar-dev.db",
"WriteUrl": "server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",
"ReadUrl": [
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",

View File

@@ -25,13 +25,10 @@
"Cors_Enabled": true,
"DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle" ],
"DbSelect": "Mysql",
"Pan": {
"ZipPath": "D:/AppWeb/test/zip"
},
"DbSelect": "Sqlite",
"DbConn": {
"WriteUrl": "server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",
"WriteUrl": "DataSource=yi-sqlsugar-dev.db",
//"WriteUrl": "[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",
"ReadUrl": [
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace Yi.Framework.Common.IOCOptions
{
public class DbConnOptions
public class SqlConnOptions
{
public string WriteUrl { get; set; }
public List<string> ReadUrl { get; set; }

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Common.IOCOptions
{
public class SqliteOptions
{
public string WriteUrl { get; set; }
public List<string> ReadUrl { get; set; }
}
}

View File

@@ -37,11 +37,10 @@ namespace Yi.Framework.Core
claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"));
claims.Add(new Claim(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(DateTime.Now.AddMinutes(minutes)).ToUnixTimeSeconds()}"));
claims.Add(new Claim(JwtRegisteredClaimNames.Sid, user.Id.ToString()));
//claims.Add(new Claim("TenantId", userRoleMenuEntity.user.TenantId.ToString()));
//claims.Add(new Claim("TenantName", userRoleMenuEntity.tenant.TenantName.ToString()));
//claims.Add(new Claim("Id", userRoleMenuEntity.user.Id.ToString()));
//claims.Add(new Claim("Name", userRoleMenuEntity.user.Name));
//claims.Add(new Claim("TenantLevel", userRoleMenuEntity.tenant.TenantLevel.ToString()));
//-----------------------------以下从user的权限表中添加权限-----------------------例如:
claims.Add(new Claim("permission", "userentity:get:list"));
claims.Add(new Claim("permission", "userentity:get:one"));
if (isRefresh)
{

View File

@@ -1,9 +0,0 @@
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Interface
{
public partial interface ITenantService:IBaseService<TenantEntity>
{
}
}

View File

@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="T4Service.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
<ProjectReference Include="..\Yi.Framework.Repository\Yi.Framework.Repository.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Folder Include="IServiceTemplate\" />
</ItemGroup>
</Project>

View File

@@ -14,12 +14,23 @@
<ProjectReference Include="..\Yi.Framework.Repository\Yi.Framework.Repository.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="T4IService.tt">
<LastGenOutput>T4Iservice.cs</LastGenOutput>
<Generator>TextTemplatingFileGenerator</Generator>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Folder Include="IServiceTemplate\" />
<Compile Update="T4IService.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>T4IService.tt</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@@ -11,7 +11,6 @@ namespace Yi.Framework.Model.Models
{
public BaseModelEntity()
{
this.Id = Guid.NewGuid();
this.IsDeleted = false;
this.CreateTime = DateTime.Now;
}
@@ -19,17 +18,17 @@ namespace Yi.Framework.Model.Models
/// 1
///</summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
public Guid Id { get; set; }
public long Id { get; set; }
/// <summary>
/// 创建者
/// </summary>
[SugarColumn(ColumnName = "CreateUser")]
public Guid? CreateUser { get; set; }
public long? CreateUser { get; set; }
/// <summary>
/// 修改者
///</summary>
[SugarColumn(ColumnName = "ModifyUser")]
public Guid? ModifyUser { get; set; }
public long? ModifyUser { get; set; }
/// <summary>
/// 创建时间
///</summary>

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;
namespace Yi.Framework.Model.Models
{
/// <summary>
/// 租户表
///</summary>
[SugarTable("Tenant")]
public partial class TenantEntity:BaseModelEntity
{
/// <summary>
/// 租户名
///</summary>
[SugarColumn(ColumnName="TenantName" )]
public string TenantName { get; set; }
}
}

View File

@@ -5,38 +5,38 @@ using SqlSugar;
namespace Yi.Framework.Model.Models
{
/// <summary>
/// 用户表
///
///</summary>
[SugarTable("User")]
public partial class UserEntity:BaseModelEntity
{
/// <summary>
/// 姓名
///
///</summary>
[SugarColumn(ColumnName="Name" )]
public string Name { get; set; }
/// <summary>
/// 年龄
///
///</summary>
[SugarColumn(ColumnName="Age" )]
public int? Age { get; set; }
/// <summary>
/// 租户Id
///
///</summary>
[SugarColumn(ColumnName="TenantId" )]
public Guid? TenantId { get; set; }
public long? TenantId { get; set; }
/// <summary>
/// 账户
///
///</summary>
[SugarColumn(ColumnName="UserName" )]
public string UserName { get; set; }
/// <summary>
/// 密码
///
///</summary>
[SugarColumn(ColumnName="Password" )]
public string Password { get; set; }
/// <summary>
/// 加密盐值
///
///</summary>
[SugarColumn(ColumnName="Salt" )]
public string Salt { get; set; }

View File

@@ -0,0 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="BaseModels\**" />
<Compile Remove="ModelFactory\**" />
<EmbeddedResource Remove="BaseModels\**" />
<EmbeddedResource Remove="ModelFactory\**" />
<None Remove="BaseModels\**" />
<None Remove="ModelFactory\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NEST" Version="7.16.0" />
<PackageReference Include="SqlSugarCore" Version="5.0.6.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Common\Yi.Framework.Common.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="T4DaraContext.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>T4DaraContext.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Compile Update="T4DaraContext.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>T4DaraContext.tt</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@@ -1,21 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="BaseModels\**" />
<Compile Remove="ModelFactory\**" />
<EmbeddedResource Remove="BaseModels\**" />
<EmbeddedResource Remove="ModelFactory\**" />
<None Remove="BaseModels\**" />
<None Remove="ModelFactory\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NEST" Version="7.16.0" />
<PackageReference Include="SqlSugarCore" Version="5.0.6.4" />
<PackageReference Include="SqlSugarCore" Version="5.0.6.5" />
</ItemGroup>
<ItemGroup>
@@ -27,6 +18,10 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>T4DaraContext.cs</LastGenOutput>
</None>
<None Update="T4DataContext.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>T4DataContext.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
@@ -39,6 +34,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>T4DaraContext.tt</DependentUpon>
</Compile>
<Compile Update="T4DataContext.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>T4DataContext.tt</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@@ -17,6 +17,6 @@ namespace Yi.Framework.Repository
public Task<List<S>> StoreAsync<S>(string storeName, object para);
public Task<PageModel<List<T>>> CommonPage(QueryPageCondition pars);
public Task<List<T>> GetListAsync(QueryCondition pars);
public Task<bool> DeleteByLogic(List<Guid> ids);
public Task<bool> DeleteByLogic(List<long> ids);
}
}

View File

@@ -31,6 +31,7 @@ namespace Yi.Framework.Repository
/// <returns></returns>
public async Task<T> InsertReturnEntityAsync(T entity)
{
entity.Id =SnowFlakeSingle.instance.getID();
return await Db.Insertable(entity).ExecuteReturnEntityAsync();
}
@@ -38,7 +39,7 @@ namespace Yi.Framework.Repository
/// 逻辑多删除
/// </summary>
/// <returns></returns>
public async Task<bool> DeleteByLogic(List<Guid> ids)
public async Task<bool> DeleteByLogic(List<long> ids)
{
var entitys = await Db.Queryable<T>().Where(u => ids.Contains(u.Id)).ToListAsync();
entitys.ForEach(u=>u.IsDeleted=true);

View File

@@ -11,6 +11,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Common\Yi.Framework.Common.csproj" />
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
</ItemGroup>

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class TenantService : BaseService<TenantEntity>, ITenantService
{
public TenantService(IRepository<TenantEntity> repository) : base(repository)
{
}
}
}

View File

@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="T4DaraContext.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Core\Yi.Framework.Core.csproj" />
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
<ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" />
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
<ProjectReference Include="..\Yi.Framework.Repository\Yi.Framework.Repository.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Folder Include="ServiceTemplate\" />
</ItemGroup>
</Project>

View File

@@ -16,12 +16,23 @@
<ProjectReference Include="..\Yi.Framework.Repository\Yi.Framework.Repository.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="T4Service.tt">
<LastGenOutput>T4Service.cs</LastGenOutput>
<Generator>TextTemplatingFileGenerator</Generator>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Folder Include="ServiceTemplate\" />
<Compile Update="T4Service.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>T4Service.tt</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.IdentityModel.JsonWebTokens;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -29,16 +30,21 @@ namespace Yi.Framework.WebCore.AttributeExtend
{
throw new Exception("权限不能为空!");
}
//可以从Redis得到用户菜单列表或者直接从jwt中获取
var result = false;
//判断权限是否存在Redis中
if (permission.Length>0)
{
result = true;
}
//可以从Redis得到用户菜单列表或者直接从jwt中获取
var sid = context.HttpContext.User.Claims.FirstOrDefault(u => u.Type == JwtRegisteredClaimNames.Sid);
//jwt存在的权限列表
var perList = context.HttpContext.User.Claims.Where(u => u.Type == "permission").Select(u=> u.Value.ToString().ToLower()). ToList();
//判断权限是否存在Redis中,或者jwt中
//if (perList.Contains(permission.ToLower()))
//{
// result = true;
//}
result = true;
if (!result)

View File

@@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.IdentityModel.JsonWebTokens;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -15,51 +17,30 @@ namespace Yi.Framework.WebCore.AuthorizationPolicy
public class CustomAuthorizationHandler : AuthorizationHandler<CustomAuthorizationRequirement>
{
private CacheClientDB _cacheClientDB;
//private CacheClientDB _cacheClientDB;
/// <summary>
/// 构造函数
/// </summary>
public CustomAuthorizationHandler(CacheClientDB cacheClientDB)
public CustomAuthorizationHandler()
{
_cacheClientDB= cacheClientDB;
}
//验证的方法就在这里
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, CustomAuthorizationRequirement requirement)
{
var currentClaim = context.User.Claims.FirstOrDefault(u => u.Type == ClaimTypes.Sid);
if (currentClaim==null) //说明没有写入Sid 没有登录
{
return Task.CompletedTask; //验证不同过
}
int currentUserId = 0;
if (!string.IsNullOrWhiteSpace(currentClaim.Value))
{
currentUserId = Convert.ToInt32(currentClaim.Value);
}
DefaultHttpContext httpcontext = (DefaultHttpContext)context.Resource;
Dictionary<string, string> dicMenueDictionary = new Dictionary<string, string>();
//现在只需要登录的时候把用户的api路径添加到redis去
//每次访问的时候进行redis判断一下即可
//注意一下redis不能一直保存和jwt一样搞一个期限
//var menuList=_cacheClientDB.Get<List<menuDto>>(RedisConst.userMenusApi+":"+currentUserId);
//foreach (var k in menuList)
//{
// if (k.mould != null)
// {
// dicMenueDictionary.Add(k.mould?.id.ToString(), "/api"+ k.mould?.url);
// }
//}
if (dicMenueDictionary.ContainsValue(httpcontext.Request.Path))
var currentClaim = context.User.Claims.FirstOrDefault(u => u.Type == JwtRegisteredClaimNames.Sid);
//DefaultHttpContext httpcontext = (DefaultHttpContext)context.AuthenticateAsync();
if (currentClaim!=null) //说明没有写入Sid 没有登录
{
context.Succeed(requirement); //验证通过了
}
//string currentUserId = "";
//if (!string.IsNullOrWhiteSpace(currentClaim.Value))
//{
// currentUserId = currentClaim.Value;
//}
//DefaultHttpContext httpcontext = (DefaultHttpContext)context.Resource;
return Task.CompletedTask; //验证不同过
}
}

View File

@@ -15,6 +15,6 @@ namespace Yi.Framework.WebCore.AuthorizationPolicy
}
public static class PolicyName
{
public const string Menu = "Menu";
public const string Sid = "Sid";
}
}

View File

@@ -33,9 +33,8 @@ namespace Yi.Framework.WebCore
public static UserEntity GetCurrentUserEntityInfo(this HttpContext httpContext, out List<Guid> menuIds)
{
IEnumerable<Claim> claimlist = httpContext.AuthenticateAsync().Result.Principal.Claims;
var resId= new Guid (claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Sid).Value);
long.TryParse(claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Sid).Value,out var resId) ;
menuIds = claimlist.Where(u => u.Type == "menuIds").ToList().Select(u => new Guid(u.Value)).ToList();

View File

@@ -13,15 +13,15 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
public static IServiceCollection AddAuthorizationService(this IServiceCollection services)
{
//services.AddAuthorization(options =>
//{
// options.AddPolicy(PolicyName.Menu, polic =>
// {
// polic.AddRequirements(new CustomAuthorizationRequirement(PolicyEnum.MenuPermissions));
// });
//});
services.AddAuthorization(options =>
{
options.AddPolicy(PolicyName.Sid, polic =>
{
polic.AddRequirements(new CustomAuthorizationRequirement(PolicyEnum.MenuPermissions));
});
});
//services.AddSingleton<IAuthorizationHandler, CustomAuthorizationHandler>();
services.AddSingleton<IAuthorizationHandler, CustomAuthorizationHandler>();
return services;
}
}

View File

@@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
using Yi.Framework.Common.IOCOptions;
using Yi.Framework.Model;
namespace Yi.Framework.WebCore.MiddlewareExtend
@@ -20,6 +21,11 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
#endregion
services.AddSingleton(new Appsettings(configuration));
#region
//数据库连接字符串
#endregion
services.Configure<SqlConnOptions>(Appsettings.appConfiguration("DbConn"));
return services;
}

View File

@@ -27,11 +27,9 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,//是否验证Issuer
ValidateIssuer = true,//是否验证Issuer
ValidateAudience = true,//是否验证Audience
ValidateLifetime = true,//是否验证失效时间
ValidateIssuerSigningKey = true,//是否验证SecurityKey
ValidAudience = jwtOptions.Audience,//Audience
ValidIssuer = jwtOptions.Issuer,//Issuer这两项和前面签发jwt的设置一致

View File

@@ -12,11 +12,36 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
public static void AddSqlsugarServer(this IServiceCollection services)
{
DbType dbType;
var slavaConFig = new List<SlaveConnectionConfig>();
if (Appsettings.appBool("MutiDB_Enabled"))
{
var readCon = Appsettings.app<List<string>>("DbConn", "ReadUrl");
readCon.ForEach(s => {
slavaConFig.Add(new SlaveConnectionConfig() { ConnectionString = s });
});
}
switch (Appsettings.app("DbSelect"))
{
case "Mysql": dbType = DbType.MySql; break;
case "Sqlite": dbType = DbType.Sqlite; break;
case "Sqlserver": dbType = DbType.SqlServer; break;
case "Oracle": dbType = DbType.Oracle; break;
default:throw new Exception("DbSelect配置写的TM是个什么东西");
}
SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
{
DbType = SqlSugar.DbType.MySql,
DbType = dbType,
ConnectionString = Appsettings.app("DbConn", "WriteUrl"),
IsAutoCloseConnection = true
IsAutoCloseConnection = true,
MoreSettings = new ConnMoreSettings()
{
DisableNvarchar = true
},
SlaveConnectionConfigs = slavaConFig,
},
db =>
{
@@ -31,7 +56,6 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
//entityInfo.SetValue(new Guid(httpcontext.Request.Headers["Id"].ToString()));
}
if (entityInfo.PropertyName == "TenantId")
{
//entityInfo.SetValue(new Guid(httpcontext.Request.Headers["TenantId"].ToString()));