Can Spring help to prevent caching of html pages on the browser? -
i have java/spring 3.x webapp uses extjs , use sencha architect create front end results in automatically generated app.html file loads in js , css resources looks this:
<!doctype html> <!-- auto generated sencha architect --> <!-- modifications file overwritten. --> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>ui</title> <script src="ext/ext-all.js"></script> <script src="ext/ext-theme-neptune.js"></script> <link rel="stylesheet" href="ext/resources/ext-theme-neptune/ext-theme-neptune-all.css"> <link rel="stylesheet" href="css/custom.css"> <script type="text/javascript" src="app.js"></script> </head> <body></body> </html>
i want protect html file spring security , seems work except cached in browser appears reload when user not logged in. here spring xml configures security webapp:
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" 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/security http://www.springframework.org/schema/security/spring-security-3.2.xsd"> <http auto-config="true" use-expressions="true"> <intercept-url pattern="/ui/app.html" access="hasrole('role_user')" /> <intercept-url pattern="/ui/**" access="permitall" /> <form-login login-page="/login" default-target-url="/ui/app.html" authentication-failure-url="/login?error" username-parameter="username" password-parameter="password" /> <logout logout-success-url="/login?logout" /> <csrf/> <!-- enable csrf protection --> </http> <authentication-manager> <authentication-provider > <user-service> <user name="test" password="test" authorities="role_user" /> </user-service> </authentication-provider> </authentication-manager> </beans:beans>
as can see have configured protect ui/app.html resource redirect page after log in. works fine until browser caches page , causes confusion when user logged out , tries access same url.
i wondering if spring mvc used load page via controller, perhaps modifying http headers force page expire, page delivered directly servlet container , not mvc i'm not sure how configure that.
i'd able leave app.html file in-situ uses resources relative it, , it's easier leave there when working sencha architect.
this prevent browser caching:
<http> <!-- ... --> <headers> <cache-control /> </headers> </http>
it adds cache-control
, pragma
, expires
headers every response. more information can found in reference documentation, section security http response headers.
update: answer written version 3.2 of spring security. of version 4, these headers included default.
Comments
Post a Comment