mirror of
https://gitee.com/yubaolee/OpenAuth.Core.git
synced 2025-12-06 16:39:10 +08:00
@@ -3,7 +3,7 @@
|
||||
public static class Define
|
||||
{
|
||||
public static string USERROLE = "UserRole"; //用户角色关联KEY
|
||||
public const string ROLERESOURCE= "RoleResource"; //角色资源关联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
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
public const string DBTYPE_SQLSERVER = "SqlServer"; //sql server
|
||||
public const string DBTYPE_MYSQL = "MySql"; //mysql
|
||||
public const string DBTYPE_PostgreSQL = "PostgreSQL"; //mysql
|
||||
public const string DBTYPE_ORACLE = "Oracle"; //oracle
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Infrastructure;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
@@ -19,13 +22,13 @@ namespace OpenAuth.Mvc.Controllers
|
||||
}
|
||||
|
||||
// GET: /ModuleManager/
|
||||
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ActionResult Assign()
|
||||
{
|
||||
return View();
|
||||
@@ -41,7 +44,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
var modules = _app.LoadForRole(firstId);
|
||||
return JsonHelper.Instance.Serialize(modules);
|
||||
}
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 获取角色已经分配的字段
|
||||
/// </summary>
|
||||
/// <param name="roleId">角色id</param>
|
||||
@@ -53,19 +56,19 @@ namespace OpenAuth.Mvc.Controllers
|
||||
try
|
||||
{
|
||||
var props = _app.LoadPropertiesForRole(roleId, moduleCode);
|
||||
var data = new Response<IEnumerable<string>>
|
||||
var data = new Response<IEnumerable<string>>
|
||||
{
|
||||
Result = props.ToList(),
|
||||
};
|
||||
return JsonHelper.Instance.Serialize(data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch(Exception ex)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(new Response
|
||||
{
|
||||
Message =ex.Message,
|
||||
Code = 500,
|
||||
});
|
||||
{
|
||||
Message = ex.Message,
|
||||
Code = 500,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +89,8 @@ namespace OpenAuth.Mvc.Controllers
|
||||
public string LoadAuthorizedMenus(string modulecode)
|
||||
{
|
||||
var user = _authUtil.GetCurrentUser();
|
||||
var module = user.Modules.First(u =>u.Code == modulecode);
|
||||
if (module != null)
|
||||
var module = user.Modules.First(u => u.Code == modulecode);
|
||||
if(module != null)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(module.Elements);
|
||||
|
||||
@@ -100,31 +103,31 @@ namespace OpenAuth.Mvc.Controllers
|
||||
|
||||
//添加模块
|
||||
[HttpPost]
|
||||
|
||||
|
||||
public string Add(Module model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Add(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch(Exception ex)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = ex.InnerException?.Message??ex.Message;
|
||||
Result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(Result);
|
||||
}
|
||||
|
||||
//修改模块
|
||||
[HttpPost]
|
||||
|
||||
|
||||
public string Update(Module model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch(Exception ex)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
@@ -139,7 +142,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
_app.Delete(ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch(Exception e)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = e.InnerException?.Message ?? e.Message;
|
||||
@@ -160,7 +163,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
var user = _authUtil.GetCurrentUser();
|
||||
|
||||
var module = user.Modules.Single(u => u.Id == moduleId);
|
||||
|
||||
|
||||
var data = new TableData
|
||||
{
|
||||
data = module.Elements,
|
||||
@@ -171,14 +174,14 @@ namespace OpenAuth.Mvc.Controllers
|
||||
|
||||
//添加菜单
|
||||
[HttpPost]
|
||||
|
||||
|
||||
public string AddMenu(ModuleElement model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddMenu(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch(Exception ex)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
@@ -188,14 +191,14 @@ namespace OpenAuth.Mvc.Controllers
|
||||
|
||||
//添加菜单
|
||||
[HttpPost]
|
||||
|
||||
|
||||
public string UpdateMenu(ModuleElement model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.UpdateMenu(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch(Exception ex)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
@@ -214,7 +217,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
_app.DelMenu(ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch(Exception e)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = e.InnerException?.Message ?? e.Message;
|
||||
@@ -223,6 +226,6 @@ namespace OpenAuth.Mvc.Controllers
|
||||
return JsonHelper.Instance.Serialize(Result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.Repository.Domain;
|
||||
@@ -27,12 +29,12 @@ namespace OpenAuth.Mvc.Models
|
||||
|
||||
//添加有允许匿名的Action,可以不用登录访问,如Login/Index
|
||||
var anonymous = description.MethodInfo.GetCustomAttribute(typeof(AllowAnonymousAttribute));
|
||||
if (anonymous != null)
|
||||
if(anonymous != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_authUtil.CheckLogin())
|
||||
if(!_authUtil.CheckLogin())
|
||||
{
|
||||
context.Result = new RedirectResult("/Login/Index");
|
||||
return;
|
||||
@@ -43,7 +45,7 @@ namespace OpenAuth.Mvc.Models
|
||||
//如果是ajax请求的,跳过模块授权认证
|
||||
var headers = context.HttpContext.Request.Headers;
|
||||
var xreq = headers.ContainsKey("x-requested-with");
|
||||
if (xreq && headers["x-requested-with"] == "XMLHttpRequest")
|
||||
if(xreq && headers["x-requested-with"] == "XMLHttpRequest")
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -51,22 +53,22 @@ namespace OpenAuth.Mvc.Models
|
||||
var Controllername = description.ControllerName.ToLower();
|
||||
var Actionname = description.ActionName.ToLower();
|
||||
//控制器白名单,在该名单中的控制器,需要登录,但不需要授权
|
||||
var whiteController = new[] {"usersession","home","redirects"};
|
||||
if (whiteController.Contains(Controllername))
|
||||
var whiteController = new[] { "usersession", "home", "redirects" };
|
||||
if(whiteController.Contains(Controllername))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//URL白名单
|
||||
var whiteurls = new[] {"usermanager/changepassword", "usermanager/profile"};
|
||||
if (whiteurls.Contains(Controllername + "/" + Actionname))
|
||||
var whiteurls = new[] { "usermanager/changepassword", "usermanager/profile" };
|
||||
if(whiteurls.Contains(Controllername + "/" + Actionname))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var currentModule = _authUtil.GetCurrentUser().Modules.FirstOrDefault(u => u.Url.ToLower().Contains(Controllername));
|
||||
//当前登录用户没有Action记录
|
||||
if (currentModule == null)
|
||||
if(currentModule == null)
|
||||
{
|
||||
context.Result = new RedirectResult("/Error/Auth");
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
"AllowedHosts": "*",
|
||||
"DataProtection": "temp-keys/",
|
||||
"ConnectionStrings": {
|
||||
"OpenAuthDBContext": "Data Source=.;Initial Catalog=OpenAuthDB;User=sa;Password=000000"
|
||||
//"OpenAuthDBContext": "server=127.0.0.1;user id=root;database=openauthdb;password=000000" //my sql
|
||||
"OpenAuthDBContext": "Host=localhost;Port=5432;Database=OpenAuth;Username=postgres;Password=123;"
|
||||
},
|
||||
"AppSetting": {
|
||||
//"IdentityServerUrl": "http://localhost:12796", //IdentityServer服务器地址。如果为空,则不启用OAuth认证
|
||||
@@ -16,7 +15,7 @@
|
||||
"SSOPassport": "http://localhost:52789",
|
||||
"Version": "1.0", //如果为demo,则可以防止post提交
|
||||
"DbTypes": {
|
||||
"OpenAuthDBContext":"SqlServer" //数据库类型:SqlServer、MySql、Oracle
|
||||
"OpenAuthDBContext": "PostgreSQL" //数据库类型:SqlServer、MySql、Oracle
|
||||
},
|
||||
"RedisConf": "redistest.cq-p.com.cn:8001,password=share_redis@123", //redis配置
|
||||
"HttpHost": "http://*:1802" //启动绑定地址及端口
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<key id="c38e86e4-ecc5-42c1-bc85-bea79d9f99cb" version="1">
|
||||
<creationDate>2023-02-10T06:43:55.6481399Z</creationDate>
|
||||
<activationDate>2023-02-10T06:43:55.6252297Z</activationDate>
|
||||
<expirationDate>2023-05-11T06:43:55.6252297Z</expirationDate>
|
||||
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=3.1.31.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
|
||||
<descriptor>
|
||||
<encryption algorithm="AES_256_CBC" />
|
||||
<validation algorithm="HMACSHA256" />
|
||||
<masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
|
||||
<!-- Warning: the key below is in an unencrypted form. -->
|
||||
<value>fs5gZELJa/ZPaXZMycsuUh5hJKsKEoXMqEziaG1EdETcT5PuKTRhnjYFRQVDrL6XutNp8jB3GOIlAdYgfMvyXg==</value>
|
||||
</masterKey>
|
||||
</descriptor>
|
||||
</descriptor>
|
||||
</key>
|
||||
@@ -16,6 +16,7 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" />
|
||||
<PackageReference Include="Moq" Version="4.13.1" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.13" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
|
||||
|
||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Infrastructure;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Utilities;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.QueryObj;
|
||||
|
||||
namespace OpenAuth.Repository
|
||||
{
|
||||
|
||||
|
||||
public partial class OpenAuthDBContext : DbContext
|
||||
{
|
||||
|
||||
@@ -23,7 +25,7 @@ namespace OpenAuth.Repository
|
||||
private IConfiguration _configuration;
|
||||
private IOptions<AppSetting> _appConfiguration;
|
||||
|
||||
public OpenAuthDBContext(DbContextOptions<OpenAuthDBContext> options, ILoggerFactory loggerFactory,
|
||||
public OpenAuthDBContext(DbContextOptions<OpenAuthDBContext> options, ILoggerFactory loggerFactory,
|
||||
IHttpContextAccessor httpContextAccessor, IConfiguration configuration, IOptions<AppSetting> appConfiguration)
|
||||
: base(options)
|
||||
{
|
||||
@@ -47,7 +49,7 @@ namespace OpenAuth.Repository
|
||||
|
||||
var tenantId = _httpContextAccessor.GetTenantId();
|
||||
string connect = _configuration.GetConnectionString(tenantId);
|
||||
if (string.IsNullOrEmpty(connect))
|
||||
if(string.IsNullOrEmpty(connect))
|
||||
{
|
||||
throw new Exception($"未能找到租户{tenantId}对应的连接字符串信息");
|
||||
}
|
||||
@@ -55,20 +57,24 @@ namespace OpenAuth.Repository
|
||||
//这个地方如果用IOption,在单元测试的时候会获取不到AppSetting的值😅
|
||||
var dbtypes = _configuration.GetSection("AppSetting:DbTypes").GetChildren()
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
|
||||
var dbType = dbtypes[tenantId];
|
||||
if (dbType == Define.DBTYPE_SQLSERVER)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(connect);
|
||||
|
||||
var dbType = dbtypes[tenantId];
|
||||
if(dbType == Define.DBTYPE_SQLSERVER)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(connect);
|
||||
}
|
||||
else if(dbType == Define.DBTYPE_MYSQL) //mysql
|
||||
{
|
||||
optionsBuilder.UseMySql(connect, new MySqlServerVersion(new Version(8, 0, 11)));
|
||||
}
|
||||
else
|
||||
{
|
||||
optionsBuilder.UseOracle(connect,options =>options.UseOracleSQLCompatibility("11"));
|
||||
}
|
||||
{
|
||||
optionsBuilder.UseMySql(connect, new MySqlServerVersion(new Version(8, 0, 11)));
|
||||
}
|
||||
else if(dbType == Define.DBTYPE_PostgreSQL) //mysql
|
||||
{
|
||||
optionsBuilder.UseNpgsql(connect);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionsBuilder.UseOracle(connect, options => options.UseOracleSQLCompatibility("11"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -102,9 +108,9 @@ namespace OpenAuth.Repository
|
||||
public virtual DbSet<SysLog> SysLogs { get; set; }
|
||||
|
||||
public virtual DbSet<SysMessage> SysMessages { get; set; }
|
||||
|
||||
|
||||
public virtual DbSet<DataPrivilegeRule> DataPrivilegeRules { get; set; }
|
||||
|
||||
|
||||
public virtual DbSet<WmsInboundOrderDtbl> WmsInboundOrderDtbls { get; set; }
|
||||
public virtual DbSet<WmsInboundOrderTbl> WmsInboundOrderTbls { get; set; }
|
||||
public virtual DbSet<OpenJob> OpenJobs { get; set; }
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"AllowedHosts": "*",
|
||||
"DataProtection": "temp-keys/",
|
||||
"ConnectionStrings": {
|
||||
"OpenAuthDBContext": "Data Source=.;Initial Catalog=OpenAuthPro;User=sa;Password=000000"
|
||||
"OpenAuthDBContext": "Host=localhost;Port=5432;Database=OpenAuth;Username=postgres;Password=123;"
|
||||
//"OpenAuthDBContext2": "DATA SOURCE=192.168.0.118:1521/YUBAO;PASSWORD=000000;Validate Connection=true;PERSIST SECURITY INFO=True;USER ID=yubaolee;" //Oracle
|
||||
//"OpenAuthDBContext3": "server=127.0.0.1;user id=root;database=openauthpro;password=000000" //my sql
|
||||
},
|
||||
@@ -15,7 +15,7 @@
|
||||
"IdentityServerUrl": "", //IdentityServer服务器地址。如果为空,则不启用OAuth认证
|
||||
// "IdentityServerUrl": "http://localhost:12796", //IdentityServer服务器地址。如果为空,则不启用OAuth认证
|
||||
"DbTypes": {
|
||||
"OpenAuthDBContext":"SqlServer" //数据库类型:SqlServer、MySql、Oracle
|
||||
"OpenAuthDBContext":"PostgreSQL" //数据库类型:SqlServer、MySql、Oracle
|
||||
// ,"OpenAuthDBContext2":"Oracle"
|
||||
// ,"OpenAuthDBContext3":"MySql"
|
||||
},
|
||||
|
||||
1621
postgresql初始化备份/db_back.sql
Normal file
1621
postgresql初始化备份/db_back.sql
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user