I am woking on a project using JSF2. I use Spring security for Authentication (access ,login, and logout) and my view pages are xhtml. My problem is that after logout user could back to previous page and do job. I use AuthenticationBean class for login&louout. Also I added below command to header of my page but nothing changed!
meta http-equiv="Cache-control" content="public"
meta http-equiv="Cache-control" content="private"
meta http-equiv="Cache-control" content="no-cache"
meta http-equiv="Cache-control" content="no-store"
The bean:
@ManagedBean(name = "authenticationBean")
@RequestScoped
public class AuthenticationBean {
public String doLogin() throws ServletException, IOException {
ExternalContext context = FacesContext
.getCurrentInstance().getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
.getRequestDispatcher("/j_spring_security_check");
dispatcher.forward(
(ServletRequest) context.getRequest(),
(ServletResponse) context.getResponse());
FacesContext.getCurrentInstance().responseComplete();
return null;
}
public String doLogout() {
FacesContext.getCurrentInstance()
.getExternalContext().invalidateSession();
return "/login.xhtml";
}
}
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
<h:graphicImage library="images" name="spr-2.png" width="400" height="400"/>
<h:form id="loginForm" prependId="false">
<h:messages globalOnly="true"/>
<p:messages autoUpdate="true"/>
<h:panelGrid columns="3">
<h:outputLabel for="j_username" value="User: * " />
<p:inputText id="j_username" required="true" label="username" />
<h:outputLabel for="j_password" value="Password: * " />
<p:password id="j_password" label="password" required="true" />
</h:panelGrid>
<h:commandButton type="submit" id="login" value="Login" action="#{authenticationBean.doLogin()}" />
</h:form>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
</f:facet>
</h:head>
<h:body>
<h:form>
<h:commandLink action="#{authenticationBean.doLogout}" style="font-size: 0.7em;color:blue;font-family:serif ">logout</h:commandLink>
</h:form>
<h:form>
<p:commandLink value="GO TO Functions" action="/pages/admin/indexAdmin?faces-redirect=true"/>
</h:form>
<h:graphicImage library="images" name="pic1.jpg" width="800" height="200"/> </h:body>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">