Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, it is possible. You can send cookie to user's web browser with value of his/her username when user is authenticated. When session is expired, you can still access that cookie. All you need to do is set its lifetime to be long enough.</p> <p>You may implement your own <code>Filter</code>. I recommend extending <code>UsernamePasswordAuthenticationFilter</code>. Overriding <code>Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)</code> gives you access to cookies - you can add one with <code>HttpServletResponse.addCookie(Cookie cookie)</code>.</p> <p>You can easily inject your own filter. More info about config: <a href="http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#nsa-custom-filter" rel="nofollow">http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#nsa-custom-filter</a></p> <p>Also take into account that it can be insecure to send such a cookie. I don't see any other way to accomplish what you want. But you can easily improve security of this solution by configuring <code>LogoutHandler</code>. There is an implementation of this interface <code>CookieClearingLogoutHandler</code>. You can use it to clear that cookie when user decides to logout manually.</p> <pre><code>&lt;bean id="cookieClearingLogoutHandler" class="org.springframework.security.web.authentication.logout.CookieClearingLogoutHandler"&gt; &lt;constructor-arg&gt; &lt;!-- Names of the cookies you want to remove when user logs out --&gt; &lt;list&gt; &lt;value&gt;username&lt;/value&gt; &lt;/list&gt; &lt;/constructor-arg&gt; &lt;/bean&gt; &lt;bean id="logoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter"&gt; &lt;constructor-arg value="/login"/&gt; &lt;constructor-arg&gt; &lt;array&gt; &lt;ref local="securityContextLogoutHandler"/&gt; &lt;!-- Inject it --&gt; &lt;ref local="cookieClearingLogoutHandler"/&gt; &lt;/array&gt; &lt;/constructor-arg&gt; &lt;property name="filterProcessesUrl" value="/logout"/&gt; &lt;/bean&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload