Browse Source

CAS统一认证对接

和田中职
王晓寒 1 month ago
parent
commit
06bba960ad
20 changed files with 11077 additions and 101 deletions
  1. +189
    -92
      Learun.Framework.Ultimate V7/Learun.Application.Web/Controllers/LoginController.cs
  2. +4
    -4
      Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj
  3. +3
    -3
      Learun.Framework.Ultimate V7/Learun.Application.Web/Properties/PublishProfiles/FolderProfile1.pubxml
  4. +14
    -2
      Learun.Framework.Ultimate V7/Learun.Application.Web/Web.config
  5. +1
    -0
      Learun.Framework.Ultimate V7/Learun.Application.Web/packages.config
  6. +2
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Learun.Util.csproj
  7. +299
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Log/LogHelper.cs
  8. BIN
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/.signature.p7s
  9. BIN
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/DotNetCasClient.1.3.2.nupkg
  10. +77
    -0
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/content/web.config.install.xdt
  11. +4
    -0
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/content/web.config.transform
  12. +34
    -0
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/content/web.config.uninstall.xdt
  13. BIN
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net20/DotNetCasClient.dll
  14. +2584
    -0
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net20/DotNetCasClient.xml
  15. BIN
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net35/DotNetCasClient.dll
  16. +2584
    -0
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net35/DotNetCasClient.xml
  17. BIN
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net40/DotNetCasClient.dll
  18. +2641
    -0
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net40/DotNetCasClient.xml
  19. BIN
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net45/DotNetCasClient.dll
  20. +2641
    -0
      Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net45/DotNetCasClient.xml

+ 189
- 92
Learun.Framework.Ultimate V7/Learun.Application.Web/Controllers/LoginController.cs View File

@@ -24,6 +24,8 @@ using System.Collections.Generic;
using Learun.Cache.Redis;
using Learun.Application.TwoDevelopment.PersonnelManagement;
using Learun.Application.TwoDevelopment.Permission;
using DotNetCasClient;
using DotNetCasClient.Configuration;

