原理:客户访问我的超链接,传来一个key值,我通过这个key‘值去客户的esb系统去验证,若验证成功,返回用户信息,我拿到用户信息,跟本地服务器的用户信息进行比对,若一致,跳过登陆页面,直接授权进入系统。客户是内网,域名又有限制,访问不到接口,只能进行远程调试;因为获取用户用的是soap协议,所以还需要生成wsdl文件的代理类。
主要代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Security.Cryptography;
using TechExcel.Project.DataAccess;
using TechExcel.Project.DataAccess.Service;
using TechExcel.Project.DataAccess.Utility;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.IO;
using System.Xml;
using TechExcel.PPM.ProjectWeb.WebServiceEastHope;
namespace TechExcel.PPM.ProjectWeb
{
public partial class SSOLogin4EastHope : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CookieContainer cookieContainer = new CookieContainer();
string url = ConfigurationManager.AppSettings.Get("EastHopeEsbUrl");//esb接口的url
string strUser= string.Empty;//用户信息
string token = string.Empty;//key值
string iPlanetDirectoryProVal = string.Empty;//
int timeout = 0;
string userAgent = string.Empty;
string strLang = string.Empty;
int nLangID = 0;
int.TryParse(strLang, out nLangID);
string strRuntimeKey = string.Empty;
if (Request.Cookies == null)
{
Response.Write("cookie is null");
//Response.Redirect("login.aspx");
return;
}
if (HttpContext.Current.Request.Cookies["tokenID"] != null)
{
iPlanetDirectoryProVal = HttpContext.Current.Request.Cookies["tokenID"].Value;
}
if (HttpContext.Current.Request.Cookies["iPlanetDirectoryPro"] != null)
{
string tokenTemp = HttpContext.Current.Request.Cookies["iPlanetDirectoryPro"].Value;
Response.Write("iPlanetDirectoryPro is not null " + tokenTemp);
string xmlToken=GetXml(tokenTemp);
//拿到cookies的key值并且生成xml数据的格式之后,到ESB系统获取用户信息
//Cookie cookie = new Cookie("tokenID", tokenTemp);
//HttpHelper httpR = new HttpHelper();
//HttpWebResponse re = httpR.CreateGetHttpResponse(url, timeout, userAgent, cookie,xmlToken);
AuthenticationWSClient authticayion=new AuthenticationWSClient();
string xmlIn=authticayion.getTokenUser(xmlToken);
if (xmlIn != null)
{
//string xmlIn = new StreamReader(re.GetResponseStream(), Encoding.UTF8).ReadToEnd();
strUser = getXmlUser(xmlIn);
Response.Write("xmlIn is not null " + xmlToken + " xmlIn:"+xmlIn+" strUser:"+strUser);
if (strUser != null)
{
if (SSOAuthentication(nLangID, strRuntimeKey, strUser))
return;
}
}
else
&nb