<
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);此句很重要,不設置瀏覽器會報錯