namespace Learun.Application.Web.Controllers
{
@@ -193,104 +195,185 @@ namespace Learun.Application.Web.Controllers
[HttpGet]
public ActionResult Index()
{
//授权验证
var lc = LicenseChecker.CheckLicense();
if (!lc.Result)
{
return Content("<script>alert('" + lc.Message + "');location.href='about:blank';</script>");
}
//获取错误次数
ViewBag.errornum = OperatorHelper.Instance.GetCurrentErrorNum();
//获取初始密码设置中已启用的密码
ViewBag.IsSetDefaultPwd = false;
ViewBag.DefaultPwd = "";
var defaultPwdEntity = sys_DefaultPwdConfigIBLL.GetEnabledEntity();
if (defaultPwdEntity != null)
#region CAS

if (User.Identity.IsAuthenticated)
{
ViewBag.IsSetDefaultPwd = true;
ViewBag.DefaultPwd = defaultPwdEntity.Pwd;
string uid = User.Identity.Name; // 获取用户ID
if (!string.IsNullOrEmpty(uid))
{
UserEntity userEntity = userBll.GetEntityByAccount(uid);
if (userEntity != null)
{
#region 写入日志
LogEntity logEntity = new LogEntity();
logEntity.F_CategoryId = 1;
logEntity.F_OperateTypeId = ((int)OperationType.Login).ToString();
logEntity.F_OperateType = "CAS登录";
logEntity.F_OperateAccount = uid + "(" + userEntity.F_RealName + ")";
logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : uid;
logEntity.F_Module = Config.GetValue("SoftName");
logEntity.F_Description = "PC端";
#endregion
OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_PC", null);//写入缓存信息
//写入日志
logEntity.F_ExecuteResult = 1;
logEntity.F_ExecuteResultJson = "登录成功";
logEntity.WriteLog();
OperatorHelper.Instance.ClearCurrentErrorNum();
return Redirect("/Home/Index");
}
else
return Fail("系统无此用户,请先同步用户数据!");
}
}
//获取高职版跳转地址
ViewBag.DigitalschoolMisLoginurl = ConfigurationManager.AppSettings["DigitalschoolMisLoginurl"];
//ViewBag.Returnurl = "http://" + Request.Url.Host + ":" + Request.Url.Port;
CasAuthentication.RedirectToLoginPage();
//LogHelper.WriteToLog("cas登录", $"无登录信息{Request.UrlReferrer}");
//LogHelper.WriteToLog("cas登录", $"信息{User.Identity.Name}");
//LogHelper.WriteToLog("CasReauest",Request.QueryString.Get("ticket"));
//LogHelper.WriteToLog("CasParams", JsonConvert.SerializeObject(Request.Params.GetValues("AUTH_USER")));
//if (User.Identity.IsAuthenticated)
//{
// string uid = User.Identity.Name; // 获取用户ID
// LogHelper.WriteToLog("cas登录", uid);
// if (!string.IsNullOrEmpty(uid))
// {
// UserEntity userEntity = userBll.GetEntityByAccount(uid);
// if (userEntity != null)
// {
// #region 写入日志
// LogEntity logEntity = new LogEntity();
// logEntity.F_CategoryId = 1;
// logEntity.F_OperateTypeId = ((int)OperationType.Login).ToString();
// logEntity.F_OperateType = "CAS登录";
// logEntity.F_OperateAccount = uid + "(" + userEntity.F_RealName + ")";
// logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : uid;
// logEntity.F_Module = Config.GetValue("SoftName");
// logEntity.F_Description = "PC端";
// #endregion
// OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_PC", null);//写入缓存信息
// //写入日志
// logEntity.F_ExecuteResult = 1;
// logEntity.F_ExecuteResultJson = "登录成功";
// logEntity.WriteLog();
// OperatorHelper.Instance.ClearCurrentErrorNum();
// return Redirect("/Home/Index");
// }
// else
// return Fail("系统无此用户,请先同步用户数据!");
// }
// return Fail("userinfo is null");
//}

//// 获取当前请求的 URL,以便登录后可以重定向回来
//string currentUrl = Request.Url.ToString();
//// 创建登录页面 URL,这里将原始回调 URL 作为参数传递
//string loginUrl = $"{CasClientConfiguration.Config.CasServerLoginUrl}?service={HttpUtility.UrlEncode(currentUrl)}";
////Response.Redirect(loginUrl);
//return Redirect(loginUrl);
#endregion

//string ticket = Request.QueryString["ticket"];
//string serviceUrl = DotNetCasClient.Configuration.CasClientConfiguration.CAS_SERVER_LOGIN_URL;

if (!Request.QueryString["Returnurl"].IsEmpty())
{
ViewBag.Returnurl = Request.QueryString["Returnurl"];
};
if (!Request.QueryString["appid"].IsEmpty())
{
ViewBag.appid = Request.QueryString["appid"].ToString();
};
////授权验证
//var lc = LicenseChecker.CheckLicense();
//if (!lc.Result)
//{
// return Content("<script>alert('" + lc.Message + "');location.href='about:blank';</script>");
//}
////获取错误次数
//ViewBag.errornum = OperatorHelper.Instance.GetCurrentErrorNum();
////获取初始密码设置中已启用的密码
//ViewBag.IsSetDefaultPwd = false;
//ViewBag.DefaultPwd = "";
//var defaultPwdEntity = sys_DefaultPwdConfigIBLL.GetEnabledEntity();
//if (defaultPwdEntity != null)
//{
// ViewBag.IsSetDefaultPwd = true;
// ViewBag.DefaultPwd = defaultPwdEntity.Pwd;
//}
////获取高职版跳转地址
//ViewBag.DigitalschoolMisLoginurl = ConfigurationManager.AppSettings["DigitalschoolMisLoginurl"];
////ViewBag.Returnurl = "http://" + Request.Url.Host + ":" + Request.Url.Port;

//获取登录页二维码配置信息
ViewBag.HasQRCode = false;
var qrcodelist = sys_QRCodeInLoginIBLL.GetList().ToList().Where(x => x.EnabledMark == 1).OrderByDescending(x => x.CreateTime);
if (qrcodelist.Any())
{
ViewBag.HasQRCode = true;
ViewBag.QRCodeUrl = qrcodelist.FirstOrDefault().QRCodeUrl;
ViewBag.QRCodeText = qrcodelist.FirstOrDefault().Title;
ViewBag.Title = qrcodelist.FirstOrDefault().Title;
}

//获取登录页面版本号
ViewBag.Version = false;
var versionlist = sys_UpdateRecordIBLL.GetList().OrderByDescending(x => x.UpdateTime);
if (versionlist.Any())
{
ViewBag.Version = true;
ViewBag.VersionNum = versionlist.FirstOrDefault().VersionNum;
ViewBag.VersionList = JsonConvert.SerializeObject(versionlist);
}

var result = teachSwitchIBLL.FindFirst("js");
ViewBag.TeachSwitch = result;
var result2 = teachSwitchIBLL.FindFirst("fx");
ViewBag.FeiXinSwitch = result2;
//网上办事大厅
var result3 = teachSwitchIBLL.FindFirst("ssosystem");
ViewBag.SSOSystemSwitch = result3;
//微信快捷登录
var result4 = teachSwitchIBLL.FindFirst("wxloginforpc");
ViewBag.WeixinLoginSwitch = result4;
//访客注册
var result5 = teachSwitchIBLL.FindFirst("fk");
ViewBag.VisitorSwitch = result5;
//获取在线用户人数
ViewBag.OnlineUserNum = 0;
var onlineUserResult = sys_UpdateRecordIBLL.GetOnlineUserNum();
if (onlineUserResult != null)
{
ViewBag.OnlineUserNum = onlineUserResult.OnlineUserNum;
}
//获取本机ip
ViewBag.Ip = GetIP();
ViewBag.ACIp = ConfigurationManager.AppSettings["ACIp"] ?? "";
ViewBag.ACIp2 = ConfigurationManager.AppSettings["ACIp2"] ?? "";
//获取登录页风格
var pageEntity = loginModelIbll.FindEnablePage();
if (string.IsNullOrEmpty(pageEntity?.Name))
{
ViewBag.LoGo = "/Content/images/logins/login4.png";
return View("Default");
}
else
{
var logoUrl = annexesFileIbll.GetEntityByFolderId(pageEntity.Logo)?.F_FilePath;
if (string.IsNullOrEmpty(logoUrl))
{
logoUrl = "/Content/images/logins/login4.png";
ViewBag.LoGo = logoUrl;
}
else
{
ViewBag.LoGo = "/" + logoUrl.Substring(logoUrl.IndexOf("Resource"));
}
return View(pageEntity.Name);
}
//if (!Request.QueryString["Returnurl"].IsEmpty())
//{
// ViewBag.Returnurl = Request.QueryString["Returnurl"];
//};
//if (!Request.QueryString["appid"].IsEmpty())
//{
// ViewBag.appid = Request.QueryString["appid"].ToString();
//};

////获取登录页二维码配置信息
//ViewBag.HasQRCode = false;
//var qrcodelist = sys_QRCodeInLoginIBLL.GetList().ToList().Where(x => x.EnabledMark == 1).OrderByDescending(x => x.CreateTime);
//if (qrcodelist.Any())
//{
// ViewBag.HasQRCode = true;
// ViewBag.QRCodeUrl = qrcodelist.FirstOrDefault().QRCodeUrl;
// ViewBag.QRCodeText = qrcodelist.FirstOrDefault().Title;
// ViewBag.Title = qrcodelist.FirstOrDefault().Title;
//}

////获取登录页面版本号
//ViewBag.Version = false;
//var versionlist = sys_UpdateRecordIBLL.GetList().OrderByDescending(x => x.UpdateTime);
//if (versionlist.Any())
//{
// ViewBag.Version = true;
// ViewBag.VersionNum = versionlist.FirstOrDefault().VersionNum;
// ViewBag.VersionList = JsonConvert.SerializeObject(versionlist);
//}

//var result = teachSwitchIBLL.FindFirst("js");
//ViewBag.TeachSwitch = result;
//var result2 = teachSwitchIBLL.FindFirst("fx");
//ViewBag.FeiXinSwitch = result2;
////网上办事大厅
//var result3 = teachSwitchIBLL.FindFirst("ssosystem");
//ViewBag.SSOSystemSwitch = result3;
////微信快捷登录
//var result4 = teachSwitchIBLL.FindFirst("wxloginforpc");
//ViewBag.WeixinLoginSwitch = result4;
////访客注册
//var result5 = teachSwitchIBLL.FindFirst("fk");
//ViewBag.VisitorSwitch = result5;
////获取在线用户人数
//ViewBag.OnlineUserNum = 0;
//var onlineUserResult = sys_UpdateRecordIBLL.GetOnlineUserNum();
//if (onlineUserResult != null)
//{
// ViewBag.OnlineUserNum = onlineUserResult.OnlineUserNum;
//}
////获取本机ip
//ViewBag.Ip = GetIP();
//ViewBag.ACIp = ConfigurationManager.AppSettings["ACIp"] ?? "";
//ViewBag.ACIp2 = ConfigurationManager.AppSettings["ACIp2"] ?? "";
////获取登录页风格
//var pageEntity = loginModelIbll.FindEnablePage();
//if (string.IsNullOrEmpty(pageEntity?.Name))
//{
// ViewBag.LoGo = "/Content/images/logins/login4.png";
// return View("Default");
//}
//else
//{
// var logoUrl = annexesFileIbll.GetEntityByFolderId(pageEntity.Logo)?.F_FilePath;
// if (string.IsNullOrEmpty(logoUrl))
// {
// logoUrl = "/Content/images/logins/login4.png";
// ViewBag.LoGo = logoUrl;
// }
// else
// {
// ViewBag.LoGo = "/" + logoUrl.Substring(logoUrl.IndexOf("Resource"));
// }
// return View(pageEntity.Name);
//}

//string learn_UItheme = WebHelper.GetCookie("Learn_ADMS_V6.1_UItheme");
//switch (learn_UItheme)
@@ -306,6 +389,7 @@ namespace Learun.Application.Web.Controllers
// default:
// return View("Default"); // 经典版本
//}
return Fail("userinfo is null");
}

[HttpGet]
@@ -558,9 +642,22 @@ namespace Learun.Application.Web.Controllers
Session.Abandon(); //清除当前会话
Session.Clear(); //清除当前浏览器所有Session
OperatorHelper.Instance.EmptyCurrent();
return Success("退出系统");
}

