Browse Source

app2.0 统一身份认证2.0

西昌分支
ndbs 1 year ago
parent
commit
868608d707
7 changed files with 413 additions and 1 deletions
  1. +13
    -0
      Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj
  2. +325
    -0
      Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/SSOApi.cs
  3. +19
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionBLL.cs
  4. +5
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionEntity.cs
  5. +3
    -1
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionIBLL.cs
  6. +44
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionService.cs
  7. +4
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_FunctionType/Perm_FunctionTypeEntity.cs

+ 13
- 0
Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj View File

@@ -191,6 +191,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Bootstraper.cs" />
<Compile Include="Modules\EducationalAdministration\ArrangeExamTermApi.cs" />
<Compile Include="Modules\EducationalAdministration\ArrangeExamTermNewApi.cs" />
<Compile Include="Modules\SSOApi.cs" />
<Compile Include="Modules\StampPersonalApi.cs" />
<Compile Include="Modules\FundsApplyApi.cs" />
<Compile Include="Modules\AnnexesApiWx.cs" />
<Compile Include="Modules\ReceiveSendFeeManagement\FinaChargeStuYearApi.cs" />
<Compile Include="Modules\EducationalAdministration\AddressBookApi.cs" />
@@ -324,6 +329,14 @@
<Project>{88d8e99d-df26-4506-83c5-51e354818bef}</Project>
<Name>Learun.Application.WorkFlow</Name>
</ProjectReference>
<ProjectReference Include="..\Learun.Framework.Module\Learun.Cache\Learun.Cache.Base\Learun.Cache.Base.csproj">
<Project>{975F2CB8-605C-4ADD-B365-B97BF844F0FE}</Project>
<Name>Learun.Cache.Base</Name>
</ProjectReference>
<ProjectReference Include="..\Learun.Framework.Module\Learun.Cache\Learun.Cache.Factory\Learun.Cache.Factory.csproj">
<Project>{68902FCF-C439-4010-B17B-2499C972EE33}</Project>
<Name>Learun.Cache.Factory</Name>
</ProjectReference>
<ProjectReference Include="..\Learun.Framework.Module\Learun.Db\Learun.DataBase.EF.Oracle\Learun.DataBase.Oracle.csproj">
<Project>{82069f3a-ab45-4f8b-b2bf-a36b14208f41}</Project>
<Name>Learun.DataBase.Oracle</Name>


+ 325
- 0
Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/SSOApi.cs View File

@@ -0,0 +1,325 @@
using Learun.Application.AppMagager;
using Learun.Util;
using Nancy;
using System.Collections.Generic;
using System.Linq;
using Learun.Application.Base.SystemModule;
using Learun.Application.TwoDevelopment.LR_Desktop;
using System.Text;
using System.Data;
using Learun.Application.OA;
using System.Configuration;
using Learun.Application.TwoDevelopment.Permission;
using System;
using Learun.Cache.Factory;
using Learun.Cache.Base;

