java - How to get session time out message using Spring security -


i want session time out message when session expires.below spring-security.xml

<http auto-config="true" use-expressions="true">     <logout logout-success-url="/" invalidate-session="true" logout-url="/logout"/>     <form-login login-page="/login" username-parameter="name" password-parameter="pwd"/>     <session-management invalid-session-url="/?timeout=true">         <concurrency-control max-sessions="1" expired-url="/timeout?timeout=true" />     </session-management> </http> 

according knowledge using above code when session expired should redirect /?timeout=true or /timeout?timeout=true. , on logout should go /. in case on logout redirecting invalid-session-url getting timeout true both normal logout , session timeout.

please me differentiate this.

update

/logout request contains

session = request.getsession(); session.invalidate(); session = null; 

i solved it! writing filter instead depending on spring-security.

if 1 interested can use below code :-

import java.io.ioexception; import java.io.printwriter; import java.io.stringwriter; import java.text.messageformat;  import javax.servlet.filterchain; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse;  import org.apache.log4j.logger; import org.springframework.web.filter.onceperrequestfilter;  public class filtertogettimeout extends onceperrequestfilter {      @override     public void dofilterinternal(httpservletrequest request, httpservletresponse response, filterchain filterchain) throws ioexception {         try {             if(request.getrequesturi().equals("/") || request.getrequesturi().equals("/login/")){                 if(request.getsession().getattribute("login") != null && (boolean)request.getsession().getattribute("login") == true){                     response.sendredirect(url);     //after login page                 }             } else if(request.getsession().getattribute("login") == null && !request.getrequesturi().equals("/logout")){                 response.sendredirect(request.getcontextpath()+"/?timeout=true");   //if timeout true send session timeout error message jsp             }             filterchain.dofilter(request, response);         } catch (exception e) {             //log exception          }     } } 

add filter in web.xml.

    <filter>         <filter-name>filtertogettimeout </filter-name>          <filter-class>package.filtertogettimeout </filter-class>      </filter>     <filter-mapping>          <filter-name>filtertogettimeout</filter-name>          <url-pattern>/*</url-pattern>      </filter-mapping>  

so session invalidates , can handle session timeout too.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -