How to deal with spring button

I am using spring security and I was wondering how to solve this button or browser problem.

The fact is that after logging in, when I click the "Back" button. I went back to the login page. It would be very nice if even when you click the "Back" button, you remain only on the home page.

The same should be, if I logged out, it should not be, when I click the "Back" button, I am again on the home page. I am not sure what to do to solve this problem. I know the browser caches pages, but when I use a standard website like facebook or yahoo, it seems like there is already some solution for it. Any direction or information would be very helpful.?

+4
source share
2 answers

Part of the problem arises from the browser cache. You can disable it in several ways:

  • Configure Spring MVC interceptor for all your pages:
<mvc:annotation-driven/> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**/*"/> <bean id="webContentInterceptor" class="org.springframework.web.servlet.mvc.WebContentInterceptor"> <property name="cacheSeconds" value="0"/> <property name="useExpiresHeader" value="true"/> <property name="useCacheControlHeader" value="true"/> <property name="useCacheControlNoStore" value="true"/> </bean> </mvc:interceptor> </mvc:interceptors> 
  • Call Answer Methods:
  response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); 
  • Add meta tags to relevant pages:
  <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-cache"> <meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT"> 
+5
source

You tried to build cache control in Spring Security:

 @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http // ... .headers() .defaultsDisabled() .cacheControl(); } } 
+1
source

Source: https://habr.com/ru/post/1496143/


All Articles