namespace Learun.Application.WebApi.Modules
{

public class SSOApi : BaseApi
{
private Perm_FunctionIBLL perm_FunctionIBLL = new Perm_FunctionBLL();
private Perm_FunctionTypeIBLL perm_FunctionTypeIBLL = new Perm_FunctionTypeBLL();
Perm_UserPermissionIBLL permUserPermissionIbll = new Perm_UserPermissionBLL();
private Perm_FunctionVisitIBLL functionVisitIbll = new Perm_FunctionVisitBLL();
private ICache cache = CacheFactory.CaChe();

public SSOApi()
: base("/quanjiang/sso")
{
Get["/list"] = GetList;
Get["/list20"] = GetList20;
Get["/goto"] = GoTo;
Get["/goto20"] = GoToApplication;
Get["first"] = First;
Post["first"] = FirstPost;
Get["authorize"] = Authorize;
}

/// <summary>
/// 统一身份认证2.0
/// </summary>
/// <param name="_"></param>
/// <returns></returns>
public Response Authorize(dynamic _)
{
string appid = Request.Query["appid"];
string secret = Request.Query["secret"];
string appkey = Request.Query["appkey"];
if (string.IsNullOrEmpty(appid))
{
return Fail("参数:appid不能为空");
}
if (string.IsNullOrEmpty(secret))
{
return Fail("参数:secret不能为空");
}
if (string.IsNullOrEmpty(appkey))
{
return Fail("参数:appkey不能为空");
}
var application = perm_FunctionIBLL.GetPerm_FunctionEntity(appid);
if (application != null)
{
if (Util.DESEncrypt.Decrypt(application.FSecret,
ConfigurationManager.AppSettings["SSOPublicSecret"]).Equals(secret))
{
try
{
var code = DESEncrypt.Decrypt(appkey, "bjqjsso");

if (!string.IsNullOrEmpty(cache.Read<string>(code)))
{
return Success(new { useraccount = cache.Read<string>(code) });
}
else
{
return Fail("appkey已过期");
}
}
catch (Exception e)
{
return Fail("appkey错误");
}
}
else
{
return Fail("secret错误");
}
}
else
return Fail("未授权的appid");
}

private Response FirstPost(dynamic _)
{
string publickey = ConfigurationManager.AppSettings["SSOPublicSecret"];
var ssoparam = this.GetReqData<SSOParam>();
if (!string.IsNullOrEmpty(ssoparam.UPId))
{
Perm_FunctionEntity up = new Perm_FunctionEntity();
up.UPUserName = ssoparam.UPUserName;
up.UPPass = ssoparam.UPPass;
up.FId = ssoparam.FId;
up.UserId = ssoparam.UserId;
perm_FunctionIBLL.SaveEntityByUPId(ssoparam.UPId, up);
return Success(new { FInterfaceUrl = "/SSO/GoTo?sysid=" + DESEncrypt.Encrypt(up.FId, publickey) + "&openid=" + DESEncrypt.Encrypt(up.UserId, publickey) });
}
else
{
return Fail("参数错误");
}
}

private Response First(dynamic _)
{
string publickey = ConfigurationManager.AppSettings["SSOPublicSecret"];
var ssoparam = this.GetReqData<SSOParam>();
string sysid = ssoparam.sysid;
string strsysid = DESEncrypt.Decrypt(sysid, publickey);
string openid = ssoparam.openid;
string userid = DESEncrypt.Decrypt(openid, publickey);
var uplist = permUserPermissionIbll.GetPerm_UserPermissionEntityByFIdAndUid(strsysid, userid);
if (uplist == null)
{
return Fail("用户未授权。");
}
var perfun = perm_FunctionIBLL.GetPerm_FunctionEntityByUPId(uplist.UPId);
return Success(perfun);
}

public class SSOParam
{
public string sysid { get; set; }
public string openid { get; set; }
public string UPId { get; set; }
public string FId { get; set; }
public string UserId { get; set; }
public string UPUserName { get; set; }
public string UPPass { get; set; }
public string appid { get; set; }
}

public Response GoToApplication(dynamic _)
{
var userinfo = userInfo;
var ssoparam = this.GetReqData<SSOParam>();
if (userinfo != null)
{
var perm_application = perm_FunctionIBLL.GetPerm_FunctionEntity(ssoparam.appid);
if (perm_application != null)
{
//写入当前请求所登录的用户
var code = Util.CommonHelper.RndNum(9);
cache.Write(code, userinfo.account, TimeSpan.FromMinutes(10));
var url = perm_application.FInterfaceUrl;
if (url.Contains("?"))
{
url += "&appkey=" + DESEncrypt.Encrypt(code, "bjqjsso");
}
else
{
url += "?appkey=" + DESEncrypt.Encrypt(code, "bjqjsso");
}
return Success(new{ FInterfaceUrl=url });
}
else
return Fail("appid解析失败,请确认。");
}
else
{
return Fail("用户信息解析失败,请确认。");
}
}

public Response GoTo(dynamic _)
{
try
{
var ssoparam = this.GetReqData<SSOParam>();
string publickey = ConfigurationManager.AppSettings["SSOPublicSecret"];
string sysid = ssoparam.sysid;
string strsysid = DESEncrypt.Decrypt(sysid, publickey);
string openid = ssoparam.openid;
string userid = DESEncrypt.Decrypt(openid, publickey);
var uplist = permUserPermissionIbll.GetPerm_UserPermissionEntityByFIdAndUid(strsysid, userid);
Perm_FunctionVisitEntity functionVisitEntity = new Perm_FunctionVisitEntity();
functionVisitEntity.Create();
functionVisitEntity.Fid = strsysid;
functionVisitEntity.PDate = DateTime.Now;
functionVisitEntity.PUId = userid;
var userinfo = userInfo;
functionVisitEntity.PUName = userinfo.realName;
if (uplist == null)
{
functionVisitEntity.PIsLoginSuccess = false;
functionVisitEntity.PContent = "用户未授权";
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Fail("用户未授权。");
}

var perfun = perm_FunctionIBLL.GetPerm_FunctionEntityByUPId(uplist.UPId);
string secretkey = DESEncrypt.Decrypt(perfun.FSecret, publickey);
if (perfun.FIsManagePage == true)
{
if (!string.IsNullOrEmpty(perfun.FInterfaceUrl))
{
if (!string.IsNullOrEmpty(perfun.UPUserName) && !string.IsNullOrEmpty(perfun.UPPass))
{
functionVisitEntity.PIsLoginSuccess = true;
functionVisitEntity.PContent = "成功转到统一认证网站:" + perfun.FUrl;
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Success(new
{
FInterfaceUrl = perfun.FInterfaceUrl + "?u=" +
DESEncrypt.Encrypt(DESEncrypt.Encrypt(perfun.UPUserName, secretkey),
publickey) + "&p=" +
DESEncrypt.Encrypt(DESEncrypt.Encrypt(perfun.UPPass, secretkey),
publickey) + "&t=" +
DESEncrypt.Encrypt(
DESEncrypt.Encrypt(DateTime.Now.ToString("yyyyMMddHHmmss"), secretkey),
publickey) + "&ip=" +
DESEncrypt.Encrypt(DESEncrypt.Encrypt(GetIP(), secretkey), publickey)
});
}
else
{
functionVisitEntity.PIsLoginSuccess = false;
functionVisitEntity.PContent = "用户未配置转到用户名密码配置页面";
functionVisitIbll.SaveEntity(null, functionVisitEntity);
//用户未配置转到用户名密码配置页面
return Success(new { FInterfaceUrl = "/SSO/FirstLogin?sysid=" + sysid + "&openid=" + openid });
}
}
else
{
functionVisitEntity.PIsLoginSuccess = false;
functionVisitEntity.PContent = "未配置登录接口地址";
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Fail("未配置登录接口地址。");
}
}
else
{
if (!string.IsNullOrEmpty(perfun.FUrl))
{
functionVisitEntity.PIsLoginSuccess = true;
functionVisitEntity.PContent = "成功转到统一认证网站:" + perfun.FUrl;
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Success(new { FInterfaceUrl = perfun.FUrl });
}
else
{
functionVisitEntity.PIsLoginSuccess = false;
functionVisitEntity.PContent = "未配置地址";
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Fail("未配置地址。");
}
}
}
catch (Exception e)
{
return Fail("参数错误。");
}
}

public Response GetList20(dynamic _)
{
var userinfo = userInfo;
var functionlist = perm_FunctionIBLL.GetListByUserId(userinfo.userId).Where(m=>m.FIsH5==true).Select(m=>
new
{
m.FName,
m.FId,
});
return Success(functionlist);
}


/// <summary>
/// 获取页面显示列表数据
/// <summary>
/// <param name="_"></param>
/// <returns></returns>
public Response GetList(dynamic _)
{
string publickey = ConfigurationManager.AppSettings["SSOPublicSecret"];
var logininfo = userInfo;
var datatype = perm_FunctionTypeIBLL.GetListByUserId(userInfo.userId);
foreach (var typeEntity in datatype)
{
var datafunction = perm_FunctionIBLL.GetListByFTId(typeEntity.FTId, userInfo.userId).Where(m=>m.FIsH5==true);
foreach (var item in datafunction)
{
if (item.FIsManagePage == true)
{
item.FInterfaceUrl = "/SSO/GoTo?sysid=" + DESEncrypt.Encrypt(item.FId, publickey) + "&openid=" + DESEncrypt.Encrypt(logininfo.userId, publickey);
}
else
{
item.FInterfaceUrl = item.FUrl;
}
item.FUrl = null;
}
typeEntity.PermFunction = datafunction.ToList();
}
return Success(datatype);
}
/// <summary>
/// 获取IP
/// </summary>
/// <returns></returns>
private string GetIP()
{
string ip = string.Empty;
if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"]))
ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
if (string.IsNullOrEmpty(ip))
ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
return ip;
}
}


}

