国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
CAS自定義客戶端登錄界面
一、說明
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標簽之后添加
普通瀏覽復制代碼
  1.     <action-state id="provideLoginTicket">  
  2.         <evaluate ="provideLoginTicketAction"/>  
  3.         <transition on="loginTicketRequested" to ="viewResponseLoginTicketInfo" />  
  4.         <transition on="continue" to="ticketGrantingTicketExistsCheck" />  
  5.     </action-state>
  6.         <view-state id="viewResponseLoginTicketInfo" view="responseLoginTicketInfoView" model="credentials">
  7.         <binder>  
  8.             <binding property="username" />  
  9.             <binding property="password" />  
  10.         </binder>  
  11.         <on-entry>  
  12.             <set name="viewScope.commandName" value="'credentials'" />  
  13.         </on-entry>  
  14.         <transition on="submit" bind="true" validate="true" to="realSubmit">
  15.             <evaluate ="authenticationViaFormAction.doBind(flowRequestContext, flowScope.credentials)" />  
  16.         </transition>  
  17.     </view-state>
(2)在cas-servlet.xml中聲明provideLoginTicketAction

  1. <bean id="provideLoginTicketAction" class="net.water.cas.controller.ProvideLoginTicketAction"
  2.    p:ticketIdGenerator-ref="loginTicketUniqueIdGenerator" />
復制代碼
(3)添加ProvideLoginTicketAction.java
普通瀏覽復制代碼
  1. package net.water.cas.controller;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.validation.constraints.NotNull;
  4. import org.apache.commons.logging.Log;
  5. import org.apache.commons.logging.LogFactory;
  6. import org.jasig.cas.util.UniqueTicketIdGenerator;
  7. import org.jasig.cas.web.support.WebUtils;
  8. import org.springframework.webflow.action.AbstractAction;
  9. import org.springframework.webflow.execution.Event;
  10. import org.springframework.webflow.execution.RequestContext;
  11. public class ProvideLoginTicketAction extends AbstractAction{  
  12.         private static final String PREFIX = "LT";  
  13.         private final Log logger = LogFactory.getLog(getClass());  
  14.         @NotNull  
  15.         private UniqueTicketIdGenerator ticketIdGenerator;  
  16.         public final String generate(final RequestContext context) {  
  17.             final String loginTicket = this.ticketIdGenerator.getNewTicketId(PREFIX);  
  18.             this.logger.debug("Generated login ticket " + loginTicket);  
  19.             WebUtils.putLoginTicket(context, loginTicket);  
  20.             return "generated";  
  21.         }  
  22.         public void setTicketIdGenerator(final UniqueTicketIdGenerator generator) {  
  23.             this.ticketIdGenerator = generator;  
  24.         }  
  25.         @Override  
  26.         protected Event doExecute(RequestContext context) throws Exception {  
  27.             final HttpServletRequest request = WebUtils.getHttpServletRequest(context);  
  28.             if (request.getParameter("get-lt") != null && request.getParameter("get-lt").equalsIgnoreCase("true")) {  
  29.                 final String loginTicket = this.ticketIdGenerator.getNewTicketId(PREFIX);  
  30.                 this.logger.debug("--------------Generated login ticket :" + loginTicket);  
  31.                 WebUtils.putLoginTicket(context, loginTicket); 
  32.                 return result("loginTicketRequested");
  33.             }  
  34.             return result("continue");
  35.         }  
  36. }
(4)在default_views.properties中添加頁面的配置

  1. responseLoginTicketInfoView.(class)=org.springframework.web.servlet.view.JstlView
  2. responseLoginTicketInfoView.url=/WEB-INF/view/jsp/default/ui/responseLoginTicketInfo.jsp
復制代碼
(5)添加responseLoginTicketInfo.jsp文件

  1. <%@ page contentType="text/html; charset=UTF-8"%>
  2. <%out.print("flightHandler({'lt':'");%>${loginTicket}<%out.print("','execution':'");%>${flowExecutionKey}<%out.print("'});");%>
