Avoid Going on back page after Logout in JSF application
Asked Answered
D

0

0

I am disabling the user to go back on the previous page after he has logged out. Controls comes in the filter but the page are still there in cache. I have used the filter suggested in this answer :

BalusC Answer

My filter looks like :

@WebFilter
public class NoCacheFilter implements Filter {

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    System.err.println("Cache Filter- Called");
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0); // Proxies.

    chain.doFilter(req, res);
}

@Override
public void destroy() {
    // TODO Auto-generated method stub

}

web.xml looks like :

<filter>
        <filter-name>EncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>EncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>NoCacheFilter</filter-name>
        <filter-class>com.omnia.pie.cm.filters.NoCacheFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>NoCacheFilter</filter-name>
        <url-pattern>*.xhtml</url-pattern>
    </filter-mapping>

But still I am able to go back after I have logged out. Please help ,thanks in advance.

Dictate answered 9/11, 2017 at 14:23 Comment(6)
Is your filter getting called properly? Did you debug that to make sure, that each page is of type xhtml and filter is getting called properly or is there any other filter that is overriding these headers? Can you check response headers as well, when the page is accessed.Wordbook
@Wordbook everything seems fine and it is being called properly.Dictate
@Wordbook do you think that I need to pass the 'response' in chain.doFilter instead of 'res' object ?Dictate
No. @talib both are same object so that shall not be issue. I was just wondering, when you do chain.dofilter, is there any other filter that is removing those headers. To test, go to chrome, f12, developer's tool will come. Access the page before logout. Check in developer's tool what was the response header. It should have got those cache header in response. If there is no such header, then something is wrongWordbook
@Wordbook thanks for the response, I have checked in the developer tools and the response header contains the following headers : Cache-Control no-cache, no-store, must-revalidate Pragma no-cache Expires Thu, 01 Jan 1970 00:00:00 GMTDictate
@Wordbook any suggestion or idea ?Dictate

© 2022 - 2024 — McMap. All rights reserved.