Spring security blocks user after failed login

2019-08-12 08:19发布

问题:

I'm using spring-security 3.

I tried to login to the application and filled with the wrong user/pass combination. After 3 wrong attempts, I filled with the right user/pass combination, but it still returns:

Your login attempt was not successful, try again.
Reason: Bad credentials

On develop that's (kind of) OK because I just restart the server and can login fine, but on production I can't restart the server every time somebody forgets his/her password.

I thought that maybe waiting after the timeout I could still login, but that doesn't work either.

app-security-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
         xmlns:beans="http://www.springframework.org/schema/beans"
         xmlns:context="http://www.springframework.org/schema/context"
         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-2.5.xsd
                       http://www.springframework.org/schema/security
                       http://www.springframework.org/schema/security/spring-security-3.0.xsd
                       http://www.springframework.org/schema/context
                       http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:property-placeholder location="file:${PROPERTIES_HOME}/app.properties" ignore-unresolvable="true"/>

    <http auto-config="true" use-expressions="true">
        <intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
        <session-management>
            <concurrency-control max-sessions="3" error-if-maximum-exceeded="false"/>                   
        </session-management>
    </http>

    <authentication-manager alias="authenticationManager">
        <authentication-provider user-service-ref="userService" />
    </authentication-manager>

    <user-service id="userService">
         <user name="foo" password="bar" authorities="ROLE_USER"/>
    </user-service>
</beans:beans>

web.xml

<web-app version="2.5" 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_2_5.xsd">
    <display-name>PM app</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:app-service-context.xml
            classpath:app-dao-context.xml            
            /WEB-INF/app-web-security.xml    
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener>

    <servlet>
        <servlet-name>pmapp-web</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>app-web</servlet-name>
        <url-pattern>/app/*</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>3</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

    <mime-mapping>
        <extension>js</extension>
        <mime-type>text/javascript</mime-type>
    </mime-mapping>

    <filter>
        <filter-name>urlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>urlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <resource-ref>
        <res-ref-name>jdbc/App</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <mapped-name>App</mapped-name>
    </resource-ref>
</web-app>

I want the user to be able to either login after n minutes (unblock) or set the number of attempts before blocking the user. Any other idea is welcome.

I'm using spring 3.0.6.RELEASE and spring-security 3.0.6.RELEASE

Thanks!

回答1:

Try Spring Security 3.0.7.RELEASE. That fixed the exact same problem for me.



回答2:

Spring security does not block a user after 3 unsuccessful attempts. You can implement yr own though.

Max concurrent sessions simply restricts the number of simultaneous separate different logins for a single user.