国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看
打開APP
未登錄
開通VIP,暢享免費電子書等14項超值服
開通VIP
首頁
好書
留言交流
下載APP
聯(lián)系客服
CAS自定義客戶端登錄界面
用勿龍潛
>《CAS》
2014.07.19
關注
一、說明
CAS-Server端是作為一個獨立的項目單獨運行的,所有客戶端需要登錄時,默認是跳轉(zhuǎn)到casServer的統(tǒng)一登錄頁面。
有很多情況下,客戶端也希望有自己的登錄界面,這個頁面是在客戶端項目中的,登錄只是這個頁面的一部分功能,本文將實現(xiàn)這一效果。
所用casServer版本3.5.0
參考文章
http://denger.iteye.com/blog/809170
http://denger.iteye.com/blog/1119233
二、分析
查看casServer的統(tǒng)一登錄頁面的from,發(fā)現(xiàn)除了username/password兩參數(shù)外,還有_eventId/service/execution/lt四個,其中_eventId固定值submit,service可以自行設置,lt/execution兩項是動態(tài)的標識,所以解決方案也就有了,主要分三步:
1、獲取lt/execution的值
2、用自定義的form來登錄
3、登錄出錯時的信息提示
三、實現(xiàn)過程
1、修改login-webflow使登錄流程在某種特定情況下可以告訴我們lt/execution的值
(1)修改login-webflow.xml,在on-start標簽之后添加
普通瀏覽
復制代碼
<action-state id=
"provideLoginTicket"
>
<
evaluate
=
"provideLoginTicketAction"
/>
<transition
on
=
"loginTicketRequested"
to
=
"viewResponseLoginTicketInfo"
/>
<transition
on
=
"continue"
to
=
"ticketGrantingTicketExistsCheck"
/>
</action-state>
<view-state id=
"viewResponseLoginTicketInfo"
view=
"responseLoginTicketInfoView"
model=
"credentials"
>
<binder>
<binding
property
=
"username"
/>
<binding
property
=
"password"
/>
</binder>
<on-entry>
<
set
name
=
"viewScope.commandName"
value
=
"'credentials'"
/>
</on-entry>
<transition
on
=
"submit"
bind
=
"true"
validate=
"true"
to
=
"realSubmit"
>
<
evaluate
=
"authenticationViaFormAction.doBind(flowRequestContext, flowScope.credentials)"
/>
</transition>
</view-state>
(2)在cas-servlet.xml中聲明provideLoginTicketAction
<bean id="provideLoginTicketAction" class="net.water.cas.controller.ProvideLoginTicketAction"
p:ticketIdGenerator-ref="loginTicketUniqueIdGenerator" />
復制代碼
(3)添加ProvideLoginTicketAction.java
普通瀏覽
復制代碼
package net.water.cas.controller
;
import javax.servlet.http.HttpServletRequest
;
import javax.validation.constraints.NotNull
;
import org.apache.commons.logging.Log
;
import org.apache.commons.logging.LogFactory
;
import org.jasig.cas.util.UniqueTicketIdGenerator
;
import org.jasig.cas.web.support.WebUtils
;
import org.springframework.webflow.action.AbstractAction
;
import org.springframework.webflow.execution.Event
;
import org.springframework.webflow.execution.RequestContext
;
public
class
ProvideLoginTicketAction extends AbstractAction{
private
static
final String PREFIX =
"LT"
;
private
final Log logger = LogFactory.getLog
(
getClass
(
)
)
;
@NotNull
private
UniqueTicketIdGenerator ticketIdGenerator
;
public
final String generate
(
final RequestContext context
)
{
final String loginTicket =
this
.ticketIdGenerator.getNewTicketId
(
PREFIX
)
;
this
.logger.debug
(
"Generated login ticket "
+ loginTicket
)
;
WebUtils.putLoginTicket
(
context, loginTicket
)
;
return
"generated"
;
}
public
void
setTicketIdGenerator
(
final UniqueTicketIdGenerator generator
)
{
this
.ticketIdGenerator = generator
;
}
@Override
protected
Event doExecute
(
RequestContext context
)
throws Exception {
final HttpServletRequest request = WebUtils.getHttpServletRequest
(
context
)
;
if
(
request.getParameter
(
"get-lt"
)
!=
null
&& request.getParameter
(
"get-lt"
)
.equalsIgnoreCase
(
"true"
)
)
{
final String loginTicket =
this
.ticketIdGenerator.getNewTicketId
(
PREFIX
)
;
this
.logger.debug
(
"--------------Generated login ticket :"
+ loginTicket
)
;
WebUtils.putLoginTicket
(
context, loginTicket
)
;
return
result
(
"loginTicketRequested"
)
;
}
return
result
(
"continue"
)
;
}
}
(4)在default_views.properties中添加頁面的配置
responseLoginTicketInfoView.(class)=org.springframework.web.servlet.view.JstlView
responseLoginTicketInfoView.url=/WEB-INF/view/jsp/default/ui/responseLoginTicketInfo.jsp
復制代碼
(5)添加responseLoginTicketInfo.jsp文件
<%@ page contentType="text/html; charset=UTF-8"%>
<%out.print("flightHandler({'lt':'");%>${loginTicket}<%out.print("','execution':'");%>${flowExecutionKey}<%out.print("'});");%>
復制代碼
2、客戶端登錄頁面login.jsp
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客戶端登錄cas-demo</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
flushLoginTicket();
});
var flushLoginTicket = function(){
var _services = 'service=' + encodeURIComponent('http://localhost:8080/security/admin/home.jsp');
var urlOfGetLt = 'http://localhost:8080/casServer/login?'+_services+'&get-lt=true&n='+new Date().getTime();
$.ajax({
type: "get",
async: false,
url: urlOfGetLt,
dataType: "jsonp",
jsonp: "callback",
jsonpCallback:"flightHandler",
success: function(json){
//alert('lt: ' + json.lt + ',execution: ' + json.execution);
$("#cas_loginTicket").val(json.lt);
$("#cas_execution").val(json.execution);
},
error: function(){
alert("無法獲取登錄key");
}
});
};
<blockquote> var loginValidate = function(){
復制代碼
至此,當用戶名/密碼輸入正確時,已經(jīng)可以正常跳轉(zhuǎn)到指定的頁面,但錯誤的話還是會到casServer默認的登錄頁面。
3、登錄失敗時在客戶端提示
(1)修改org.jasig.cas.web.flow.AuthenticationViaFormAction.java的submit方法
try {
WebUtils.putTicketGrantingTicketInRequestScope(context, this.centralAuthenticationService.createTicketGrantingTicket(credentials));
putWarnCookieIfRequestParameterPresent(context);
return "success";
} catch (final TicketException e) {
populateErrorsInstance(e, messageContext);
//客戶端登錄錯誤提示
String referer = context.getRequestParameters().get("login-at");
if(referer!=null && !"".equals(referer)){
return "errorForRemoteRequestor";
}
if (isCauseAuthenticationException(e))
return getAuthenticationExceptionEventId(e);
return "error";
}
復制代碼
(2)修改login-webflow.xml
在realSubmit的聲明中添加
<transition on="errorForRemoteRequestor" to="viewRedirectToRequestorView" />
復制代碼
添加viewRedirectToRequestorView的聲明
<end-state id="viewRedirectToRequestorView" view="viewRedirectToRequestorView" />
復制代碼
(3)在default_views.properties中添加頁面的配置
viewRedirectToRequestorView.(class)=org.springframework.web.servlet.view.JstlView
viewRedirectToRequestorView.url=/WEB-INF/view/jsp/default/ui/redirectToRequestor.jsp
復制代碼
(4)添加redirectToRequestor.jsp頁面
<%@ page contentType="text/html; charset=UTF-8"%>
<%
String referer = request.getParameter("login-at");
String separator = (referer.indexOf("?") > -1) ? "&" : "?";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript" language="javascript">
<!--
var redirectURL = "<%=referer%>" + "<%=separator%>" + "login_error_msg=" + encodeURIComponent("用戶名或密碼錯誤");
window.location.replace(redirectURL);
-->
</script>
<title>Redirect</title>
</head>
<body></body>
</html>
復制代碼
(5)客戶端登錄頁面login.jsp添加錯誤提示
script中添加動態(tài)顯示
$(function(){
if("${param['login_error_msg']}" != ""){
$("#div_login_msg").html("${param['login_error_msg']}");
}
});
復制代碼
頁面中添加一個div
<div id="div_login_msg"></div>
復制代碼
form中添加login-at參數(shù)
<input type="hidden" name="login-at" value="http://localhost:8080/security/login.jsp" />
復制代碼
以上
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報
。
打開APP,閱讀全文并永久保存
查看更多類似文章
猜你喜歡
類似文章
Cas自定義登錄頁面Ajax實現(xiàn)
session超時跳轉(zhuǎn)首頁
JSP Forward與Redirect 區(qū)別
非法訪問
jsp文件開頭path, basePath作用
4.5.1 登錄頁面login.jsp
更多類似文章 >>
生活服務
首頁
萬象
文化
人生
生活
健康
教育
職場
理財
娛樂
藝術
上網(wǎng)
留言交流
回頂部
聯(lián)系我們
分享
收藏
點擊這里,查看已保存的文章
導長圖
關注
一鍵復制
下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!
聯(lián)系客服
微信登錄中...
請勿關閉此頁面
先別劃走!
送你5元優(yōu)惠券,購買VIP限時立減!
5
元
優(yōu)惠券
優(yōu)惠券還有
10:00
過期
馬上使用
×