+ 19
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionBLL.cs View File

@@ -184,6 +184,25 @@ namespace Learun.Application.TwoDevelopment.Permission
}
}

public IEnumerable<Perm_FunctionEntity> GetListByFTId(string typeEntityFtId, string userId)
{
try
{
return perm_FunctionService.GetListByFTId(typeEntityFtId, userId);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}

#endregion

}


+ 5
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionEntity.cs View File

@@ -62,6 +62,11 @@ namespace Learun.Application.TwoDevelopment.Permission
[Column("FISMANAGEPAGE")]
public bool? FIsManagePage { get; set; }
/// <summary>
/// 是否手机端
/// </summary>
[Column("FISH5")]
public bool? FIsH5 { get; set; }
/// <summary>
/// FEnabled
/// </summary>
[Column("FENABLED")]


+ 3
- 1
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionIBLL.cs View File

@@ -1,4 +1,5 @@
using Learun.Util;
using System.Collections;
using Learun.Util;
using System.Data;
using System.Collections.Generic;

@@ -49,5 +50,6 @@ namespace Learun.Application.TwoDevelopment.Permission
#endregion

void SaveEntityByUPId(string keyValue, Perm_FunctionEntity entity);
IEnumerable<Perm_FunctionEntity> GetListByFTId(string typeEntityFtId, string userId);
}
}

