调整为多租户模式

This commit is contained in:
yubaolee
2021-01-14 23:35:54 +08:00
parent 1228c6e875
commit 1ed50271bf
27 changed files with 148 additions and 59 deletions

View File

@@ -1,42 +0,0 @@
namespace OpenAuth.App
{
/// <summary>
/// 配置项
/// </summary>
public class AppSetting
{
public AppSetting()
{
SSOPassport = "http://localhost:52789";
Version = "";
UploadPath = "";
IdentityServerUrl = "";
DbType = Define.DBTYPE_SQLSERVER;
}
/// <summary>
/// SSO地址
/// </summary>
public string SSOPassport { get; set; }
/// <summary>
/// 版本信息
/// 如果为demo,则屏蔽Post请求
/// </summary>
public string Version { get; set; }
/// <summary>
/// 数据库类型 SqlServer、MySql
/// </summary>
public string DbType { get; set; }
/// <summary> 附件上传路径</summary>
public string UploadPath { get; set; }
//identity授权的地址
public string IdentityServerUrl { get; set; }
//是否是Identity授权方式
public bool IsIdentityAuth => !string.IsNullOrEmpty(IdentityServerUrl);
}
}

View File

@@ -14,6 +14,7 @@
//</summary>
// ***********************************************************************
using Infrastructure;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;

View File

@@ -1,32 +0,0 @@
using System;
namespace OpenAuth.App
{
public static class Define
{
public static string USERROLE = "UserRole"; //用户角色关联KEY
public const string ROLERESOURCE= "RoleResource"; //角色资源关联KEY
public const string USERORG = "UserOrg"; //用户机构关联KEY
public const string ROLEELEMENT = "RoleElement"; //角色菜单关联KEY
public const string ROLEMODULE = "RoleModule"; //角色模块关联KEY
public const string ROLEDATAPROPERTY = "RoleDataProperty"; //角色数据字段权限
public const string DBTYPE_SQLSERVER = "SqlServer"; //sql server
public const string DBTYPE_MYSQL = "MySql"; //sql server
public const int INVALID_TOKEN = 50014; //token无效
public const string TOKEN_NAME = "X-Token";
public const string SYSTEM_USERNAME = "System";
public const string SYSTEM_USERPWD = "123456";
public const string DATAPRIVILEGE_LOGINUSER = "{loginUser}"; //数据权限配置中当前登录用户的key
public const string DATAPRIVILEGE_LOGINROLE = "{loginRole}"; //数据权限配置中当前登录用户角色的key
public const string DATAPRIVILEGE_LOGINORG = "{loginOrg}"; //数据权限配置中当前登录用户部门的key
public const string JOBMAPKEY = "OpenJob";
}
}

View File

@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Infrastructure;
using Quartz;
namespace OpenAuth.App.Jobs

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Infrastructure;
using Microsoft.Extensions.Logging;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;

View File

@@ -5,6 +5,7 @@ using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
using System.Linq;
using Infrastructure;
using OpenAuth.App.Request;
using OpenAuth.Repository;

View File

@@ -2,6 +2,7 @@ using Infrastructure.Cache;
using Microsoft.AspNetCore.Http;
using OpenAuth.App.Interface;
using System;
using Infrastructure;
using Microsoft.Extensions.Options;
using OpenAuth.Repository.Domain;

View File

@@ -3,6 +3,7 @@
* 处理登录逻辑,验证客户段提交的账号密码,保存登录信息
*/
using System;
using Infrastructure;
using Infrastructure.Cache;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;

View File

@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Infrastructure;
using Infrastructure.Cache;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

View File

@@ -1,7 +1,10 @@
using Autofac.Extensions.DependencyInjection;
using Infrastructure;
using Infrastructure.Cache;
using Infrastructure.Extensions.AutofacManager;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Moq;
@@ -23,12 +26,24 @@ namespace OpenAuth.App.Test
serviceCollection.AddOptions();
serviceCollection.AddLogging();
//模拟配置文件
var optionMock = new Mock<IOptions<AppSetting>>();
optionMock.Setup(x => x.Value).Returns(new AppSetting { DbType = Define.DBTYPE_MYSQL});
serviceCollection.AddScoped(x => optionMock.Object);
// 测试my sql
serviceCollection.AddDbContext<OpenAuthDBContext>(options =>
//模拟多租户id
var configMock = new Mock<IConfiguration>();
configMock.Setup(x => x.GetSection("ConnectionStrings")[Define.TENANT_ID]).Returns("");
serviceCollection.AddScoped(x => configMock.Object);
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TENANT_ID]).Returns("OpenAuthDBContext");
serviceCollection.AddScoped(x => httpContextAccessorMock.Object);
// 测试my sql
serviceCollection.AddDbContext<OpenAuthDBContext>(options =>
options.UseMySql("server=127.0.0.1;user id=root;database=openauthdb;password=000000"));
// serviceCollection.AddDbContext<OpenAuthDBContext>(options =>

View File

@@ -1,6 +1,7 @@
using System.IO;
using System.Net.Http;
using System.Reflection;
using Infrastructure;
using Infrastructure.Cache;
using Infrastructure.Provider;
using Microsoft.AspNetCore.Http;

View File

@@ -23,10 +23,6 @@ namespace OpenAuth.App.Test
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest")).Returns(new UserAuthSession { Account = Define.SYSTEM_USERNAME });
services.AddScoped(x => cachemock.Object);
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
services.AddScoped(x => httpContextAccessorMock.Object);
var logMock = new Mock<ILogger<FileApp>>();
services.AddScoped(x => logMock.Object);

View File

@@ -1,4 +1,5 @@
using System.Net.Http;
using Infrastructure;
using Infrastructure.Cache;
using Microsoft.AspNetCore.Http;
using NUnit.Framework;

View File

@@ -1,4 +1,5 @@
using Infrastructure.Cache;
using Infrastructure;
using Infrastructure.Cache;
using Microsoft.AspNetCore.Http;
using NUnit.Framework;
using Microsoft.Extensions.DependencyInjection;

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Castle.Core.Internal;
using Infrastructure;
using Infrastructure.Extensions;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;