if (CasAuthentication.ServiceTicketManager != null)
{
CasAuthentication.ClearAuthCookie();
Session.Clear();
}
var singleSignOutRedirectUrl = $"{CasClientConfiguration.Config.CasServerUrlPrefix}logout?service={HttpUtility.UrlEncode(CasClientConfiguration.Config.ServerName+ "/Login/Index")}";
//HttpGet(singleSignOutRedirectUrl);
return Success(singleSignOutRedirectUrl);
//Response.Redirect(singleSignOutRedirectUrl, true);
}
[Authorize]
public ActionResult CookiesRequired()
{
return View();
}
/// <summary>
/// 登录验证
/// </summary>


+ 4
- 4
Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj View File

@@ -23,7 +23,7 @@
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<UseGlobalApplicationHostFile />
<Use64BitIISExpress />
<Use64BitIISExpress>false</Use64BitIISExpress>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
@@ -60,6 +60,9 @@
<Reference Include="DocumentFormat.OpenXml, Version=2.8.1.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17, processorArchitecture=MSIL">
<HintPath>..\packages\DocumentFormat.OpenXml.2.8.1\lib\net46\DocumentFormat.OpenXml.dll</HintPath>
</Reference>
<Reference Include="DotNetCasClient, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetCasClient.1.3.2\lib\net45\DotNetCasClient.dll</HintPath>
</Reference>
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
</Reference>
@@ -104,9 +107,6 @@
<Reference Include="Microsoft.Practices.Unity.RegistrationByConvention">
<HintPath>..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll</HintPath>
</Reference>
<Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
<Private>True</Private>


