title: Spring security max session allowed
body: <p>I'm using spring security 3.1.4 and i would like to limit the number of session per user to 1 but if someone tries to log in it will close the old session and open a new one (instead of not allowing to log in) how can i do this?</p>
  
  <p>EDIT:
  this is what i added to the xmls:
  web.xml</p>
  
  <pre><code>&lt;listener&gt;
      &lt;listener-class&gt;
           com.net.filter.session.SessionListener
        &lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>SessionListener extends HttpSessionEventPublisher</p>
  
  <p>security.xml</p>
  
  <pre><code>    &lt;security:intercept-url pattern="/**"
          access="isAuthenticated()" /&gt;
  
      &lt;security:session-management&gt;
          &lt;security:concurrency-control
              max-sessions="1"/&gt;
      &lt;/security:session-management&gt;
  
      &lt;security:form-login
          authentication-success-handler-ref="playerAuthenticationSuccessHandler" /&gt;
      &lt;security:logout logout-url="/player/logout"
          success-handler-ref="playerLogoutSuccessHandler" delete-cookies="JSESSIONID" /&gt;
  &lt;/security:http&gt;
  
      &lt;bean id="bCryptPasswordEncoder"
          class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" /&gt;
  
  
  
      &lt;security:authentication-manager&gt;
          &lt;security:authentication-provider
              ref="authenticationProvider"&gt;
          &lt;/security:authentication-provider&gt;
      &lt;/security:authentication-manager&gt;
  </code></pre>
  
  <p>were playerAuthenticationSuccessHandler, authenticationProvider and playerLogoutSuccessHandler extends the spring defaults. </p>