标签:
一、登出实现返回自定义页面
服务端修改
cas-servlet.xml
<bean id="logoutAction" class="org.jasig.cas.web.flow.LogoutAction" p:servicesManager-ref="servicesManager" p:followServiceRedirects="${cas.logout.followServiceRedirects:true}"/>
些处p:followServiceRedirects="false"改true
客户端
方法一
Web.xml 添加
<!-- 填写退出的URL --> <context-param> <param-name>casServerLogoutUrl</param-name> <param-value>http://www.myCas.com:18080/logout</param-value> </context-param> <!--单点退出配置-->
新增logout.Jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title></title> </head> <body> <% session.invalidate(); response.sendRedirect(application .getInitParameter("casServerLogoutUrl") + "?service=http://ciat.padx.cn:8080/globle-login.action"); %> </body> </html>
调用:
<a href="${ctx}/logout.jsp" class="exit"><i class="icon global-exit"></i>安全退出</a>
方法二(CMS项目)
<a href="http://www.myCas.com:18080/logout?service=http://www.myapp5.com:8088/jeeadmin/jeecms/logout.do?returnUrl=login.do" target="_top" id="logout" onclick="return confirm(‘<@s.m "global.confirm.logout"/>‘);"><@s.m "global.admin.logout"/></a>
二、密码不正确返回自定义页面
客户端需要将 返回页面传入loginurl
login-webflow.xml
1、Handle里添加第一个参数
2、添加返回页面参数
1 <action-state id="handleAuthenticationFailure"> 2 <evaluate expression="authenticationExceptionHandler.handle(flowRequestContext,currentEvent.attributes.error, messageContext)" /> 3 <transition on="AccountDisabledException" to="casAccountDisabledView"/> 4 <transition on="AccountLockedException" to="casAccountLockedView"/> 5 <transition on="CredentialExpiredException" to="casExpiredPassView"/> 6 <transition on="InvalidLoginLocationException" to="casBadWorkstationView"/> 7 <transition on="InvalidLoginTimeException" to="casBadHoursView"/> 8 <transition on="FailedLoginException" to="generateLoginTicket"/> 9 <transition on="AccountNotFoundException" to="generateLoginTicket"/> 10 <transition on="UNKNOWN" to="generateLoginTicket"/> 11 <transition on="cust" to="failureLoginView"/> 12 </action-state>
新增
<end-state id="failureLoginView" view="failureLoginView" />
AuthenticationException.java
添加方法
public String handle(final RequestContext context,final AuthenticationException e, final MessageContext messageContext) { HttpServletRequest request = WebUtils.getHttpServletRequest(context); String isFrame=context.getRequestParameters().get("isFrame"); String loginUrl=context.getRequestParameters().get("loginUrl"); request.setAttribute("tologinUrl", loginUrl); request.setAttribute("isFrame", isFrame); String error="UNKNOWN"; if (e != null) { for (final Class<? extends Exception> kind : this.errors) { for (final Class<? extends Exception> handlerError : e.getHandlerErrors().values()) { if (handlerError != null && handlerError.equals(kind)) { final String messageCode = this.messageBundlePrefix + handlerError.getSimpleName(); messageContext.addMessage(new MessageBuilder().error().code(messageCode).build()); error = handlerError.getSimpleName(); break; } } } } request.setAttribute("error", error); return "cust"; }
default_views.properties
failureLoginView.(class)=org.springframework.web.servlet.view.JstlView
failureLoginView.url=/WEB-INF/view/jsp/default/ui/failureLogin.jsp
新增failureLogin.jsp
<%@ page contentType="text/html; charset=UTF-8"%> <html> <head> </head> <body> <script type="text/javascript"> <% Boolean isFrame = (Boolean)request.getAttribute("isFrame"); if(isFrame!=null && isFrame ){%> parent.location.replace(‘${tologinUrl}?error=${error}‘) <%} else{%> location.replace(‘${tologinUrl}?error=${error}‘) <% } %> </script> </body> </html>
【SSO单点系列】(3):CAS4.0 之自定义返回登出页面
标签:
原文地址:http://www.cnblogs.com/hedgehog105/p/5417798.html