+ 3
- 3
Learun.Framework.Ultimate V7/Learun.Application.Web/Properties/PublishProfiles/FolderProfile1.pubxml View File

@@ -10,9 +10,9 @@
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<ExcludeApp_Data>false</ExcludeApp_Data>
<publishUrl>bin\Release\Publish</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<DeleteExistingFiles>false</DeleteExistingFiles>
</PropertyGroup>
</Project>

+ 14
- 2
Learun.Framework.Ultimate V7/Learun.Application.Web/Web.config View File

@@ -11,6 +11,8 @@
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
<section name="casClientConfig" type="DotNetCasClient.Configuration.CasClientConfiguration, DotNetCasClient" />
<section name="FilterUrls" type="DotNetCasClient.Configuration.ReWritingConfigurationSetHandler, DotNetCasClient"/>
</configSections>
<unity configSource="XmlConfig\ioc.config" />
<connectionStrings configSource="XmlConfig\database.config">
@@ -45,15 +47,24 @@
</pages>
<!--最大请求长度,单位为KB(千字节),默认为4M,设置为1G,上限为2G -->
<httpRuntime maxRequestLength="2048000" executionTimeout="3600" />
<authentication mode="Forms">
<forms loginUrl="http://authserver.htpt.edu.cn/authserver/login" timeout="30" defaultUrl="/Login/Index" cookieless="UseCookies" slidingExpiration="true" path="/" />
</authentication>
<httpModules>
<add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient" />
</httpModules>
</system.web>
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true">
<requestLimits maxAllowedContentLength="2048000000"></requestLimits>
<requestLimits maxAllowedContentLength="2048000000">
</requestLimits>
</requestFiltering>
</security>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<modules runAllManagedModulesForAllRequests="true">
<add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
@@ -190,4 +201,5 @@
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<casClientConfig casServerLoginUrl="http://authserver.htpt.edu.cn/authserver/login" casServerUrlPrefix="http://authserver.htpt.edu.cn/authserver/" serverName="http://localhost:8002" notAuthorizedUrl="~/Login/Index" cookiesRequiredUrl="/Login/CookiesRequired" redirectAfterValidation="true" gateway="false" renew="false" singleSignOut="false" ticketTimeTolerance="5000" ticketValidatorName="Cas20" proxyTicketManager="CacheProxyTicketManager" serviceTicketManager="CacheServiceTicketManager" gatewayStatusCookieName="CasGatewayStatus" />
</configuration>

+ 1
- 0
Learun.Framework.Ultimate V7/Learun.Application.Web/packages.config View File

@@ -3,6 +3,7 @@
<package id="ClosedXML" version="0.93.0" targetFramework="net45" requireReinstallation="true" />
<package id="CommonServiceLocator" version="1.3" targetFramework="net45" />
<package id="DocumentFormat.OpenXml" version="2.8.1" targetFramework="net462" />
<package id="DotNetCasClient" version="1.3.2" targetFramework="net462" />
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
<package id="ExcelNumberFormat" version="1.0.3" targetFramework="net45" />
<package id="FastMember.Signed" version="1.3.0" targetFramework="net45" />


+ 2
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Learun.Util.csproj View File

@@ -95,6 +95,7 @@
<Compile Include="DataBase\FieldTypeHepler.cs" />
<Compile Include="DataBase\FieldValueParam.cs" />
<Compile Include="DataBase\DbWhere.cs" />
<Compile Include="Log\LogHelper.cs" />
<Compile Include="Mail\Model\MailAccount .cs" />
<Compile Include="Mail\Model\MailFile.cs" />
<Compile Include="Mail\Model\MailModel.cs" />
@@ -154,6 +155,7 @@
<Analyzer Include="..\..\..\packages\Microsoft.DependencyValidation.Analyzers.0.10.0\analyzers\dotnet\cs\Microsoft.DependencyValidation.Analyzers.resources.dll" />
<Analyzer Include="..\..\..\packages\Microsoft.DependencyValidation.Analyzers.0.10.0\analyzers\dotnet\Microsoft.DependencyValidation.Analyzers.dll" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">


