1

我正在使用 Spring(3.2.8) + CAS (4.0.0),我想在注销后重定向到登录页面(而不是显示注销确认页面)。

我试图添加 cas.logout.followServiceRedirects=true我的cas.properties但没有任何反应。

在客户端,当用户想要注销时,他访问: APP_URL/j_spring_cas_security_logout

我的logout-webflow.xml看起来像:

<flow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://www.springframework.org/schema/webflow"
  xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

<action-state id="terminateSession">
    <on-entry>
        <evaluate expression="cryptoServerLogoutInterceptor.terminateCryptoSession(flowRequestContext)"/>
    </on-entry>
    <evaluate expression="terminateSessionAction.terminate(flowRequestContext)"/>
    <transition to="doLogout"/>
</action-state>

<action-state id="doLogout">
    <evaluate expression="logoutAction"/>
    <transition on="finish" to="finishLogout"/>
    <transition on="front" to="frontLogout"/>
</action-state>

<action-state id="frontLogout">
    <evaluate expression="frontChannelLogoutAction"/>
    <transition on="finish" to="finishLogout"/>
    <transition on="redirectApp" to="redirectToFrontApp"/>
</action-state>

<view-state id="redirectToFrontApp"
            view="externalRedirect:#{currentEvent.attributes.logoutUrl}&amp;RelayState=#{flowExecutionContext.key}">
    <transition on="next" to="frontLogout"/>
</view-state>


<decision-state id="finishLogout">
    <if test="flowScope.logoutRedirectUrl != null" then="redirectView" else="logoutView"/>
</decision-state>

<end-state id="redirectView" view="externalRedirect:#{flowScope.logoutRedirectUrl}"/>

<view-state id="logoutView" view="casLogoutView"/>

另一方面,当用户在未经身份验证的情况下访问应用程序时,他会被重定向到: CAS_URL/login?service=APP_URL%2Fj_spring_cas_security_check

所以我可能需要在某处添加/保留:service=APP_URL

谢谢帮助。

编辑

当我尝试:

<end-state id="logoutView" view="flowRedirect:login"/>

我最终:

此网页有重定向循环

ERR_TOO_MANY_REDIRECTS

但它适用于:

<end-state id="logoutView" view="externalRedirect:contextRelative:login"/>
4

1 回答 1

0

正如你所说cas.logout.followServiceRedirects=true是不够的。因为您应该定义注销后应该重定向的服务:

    <bean id="requestSingleLogoutFilter"
    class="org.springframework.security.web.authentication.logout.LogoutFilter">
    <constructor-arg
        value="${cas.server.address}/logout?service=${cas.server.address}" />
    <constructor-arg>
        <bean
            class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler" />
    </constructor-arg>
    <property name="filterProcessesUrl" value="/j_spring_cas_security_logout" />
</bean>

您应该将此过滤器添加到springSecurityFilterChain

        <sec:filter-chain pattern="/j_spring_cas_security_logout*"
            filters="requestSingleLogoutFilter" />
于 2018-12-02T08:11:07.970 回答