增加Oracle驱动

调整登录时应用判定
This commit is contained in:
yubaolee 2021-04-17 17:06:48 +08:00
parent b061f77495
commit c55ecaff85
10 changed files with 68 additions and 18 deletions

View File

@ -10,7 +10,8 @@
public const string ROLEDATAPROPERTY = "RoleDataProperty"; //角色数据字段权限
public const string DBTYPE_SQLSERVER = "SqlServer"; //sql server
public const string DBTYPE_MYSQL = "MySql"; //sql server
public const string DBTYPE_MYSQL = "MySql"; //mysql
public const string DBTYPE_ORACLE = "Oracle"; //oracle
public const int INVALID_TOKEN = 50014; //token无效

View File

@ -13,14 +13,19 @@ namespace OpenAuth.App
/// <summary>
/// 分类管理
/// </summary>
public class AppManager : BaseStringApp<Application,OpenAuthDBContext>
public class AppManager : BaseStringApp<Application, OpenAuthDBContext>
{
public AppManager(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Application, OpenAuthDBContext> repository) : base(unitWork, repository, null)
{
}
public void Add(Application Application)
{
if (string.IsNullOrEmpty(Application.Id))
{
Application.Id = Guid.NewGuid().ToString();
}
Repository.Add(Application);
}
@ -32,13 +37,15 @@ namespace OpenAuth.App
public async Task<List<Application>> GetList(QueryAppListReq request)
{
var applications = UnitWork.Find<Application>(null) ;
var applications = UnitWork.Find<Application>(null);
return applications.ToList();
}
public AppManager(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Application,OpenAuthDBContext> repository,IAuth auth) : base(unitWork, repository, auth)
public Application GetByAppKey(string modelAppKey)
{
return Repository.FirstOrDefault(u => u.AppSecret == modelAppKey);
}
}
}

View File

@ -18,9 +18,9 @@ namespace OpenAuth.App.SSO
//这个地方使用IRepository<User> 而不使用UserManagerApp是防止循环依赖
public IRepository<User,OpenAuthDBContext> _app;
private ICacheContext _cacheContext;
private AppInfoService _appInfoService;
private AppManager _appInfoService;
public LoginParse( AppInfoService infoService, ICacheContext cacheContext, IRepository<User,OpenAuthDBContext> userApp)
public LoginParse( AppManager infoService, ICacheContext cacheContext, IRepository<User,OpenAuthDBContext> userApp)
{
_appInfoService = infoService;
_cacheContext = cacheContext;
@ -33,12 +33,12 @@ namespace OpenAuth.App.SSO
try
{
model.Trim();
//获取应用信息
var appInfo = _appInfoService.Get(model.AppKey);
if (appInfo == null)
{
throw new Exception("应用不存在");
}
//todo:如果需要判定应用,可以取消该注释
// var appInfo = _appInfoService.GetByAppKey(model.AppKey);
// if (appInfo == null)
// {
// throw new Exception("应用不存在");
// }
//获取用户信息
User userInfo = null;
if (model.Account == Define.SYSTEM_USERNAME)
@ -84,7 +84,6 @@ namespace OpenAuth.App.SSO
_cacheContext.Set(currentSession.Token, currentSession, DateTime.Now.AddDays(10));
result.Code = 200;
result.ReturnUrl = appInfo.ReturnUrl;
result.Token = currentSession.Token;
}
catch (Exception ex)

View File

@ -9,6 +9,9 @@ namespace OpenAuth.App.SSO
public string Password { get; set; }
/// <summary>
/// 应用的AppSecrect目前没判定可以随便填一个。如果需要判定请根据注释调整LoginParse.Do方法
/// </summary>
public string AppKey { get; set; }
public void Trim()

View File

@ -77,11 +77,16 @@ namespace OpenAuth.IdentityServer
services.AddDbContext<OpenAuthDBContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("OpenAuthDBContext")));
}
else //mysql
else if(dbType == Define.DBTYPE_MYSQL) //mysql
{
services.AddDbContext<OpenAuthDBContext>(options =>
options.UseMySql(Configuration.GetConnectionString("OpenAuthDBContext")));
}
else //oracle
{
services.AddDbContext<OpenAuthDBContext>(options =>
options.UseOracle(Configuration.GetConnectionString("OpenAuthDBContext")));
}
}

View File

@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Autofac" Version="5.1.2" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
<PackageReference Include="Moq" Version="4.13.1" />
@ -19,6 +20,8 @@
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Oracle.EntityFrameworkCore" Version="3.19.110" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.110" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.4" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="3.0.40" />
</ItemGroup>

View File

@ -70,10 +70,14 @@ namespace OpenAuth.Repository
{
optionsBuilder.UseSqlServer(connect);
}
else //mysql
else if(dbType == Define.DBTYPE_MYSQL) //mysql
{
optionsBuilder.UseMySql(connect);
}
else
{
optionsBuilder.UseOracle(connect);
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Linq;
using NUnit.Framework;
using Microsoft.Extensions.DependencyInjection;
using OpenAuth.Repository.Domain;
@ -99,5 +100,31 @@ namespace OpenAuth.Repository.Test
unitWork.Save();
}
[Test]
public void MultiUpdate2()
{
var unitWork = _autofacServiceProvider.GetService<IUnitWork<OpenAuthDBContext>>();
var users = unitWork.Find<User>(null).ToList();
unitWork.ExecuteWithTransaction(()=>
{
foreach (var req in users)
{
unitWork.Update<User>(u =>u.Id == req.Id, user => new User
{
Name = "user_" + DateTime.Now.ToString("yyyy_MM_dd HH:mm:ss")
});
unitWork.Update<Org>(u => u.Id == "08f41bf6-4388-4b1e-bd3e-2ff538b44b1b", u => new Org
{
CreateTime = DateTime.Now
});
}
unitWork.Save();
});
}
}
}

View File

@ -14,7 +14,7 @@
"AppSetting": {
"IdentityServerUrl": "", //IdentityServerOAuth
//"IdentityServerUrl": "http://demo.openauth.me:12796", //IdentityServerOAuth
"DbType": "MySql", //SqlServerMySql
"DbType": "MySql", //SqlServerMySqlOracle
"UploadPath": "", //
"RedisConf": "your_redis_server:6379,password=your_redis_password" //redis
}

View File

@ -8,12 +8,13 @@
"DataProtection": "temp-keys/",
"ConnectionStrings": {
"OpenAuthDBContext": "Data Source=.;Initial Catalog=OpenAuthDB;User=sa;Password=000000"
//"OpenAuthDBContext": "DATA SOURCE=192.168.0.118:1521/YUBAO;PASSWORD=000000;Validate Connection=true;PERSIST SECURITY INFO=True;USER ID=yubaolee;" //Oracle
//"OpenAuthDBContext": "server=127.0.0.1;user id=root;database=openauthdb;password=000000" //my sql
},
"AppSetting": {
"IdentityServerUrl": "", //IdentityServerOAuth
// "IdentityServerUrl": "http://localhost:12796", //IdentityServerOAuth
"DbType": "SqlServer", //SqlServerMySql
"DbType": "SqlServer", //SqlServerMySqlOracle
"UploadPath": "", //
"RedisConf": "redistest.cq-p.com.cn:8001,password=share_redis@123"
}