+ 299
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Log/LogHelper.cs View File

@@ -0,0 +1,299 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Learun.Util
{
/// <summary>
/// 日志帮助类
/// </summary>
public class LogHelper
{
/// <summary>
/// 配置文件
/// </summary>
protected static LogConfig Config = new LogConfig();

/// <summary>
/// 写日志
/// </summary>
/// <param name="isError"></param>
/// <returns></returns>
protected static StreamWriterLock GetLogWriter(bool isError = false)
{
try
{
string root = AppDomain.CurrentDomain.BaseDirectory;
DateTime now = DateTime.Now;
//日志文件路径
string folder = isError ? Config.LogErrorFolder : Config.LogInfoFolder;
folder = Path.Combine(root, folder, now.ToString(Config.LogFolderFormat));

string filePath = Path.Combine(folder, now.ToString(Config.LogFileFormat) + Config.LogFileExt);

if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
return new StreamWriterLock(filePath);
}
catch (Exception)
{
return null;
}
}

/// <summary>
/// 写日志
/// </summary>
public static void WriteToLog(string content)
{
using (var sw = GetLogWriter())
{
var writer = sw.Writer;
writer.WriteStart();
writer.WriteTime();
writer.WriteContent(content);
writer.WriteLine();
}
}

/// <summary>
/// 写日志
/// </summary>
public static void WriteToLog(string[] contents)
{
using (var sw = GetLogWriter())
{
var writer = sw.Writer;
writer.WriteStart();
writer.WriteTime();
writer.WriteContent(contents);
writer.WriteEnd();
}
}

/// <summary>
/// 写日志
/// </summary>
public static void WriteToLog(string title, string content)
{
using (var sw = GetLogWriter())
{
var writer = sw.Writer;
writer.WriteStart();
writer.WriteTitle(title);
writer.WriteTime();
writer.WriteContent(content);
writer.WriteEnd();
}
}

/// <summary>
/// 写日志(错误)
/// </summary>
public static void WriteToLog(Exception ex, string title = "", string content = "")
{
using (var sw = GetLogWriter(true))
{
var writer = sw.Writer;
writer.WriteStart();
writer.WriteTitle(title, true);
writer.WriteTime();
if (!string.IsNullOrEmpty(content))
{
writer.WriteContent(content);
}
writer.WriteException(ex);
writer.WriteEnd();
}
}
}

/// <summary>
/// 日志目录配置
/// </summary>
public class LogConfig
{
/// <summary>
/// 构造函数
/// </summary>
public LogConfig()
{
this.LogRoot = "Log";
this.LogInfoFolder = Path.Combine(this.LogRoot, "LogInfo");
this.LogErrorFolder = Path.Combine(this.LogRoot, "LogError");
this.LogFolderFormat = "yyyyMMdd";
this.LogFileFormat = "yyyyMMdd_HH";
this.LogFileExt = ".log";
}

/// <summary>
/// 日志根目录
/// </summary>
public string LogRoot { get; set; }

/// <summary>
/// 普通信息
/// </summary>
public string LogInfoFolder { get; set; }

/// <summary>
/// 错误信息
/// </summary>
public string LogErrorFolder { get; set; }

/// <summary>
/// 文件夹日期格式
/// </summary>
public string LogFolderFormat { get; set; }

/// <summary>
/// 文件日志格式
/// </summary>
public string LogFileFormat { get; set; }

/// <summary>
/// 文件后缀名
/// </summary>
public string LogFileExt { get; set; }
}

/// <summary>
/// 日志工具
/// </summary>
public static class LogTools
{
/// <summary>
/// 开始写日志
/// </summary>
/// <param name="writer"></param>
public static void WriteStart(this StreamWriter writer)
{
writer.WriteLine("-------------------------------------------------------------------------------------");
}

/// <summary>
/// 结束写
/// </summary>
/// <param name="writer"></param>
public static void WriteEnd(this StreamWriter writer)
{
//writer.WriteLine("-------------------------------------------------------------------------------------");
writer.WriteLine();
}

/// <summary>
/// 写入时间
/// </summary>
/// <param name="writer"></param>
public static void WriteTime(this StreamWriter writer)
{
writer.WriteLine("Date:{0:yyyy-MM-dd} Time:{0:HH:mm:ss}", DateTime.Now);
}

/// <summary>
/// 写入标题
/// </summary>
/// <param name="writer"></param>
/// <param name="title"></param>
/// <param name="isError"></param>
public static void WriteTitle(this StreamWriter writer, string title, bool isError = false)
{
if (isError)
{
writer.WriteLine("Title:Error!!!");
if (!string.IsNullOrEmpty(title))
{
writer.WriteLine(title);
}
}
else
{
writer.WriteLine("Title:{0}", title);
}
}

/// <summary>
/// 写入内容
/// </summary>
/// <param name="writer"></param>
/// <param name="content"></param>
public static void WriteContent(this StreamWriter writer, string content)
{
writer.WriteLine("Content:{0}", content);
}

/// <summary>
/// 写入内容
/// </summary>
/// <param name="writer"></param>
/// <param name="contents"></param>
public static void WriteContent(this StreamWriter writer, string[] contents)
{
writer.WriteLine("Content:{0}", contents.Length);
var dig = Math.Max(2, contents.Length.ToString().Length); //位数
for (int i = 0; i < contents.Length; i++)
{
writer.WriteLine("No.{0}->{1}", (i + 1).ToString().PadLeft(2, '0'), contents[i]);
}
}

/// <summary>
/// 写入异常
/// </summary>
/// <param name="writer"></param>
/// <param name="ex"></param>
public static void WriteException(this StreamWriter writer, Exception ex)
{
writer.WriteLine("Message:{0}", ex.Message);
writer.WriteLine("StackTrace:{0}", ex.StackTrace);
if (ex.InnerException != null)
{
writer.WriteLine("InnerException:");
writer.WriteLine("Message:{0}", ex.InnerException.Message);
writer.WriteLine("StackTrace:{0}", ex.InnerException.StackTrace);
}
}
}

/// <summary>
/// 文件锁
/// </summary>
public class StreamWriterLock : IDisposable
{
/// <summary>
/// 写入
/// </summary>
public StreamWriter Writer { get; protected set; }

/// <summary>
/// 构造函数
/// </summary>
/// <param name="filePath"></param>
public StreamWriterLock(string filePath)
{
Lock.EnterWriteLock();
if (!File.Exists(filePath))//如果文件不存在
{
File.Create(filePath).Close();
}
this.Writer = File.AppendText(filePath);
}

/// <summary>
/// 文件读写锁
/// </summary>
protected static ReaderWriterLockSlim Lock = new ReaderWriterLockSlim();

public void Dispose()
{
this.Writer.Dispose();
Lock.ExitWriteLock();
}
}
}

