2011-04-14 164 views
3

春季安全有沒有辦法阻止下面的最後一點?我使用的是3.0.5春季安全退出後退按鈕

- 用戶登錄到我的網站 - 用戶進入任何頁面的網站,並點擊註銷 -log出來的鏈接無效用戶會話,並將它們發送到登錄頁面在我的網站 - 在同一瀏覽器中,用戶導航到新網站(例如cnn.com) - 用戶點擊返回按鈕,它們落在我的登錄頁面 - 用戶再次點擊返回按鈕,它們最終在應用程序中可能有數據的頁面我們不想在那裏。如果他們點擊頁面上的任何鏈接,他們會立即被髮送到登錄頁面,但他們可以從瀏覽器緩存中查看緩存頁面......以任何方式不讓他們查看此頁面?

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans 
    xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-3.0.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 
    <context:annotation-config /> 
    <context:component-scan base-package="dc" /> 
    <global-method-security /> 
    <http access-denied-page="/auth/denied.html"> 
     <intercept-url filters="none" pattern="/javax.faces.resource/**" /> 
     <intercept-url filters="none" pattern="/services/rest-api/1.0/**" /> 
     <intercept-url filters="none" pattern="/preregistered/*"/> 
     <intercept-url 
      pattern="/**/*.xhtml" 
      access="ROLE_NONE_GETS_ACCESS" /> 
     <intercept-url 
      pattern="/auth/*" 
      access="ROLE_ANONYMOUS,ROLE_USER"/> 
     <intercept-url 
      pattern="/preregistered/*" 
      access="ROLE_ANONYMOUS,ROLE_USER"/> 
     <intercept-url 
      pattern="/registered/*" 
      access="ROLE_USER" 
      requires-channel="http"/> 
     <form-login 
      login-processing-url="/j_spring_security_check.html" 
      login-page="/auth/login.html" 
      default-target-url="/registered/home.html" 
      authentication-failure-url="/auth/login.html" /> 
     <logout invalidate-session="true" 
       logout-url="/auth/logout.html" 
       success-handler-ref="DCLogoutSuccessHandler"/> 
     <anonymous username="guest" granted-authority="ROLE_ANONYMOUS"/> 
     <custom-filter after="FORM_LOGIN_FILTER" ref="xmlAuthenticationFilter" /> 
     <session-management session-fixation-protection="none"/> 
    </http> 
    <!-- Configure the authentication provider --> 
    <authentication-manager alias="am"> 
     <authentication-provider user-service-ref="userManager"> 
       <password-encoder ref="passwordEncoder" /> 
     </authentication-provider> 
     <authentication-provider ref="xmlAuthenticationProvider" /> 
    </authentication-manager> 
</beans:beans> 
+0

這將幫助: http://stackoverflow.com/questions/4364622/how-to-set-header-no-cache-in-spring-mvc-3-by-annotation – padma057 2012-11-22 07:13:46

回答

3

下面的過濾照顧了我的情況:

package com.dc.api.service.impl; 

import javax.servlet.*; 
import javax.servlet.http.HttpServletResponse; 
import java.io.IOException; 
import java.util.Date; 

public class CacheControlFilter implements Filter { 

    public void doFilter(ServletRequest request, ServletResponse response, 
         FilterChain chain) throws IOException, ServletException { 

     HttpServletResponse resp = (HttpServletResponse) response; 
     resp.setHeader("Expires", "Tue, 03 Jul 2001 06:00:00 GMT"); 
     resp.setHeader("Last-Modified", new Date().toString()); 
     resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); 
     resp.setHeader("Pragma", "no-cache"); 

     chain.doFilter(request, response); 
    } 

    @Override 
    public void destroy() {} 

    @Override 
    public void init(FilterConfig arg0) throws ServletException {} 

} 
+1

是什麼意思「resp.setHeader(」Expires「,」Tue,2001年7月3日06:00:00 GMT「);」?你爲什麼指定2001年? – vinoth 2011-07-19 13:13:41

+0

hmm使用相同的解決方案,但過濾器不適用於/ j_spring_security_logout。想法? – 2012-03-09 10:05:16

2

春天3.0.x的

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> 
    <property name="cacheSeconds" value="0" /> 
</bean> 

春季2.5.X

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 
    <property name="cacheSeconds" value="0" /> 
</bean> 
0

如果,像我一樣,在使用c12的緩存過濾器和你之後沒有得到它的工作正在使用<security:http auto-config="true">請確保您不再需要auto-config="true"部分。它(看起來像)添加了http基本身份驗證,它不處理由協議註銷!這會導致您可以獲取您的註銷URL,但點擊後退按鈕只會將您帶回,因爲您並未真正註銷。

3

來解決這個問題,必須在安全的XML配置文件中加入:

<security:http auto-config="true" use-expressions="true"> 

    <security:headers > 
     <security:cache-control /> 
     <security:hsts/> 
    </security:headers> 
+0

這工作正常。但是,文檔中提到「我們建議您避免使用此功能,而是明確配置所需的服務。」對此有何想法? – QGA 2015-04-09 10:58:38

1

是的,我用彈簧安全3.2.9.RELEASE,只是在一個Spring配置文件中像的applicationContext給<security:headers />。 xml文件如上述職位

<security:http 
    auto-config="true" use-expressions="true"> 
    <security:headers />  
</security:http> 

,這樣用戶就不能去使用瀏覽器的後退註銷後訪問其他應用程序的頁面 和前進按鈕。