<
html
>
<
header
>
<%
@ Language
=
JScript
%>
<%
/** */
/**
*说明:统一认证代理插件程序
*系统必须安装msxml4.0
*
*/
//
统一认证服务器url
//
var CAS_Server = "
https://localhost
:8443/cas/";
var CAS_Server
=
"
https://localhost:8443/cas/
"
;
//
当前系统url
var MyServer
=
"
http://localhost
"
;
//
门户url的数组
var portal_server
=
new
Array(
"
http://localhost:8080
"
,
"
http://127.0.0.1
"
);
//
控制是否允许本地登录
var isAllowLocalLogin
=
true
;
//
portal引导开通Url
var openServiceUrl
=
""
;
var queryString
=
getQueryString(Request.ServerVariables(
"
QUERY_STRING
"
));
//
当前网页url
var originatingURL
=
MyServer
+
Request.ServerVariables(
"
URL
"
)
+
queryString;
//
只在没登录的情况下涉及转发
if
(
!
isLogon())
{
var ticket
=
Request.QueryString.Item(
"
ticket
"
).Item;
//
没有ticket
if
(
!
ticket)
{
//
转发标志,为true时转向cas服务器做单点登录
var redirectFlag
=
false
;
//
如果不允许本地登录
if
(isAllowLocalLogin
==
false
)
{
redirectFlag
=
true
;
}
else
{
var refer
=
Request.ServerVariables(
"
HTTP_REFERER
"
);
if
(
!
refer)refer
=
""
;
refer
=
new
String(refer);
//
若Sessoin中未设置Referer
if
(
!
Session(
"
Referer
"
))
{
//
如果是从portal链到本站,那么转发,并置Session("refer")
for
(var i
=
0
;i
<
portal_server.length;i
++
)
{
if
(refer.indexOf(portal_server[i])
==
0
)
{
Session(
"
Referer
"
)
=
refer;
redirectFlag
=
true
;
}
}
}
else
{
redirectFlag
=
true
;
}
}
//
转到cas进行验证
if
(redirectFlag)
{
Response.Redirect(CAS_Server
+
"
login?service=
"
+
originatingURL);
Response.End;
}
}
else
{
//
有ticket,转cas验证ticket并取userid
//
setOption("SXH_OPTION_SELECT_CLIENT_SSL_CERT") = "LOCAL_MACHINE\My\myCert.cer";
var http
=
Server.CreateObject(
"
MSXML2.ServerXMLHTTP.4.0
"
);
http.setOption (
2
,
13056
);
Response.Write(
"
http.setOption (2,13056);<br>
"
);
var url
=
CAS_Server
+
"
validate?ticket=
"
+
ticket
+
"
&service=
"
+
originatingURL;
http.open(
"
GET
"
,url,
false
);
http.send();
Response.Write(
"
http.send();<br>
"
);
var resp
=
http.responseText.split(
'
\n
'
);
if
(resp[
0
]
==
"
yes
"
)
{
//
若已开通当前系统服务
if
(hasOpenedTheService(resp[
1
]))
{
//
置用户登录状态
setUserLoginState(resp[
1
]);
greeting
=
resp[
1
];
Session.Contents(
"
Netid
"
)
=
resp[
1
];
}
else
{
//
引导开通
if
(openServiceUrl
!=
null
&&
openServiceUrl.length
!=
0
)
{
Response.Redirect(openServiceUrl
+
"
?user=
"
+
resp[
1
]
+
"
&service=
"
+
originatingURL);
Response.End;
}
}
}
}
}
function getQueryString(qStr)
{
var queryStr
=
new
String(qStr);
if
(queryStr
==
null
||
queryStr
==
""
)
return
""
;
var startIndex
=
queryStr.indexOf(
"
ticket
"
,
0
);
var endIndex
=
queryStr.indexOf(
"
&
"
,startIndex);
if
(startIndex
>=
0
)
{
if
(endIndex
>=
0
)
{
if
(startIndex
>
0
)
queryStr
=
queryStr.substring(
0
,startIndex
-
1
)
+
queryStr.substring(endIndex,queryStr.length);
else
queryStr
=
queryStr.substring(
0
,startIndex
-
1
)
+
queryStr.substring(endIndex
+
1
,queryStr.length);
}
else
{
queryStr
=
queryStr.substring(
0
,startIndex
-
1
);
}
}
if
(queryStr.length
>
0
)
queryStr
=
"
?
"
+
queryStr;
return
queryStr;
}
/** */
/**
*作用:判断用户是否已经登录
*返回值:已登录返回true,未登录返回false
*/
function isLogon()
{
/**/
/*
待实现的方法
*/
return
false
;
}
/** */
/**
*作用:将用户设置成登录状态
*参数:userID为用户手机号码
*返回值:无
*/
function setUserLoginState(userID)
{
/**/
/*
待实现的方法
*/
}
/** */
/**
*作用:检测用户是否已开通本网站服务
*参数:userID为用户手机号码
*返回值:已开通返回true;否则返回false
*/
function hasOpenedTheService(userID)
{
/**/
/*
待实现的方法
*/
return
true
;
}
%>
</
header
>
<
BODY
>
<
P
>
Hello
<%=
Session.Contents(
"
Netid
"
)
+
"
--
"
+
Request.ServerVariables(
"
URL
"
)
%></
P
>
</
BODY
>
</
HTML
>
http.setOption (2,13056);此句很重要,不设置浏览器会报错