BIN
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/.signature.p7s View File


BIN
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/DotNetCasClient.1.3.2.nupkg View File


+ 77
- 0
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/content/web.config.install.xdt View File

@@ -0,0 +1,77 @@
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

<!-- Configure configSections section -->
<configSections xdt:Transform="InsertIfMissing" />
<configSections xdt:Transform="InsertBefore(/configuration/*[1])">
</configSections>

<configSections xdt:Locator="XPath(/configuration/configSections[last()])">
<section xdt:Transform="Remove" xdt:Locator="Match(name)" name="casClientConfig" />
</configSections>
<configSections xdt:Locator="XPath(/configuration/configSections[last()])">
<section xdt:Transform="Insert" name="casClientConfig" type="DotNetCasClient.Configuration.CasClientConfiguration, DotNetCasClient" />
</configSections>

<configSections xdt:Transform="RemoveAll" xdt:Locator="Condition(count(*)=0)" />

<!-- Configure system.web section -->
<system.web xdt:Transform="InsertIfMissing">
<authentication xdt:Transform="InsertIfMissing" />
<httpModules xdt:Transform="InsertIfMissing" />
</system.web>

<system.web>
<authentication xdt:Transform="SetAttributes" mode="Forms">
<forms xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" name=".DotNetCasClientAuth" loginUrl="https://cas.example.com/cas/login" cookieless="UseCookies" />
</authentication>
<httpModules>
<add xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient" />
</httpModules>
</system.web>

