In my previous employment I was experiencing a well known problem of being unable to prevent the user from being able to navigate the site using the back button after logging out. My technologies include Spring, JavaScript and potentially the Mobile module of the Java AJAX library ZK. Besides navigating using the back button, authorised access worked otherwise. I no longer have access to the application code. The application was a mobile one of which I was not the original author.
I've tried the following common solutions:
WebContentInterceptor
(as instructed here )RequestMappingHandlerAdapter
to set cacheSeconds
to 0
We have the following definition in t2-spring-security-context.xml
:
<http auto-config="true">
<intercept-url pattern="/mobile-index*" access="ROLE_ADMIN"/>
<intercept-url pattern="/t2-metrics*" access="ROLE_ADMIN"/>
<intercept-url pattern="/t2-monitor*" access="ROLE_ADMIN"/>
<form-login login-page="/login.jsp" authentication-failure-url="/loginerror.jsp"
default-target-url="/mobile-index.jsp"/>
<logout logout-success-url="/login.jsp" invalidate-session="true"/>
</http>
Other details about our implementation:
@RequestMapping
from JavaScript on a class annotated as @Controller
(I.E. t2-metrics.jsp has JS to fire to URL matching request mapping)security:global-method-security
to application context and role annotation to method My only remaining idea was that the problem involves our client code (JavaScript) or libraries (Incorrect integration with Spring Security) for from the view because debug did not hitting the Spring Security filter chain.
It happens because your browser cached the page on the client. The solution is to prevent the caching of that page(s), by forcing the browser to request a new page even when pressing Back button, instead of reading the saved one.
On the login screen, in PHP, before rendering the view, you need to check if the user is already logged in, and redirect to the default page the user should see after logged in. Similarly, on the screens requiring login, you need to check if the user is not logged in and if not, redirect them to the login screen.
Use the below code in servlet-context file
<mvc:interceptors>
<bean id="webContentInterceptor" class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheSeconds" value="0"/>
<property name="useExpiresHeader" value="false"/>
<property name="useCacheControlHeader" value="true"/>
<property name="useCacheControlNoStore" value="true"/>
</bean>
</mvc:interceptors>
It will work same as below code in jsp page:
response.setHeader("pragma", "no-cache");
response.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
response.setHeader("Expires", "0");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With