復制代碼
2、客戶端登錄頁面login.jsp

  1. <%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>客戶端登錄cas-demo</title>
  7. <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.2.min.js"></script>
  8. <script type="text/javascript">
  9.                 $(function(){
  10.                         flushLoginTicket();
  11.                 });
  12.                 var flushLoginTicket = function(){
  13.                         var _services = 'service=' + encodeURIComponent('http://localhost:8080/security/admin/home.jsp');
  14.                     var urlOfGetLt = 'http://localhost:8080/casServer/login?'+_services+'&get-lt=true&n='+new Date().getTime();
  15.                     $.ajax({
  16.              type: "get",
  17.              async: false,
  18.              url: urlOfGetLt,
  19.              dataType: "jsonp",
  20.              jsonp: "callback",
  21.              jsonpCallback:"flightHandler",
  22.              success: function(json){
  23.                  //alert('lt: ' + json.lt + ',execution: ' + json.execution);
  24.                  $("#cas_loginTicket").val(json.lt);
  25.                  $("#cas_execution").val(json.execution);
  26.              },
  27.              error: function(){
  28.                  alert("無法獲取登錄key");
  29.              }
  30.          });
  31.                 };

  32. <blockquote>         var loginValidate = function(){
復制代碼
至此,當用戶名/密碼輸入正確時,已經(jīng)可以正常跳轉(zhuǎn)到指定的頁面,但錯誤的話還是會到casServer默認的登錄頁面。
3、登錄失敗時在客戶端提示
(1)修改org.jasig.cas.web.flow.AuthenticationViaFormAction.java的submit方法

  1.         try {
  2.             WebUtils.putTicketGrantingTicketInRequestScope(context, this.centralAuthenticationService.createTicketGrantingTicket(credentials));
  3.             putWarnCookieIfRequestParameterPresent(context);
  4.             return "success";
  5.         } catch (final TicketException e) {
  6.             populateErrorsInstance(e, messageContext);
  7.             //客戶端登錄錯誤提示
  8.             String referer = context.getRequestParameters().get("login-at");
  9.             if(referer!=null && !"".equals(referer)){
  10.                     return "errorForRemoteRequestor";
  11.             }
  12.             if (isCauseAuthenticationException(e))
  13.                 return getAuthenticationExceptionEventId(e);
  14.             return "error";
  15.         }
復制代碼
(2)修改login-webflow.xml
在realSubmit的聲明中添加

  1. <transition on="errorForRemoteRequestor" to="viewRedirectToRequestorView" />
復制代碼
添加viewRedirectToRequestorView的聲明

  1. <end-state id="viewRedirectToRequestorView" view="viewRedirectToRequestorView" />
復制代碼
(3)在default_views.properties中添加頁面的配置

  1. viewRedirectToRequestorView.(class)=org.springframework.web.servlet.view.JstlView
  2. viewRedirectToRequestorView.url=/WEB-INF/view/jsp/default/ui/redirectToRequestor.jsp
復制代碼
(4)添加redirectToRequestor.jsp頁面

  1. <%@ page contentType="text/html; charset=UTF-8"%>
  2. <%
  3. String referer = request.getParameter("login-at");
  4. String separator = (referer.indexOf("?") > -1) ? "&" : "?";
  5. %>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml" >
  8.   <head>
  9.     <script type="text/javascript" language="javascript">
  10.       <!--
  11.       var redirectURL = "<%=referer%>" + "<%=separator%>" + "login_error_msg=" + encodeURIComponent("用戶名或密碼錯誤");
  12.       window.location.replace(redirectURL);
  13.       -->
  14.     </script>
  15.     <title>Redirect</title>
  16.   </head>
  17.   <body></body>
  18. </html>
復制代碼
(5)客戶端登錄頁面login.jsp添加錯誤提示
script中添加動態(tài)顯示

  1.                 $(function(){
  2.                         if("${param['login_error_msg']}" != ""){
  3.                                 $("#div_login_msg").html("${param['login_error_msg']}");
  4.                         }
  5.                 });
復制代碼
頁面中添加一個div

  1. <div id="div_login_msg"></div>
復制代碼
form中添加login-at參數(shù)

  1. <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
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服