<!-- Configure system.webServer section -->
<system.webServer xdt:Transform="InsertIfMissing">
<validation xdt:Transform="InsertIfMissing" />
<modules xdt:Transform="InsertIfMissing" />
</system.webServer>

<system.webServer>
<modules>
<add xdt:Transform="Remove" xdt:Locator="Match(name)" name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient" />
<add xdt:Transform="Insert" xdt:Locator="Match(name)" name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient" />
</modules>
</system.webServer>

<system.webServer>
<modules>
<remove xdt:Transform="Remove" xdt:Locator="Match(name)" name="DotNetCasClient" />
<remove xdt:Transform="InsertBefore(/configuration/system.webServer/modules/add)" xdt:Locator="Match(name)" name="DotNetCasClient" />
</modules>
</system.webServer>

<system.webServer>
<validation xdt:Transform="SetAttributes" validateIntegratedModeConfiguration="false" />
</system.webServer>

<!-- Insert casClientConfig section if missing -->
<casClientConfig
xdt:Transform="InsertIfMissing"
casServerLoginUrl="https://cas.example.com/cas/login"
casServerUrlPrefix="https://cas.example.com/cas/"
serverName="cas.example.com"
notAuthorizedUrl="~/NotAuthorized.aspx"
cookiesRequiredUrl="~/CookiesRequired.aspx"
redirectAfterValidation="true"
gateway="false"
renew="false"
singleSignOut="true"
ticketTimeTolerance="5000"
ticketValidatorName="Cas20"
proxyTicketManager="CacheProxyTicketManager"
serviceTicketManager="CacheServiceTicketManager"
gatewayStatusCookieName="CasGatewayStatus" />

</configuration>

+ 4
- 0
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/content/web.config.transform View File

@@ -0,0 +1,4 @@
<configuration>
<configSections>
</configSections>
</configuration>

+ 34
- 0
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/content/web.config.uninstall.xdt View File

@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

<!-- Remove casClientConfig section from configSections section -->
<configSections>
<section xdt:Transform="Remove" xdt:Locator="Match(name)" name="casClientConfig" />
<section xdt:Transform="Insert" xdt:Locator="Match(name)" name="casClientConfig" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<configSections xdt:Transform="RemoveAll" xdt:Locator="Condition(count(*)=0)" />
<!-- Remove DotNetCasClient from system.web/httpModules -->
<system.web>
<httpModules>
<add xdt:Transform="Remove" xdt:Locator="Match(name)" name="DotNetCasClient" />
</httpModules>
</system.web>
<system.web>
<httpModules xdt:Transform="RemoveAll" xdt:Locator="Condition(count(*)=0)" />
</system.web>

<!-- Remove DotNetCasClient from system.webServer/modules -->
<system.webServer>
<modules>
<remove xdt:Transform="Remove" xdt:Locator="Match(name)" name="DotNetCasClient" />
<add xdt:Transform="Remove" xdt:Locator="Match(name)" name="DotNetCasClient" />
</modules>
</system.webServer>
<system.webServer>
<modules xdt:Transform="RemoveAll" xdt:Locator="Condition(count(*)=0)" />
</system.webServer>
</configuration>

BIN
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net20/DotNetCasClient.dll View File


+ 2584
- 0
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net20/DotNetCasClient.xml
File diff suppressed because it is too large
View File


BIN
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net35/DotNetCasClient.dll View File


+ 2584
- 0
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net35/DotNetCasClient.xml
File diff suppressed because it is too large
View File


BIN
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net40/DotNetCasClient.dll View File


+ 2641
- 0
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net40/DotNetCasClient.xml
File diff suppressed because it is too large
View File


BIN
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net45/DotNetCasClient.dll View File


+ 2641
- 0
Learun.Framework.Ultimate V7/packages/DotNetCasClient.1.3.2/lib/net45/DotNetCasClient.xml
File diff suppressed because it is too large
View File


Loading…
Cancel
Save