Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Security 3.0.5 Concurrency is not working
    text
    copied!<p>Hi I am using Spring Security 3.0.5 with Spring Framework 3.0.6. I have configured concurrency as per the documentation. It is not working. I login to the application from a browser session and then attemp to login again from another tab in the same browser - it lets me log in instead of denying the attempt.</p> <p>Here is my security config file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"&gt; &lt;http auto-config="false" use-expressions="true" access-denied-page="/jsp/accessDenied.jsp" entry-point-ref="authenticationEntryPoint"&gt; &lt;intercept-url pattern="/login.jsp" filters="none" /&gt; &lt;intercept-url pattern="/**" access="hasRole('ROLE_USER')" /&gt; &lt;logout invalidate-session="true" logout-url="/logout.htm" logout-success-url="/login.jsp?loggedout=true"/&gt; &lt;custom-filter ref="authenticationFilter" position="FORM_LOGIN_FILTER"/&gt; &lt;custom-filter ref="concurrencyFilter" position="CONCURRENT_SESSION_FILTER"/&gt; &lt;session-management session-authentication-strategy-ref="sas"/&gt; &lt;/http&gt; &lt;beans:bean id="authenticationFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"&gt; &lt;beans:property name="sessionAuthenticationStrategy" ref="sas"/&gt; &lt;beans:property name="authenticationManager" ref="authenticationManager"/&gt; &lt;beans:property name="authenticationFailureHandler" ref="customAuthenticationFailureHandler"/&gt; &lt;beans:property name="authenticationSuccessHandler" ref="customAuthenticationSuccessHandler"/&gt; &lt;/beans:bean&gt; &lt;beans:bean id="customAuthenticationFailureHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"&gt; &lt;beans:property name="defaultFailureUrl" value="/login.jsp?authfailed=true"/&gt; &lt;/beans:bean&gt; &lt;beans:bean id="customAuthenticationSuccessHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler"&gt; &lt;beans:property name="defaultTargetUrl" value="/index.jsp" /&gt; &lt;/beans:bean&gt; &lt;beans:bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"&gt; &lt;beans:property name="loginFormUrl" value="/login.jsp"/&gt; &lt;/beans:bean&gt; &lt;authentication-manager alias="authenticationManager"&gt; &lt;authentication-provider user-service-ref="userDetailsService"&gt; &lt;password-encoder ref="passwordEncoder"/&gt; &lt;/authentication-provider&gt; &lt;/authentication-manager&gt; &lt;beans:bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/&gt; &lt;user-service id="userDetailsService"&gt; &lt;user name="username" password="ee11cbb19052e40b07aac0ca060c23ee" authorities="ROLE_USER, ROLE_ADMIN" /&gt; &lt;user name="test" password="21232f297a57a5a743894a0e4a801fc3" authorities="ROLE_USER" /&gt; &lt;/user-service&gt; &lt;beans:bean id="concurrencyFilter" class="org.springframework.security.web.session.ConcurrentSessionFilter"&gt; &lt;beans:property name="sessionRegistry" ref="sessionRegistry"/&gt; &lt;beans:property name="expiredUrl" value="/login.jsp?loggedout=true" /&gt; &lt;/beans:bean&gt; &lt;beans:bean id="sas" class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy"&gt; &lt;beans:property name="maximumSessions" value="1" /&gt; &lt;beans:constructor-arg name="sessionRegistry" ref="sessionRegistry" /&gt; &lt;/beans:bean&gt; &lt;beans:bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl" /&gt; </code></pre> <p></p> <p>Here is my web.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt; &lt;display-name&gt;Spring security web application (series)&lt;/display-name&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/applicationContext-security.xml &lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- - Loads the root application context of this web app at startup. - The application context is then available via - WebApplicationContextUtils.getWebApplicationContext(servletContext). --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;listener&gt; &lt;listener-class&gt; org.springframework.security.web.session.HttpSessionEventPublisher&lt;/listener-class&gt; &lt;/listener&gt; &lt;filter&gt; &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;servlet&gt; &lt;servlet-name&gt;springsecuritywebapp&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;springsecuritywebapp&lt;/servlet-name&gt; &lt;url-pattern&gt;*.htm&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;/web-app&gt; </code></pre> <p>Regards, Nazir</p>
 

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