+ 44
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionService.cs View File

@@ -67,6 +67,11 @@ namespace Learun.Application.TwoDevelopment.Permission
dp.Add("FTId", "" + queryParam["FTId"].ToString() + "", DbType.String);
strSql.Append(" AND t.FTId=@FTId ");
}
if (!queryParam["FIsH5"].IsEmpty())
{
dp.Add("FIsH5", "" + queryParam["FIsH5"].ToString() + "", DbType.Int32);
strSql.Append(" AND t.FIsH5=@FIsH5 ");
}
return this.BaseRepository().FindList<Perm_FunctionEntity>(strSql.ToString(), dp, pagination);
}
catch (Exception ex)
@@ -228,5 +233,44 @@ namespace Learun.Application.TwoDevelopment.Permission

#endregion

public IEnumerable<Perm_FunctionEntity> GetListByFTId(string typeEntityFtId,string userId)
{
try
{
// 虚拟参数
var dp = new DynamicParameters(new { });
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(@"
t.FId,
t.FName,
t.FTId,
t.FUrl,t.FInterfaceUrl,t.FSecret,
t.FOrder,
t.FEnabled,t.FIsManagePage
");
strSql.Append(",b.UPUserName,b.UPPass,b.UPId ");
strSql.Append(" FROM Perm_Function t ");
strSql.Append(" right join Perm_UserPermission b on b.fid=t.fid ");
strSql.Append(" WHERE 1=1 ");
strSql.Append(" and b.UserId=@UserId ");
dp.Add("UserId", "" + userId + "", DbType.String);
strSql.Append(" AND t.FTId=@FTId ");
dp.Add("FTId", "" + typeEntityFtId + "", DbType.String);
return this.BaseRepository().FindList<Perm_FunctionEntity>(strSql.ToString(), dp);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
}
}

+ 4
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_FunctionType/Perm_FunctionTypeEntity.cs View File

@@ -1,5 +1,6 @@
using Learun.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace Learun.Application.TwoDevelopment.Permission
@@ -64,6 +65,9 @@ namespace Learun.Application.TwoDevelopment.Permission
}
#endregion
#region 扩展字段

[NotMapped] public List<Perm_FunctionEntity> PermFunction { get; set; }

#endregion
}
}


Loading…
Cancel
Save