码迷,mamicode.com
首页 > 其他好文 > 详细

【SSO单点系列】(3):CAS4.0 之自定义返回登出页面

时间:2016-04-21 18:04:54      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:

一、登出实现返回自定义页面

服务端修改

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>
View Code

新增

<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";

}
View Code

 

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!