项目需求:开发系统A 对接客户公司的cas 认证系统 B,实现单点登录
业务场景描述:打开A 系统地址,判断Cookie 是否登录状态,如果未登录,跳转B登录界面;如果已登录,直接获取到cookie 的当前登录用户信息,进入B系统
(同时满足:其他接入cas 认证的 系统实现sso)
引入Cas 插件dotnetCasClient
按照下述配置
<configuration> <configSections> <!--定义casClientConfig--> <section name="casClientConfig" type="DotNetCasClient.Configuration.CasClientConfiguration, DotNetCasClient" /> </configSections> </configuration>
casServerLoginUrl cas 系统地址
casServerUrlPrefix cas 系统前缀
serverName A 系统地址
<configuration>
<casClientConfig casServerLoginUrl="http://XXX/cas/login"
casServerUrlPrefix="http://XXX/cas/"
serverName="http://test/login.aspx" 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>
WEB_ASPXAUTH cas 插件获取到的cookie
A 系统进入页逻辑代码
if (HttpHelper.GetCookie("WEB_ASPXAUTH") != null && BasePage.GlobalInfo.UserInfo.UserID > 0)
Response.Redirect(base.BasePage.CorrectUrl("~/SiteMain.aspx"));
//cas登录跳到这里,成功认证cooking,失败返回login.aspx
try
{
if (CasAuthentication.ServiceTicketManager != null)
{
HttpCookie ticketCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (ticketCookie != null)
{
SSOInfoBll infoBLL = new SSOInfoBll();
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(ticketCookie.Value);
if (ticket != null)
{
CasAuthenticationTicket casTicket = CasAuthentication.ServiceTicketManager.GetTicket(ticket.UserData);
if (casTicket != null)
{
EmpCode = casTicket.Assertion.PrincipalName;
}
}
}
}
}
标签:登录,Cas,系统,认证,cas,Cookie,NET,null,aspx From: https://www.cnblogs.com/jayblog/p/17098741.html