我想使用spring security来处理会话并发。我希望防止登录相同的帐户。到目前为止,我所做的是通过实施AuthenticationProvider
的身份验证部分。我重写authenticate()
方法,我认为现在认证过程很好。我的下一步是添加会话concurreny。我在我的春天xml中添加了这个:
<beans:bean id="loginAuthenticator" class="[...]" />
<sec:http auto-config='true'>
<sec:intercept-url pattern="/login.do" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<sec:intercept-url pattern="/**" access="ROLE_USER" />
<sec:form-login login-page="/login.do" login-processing-url="/j_spring_security_check" default-target-url='/home.do' always-use-default-target='true'/>
<sec:logout logout-success-url="/login.do"/>
<sec:session-management session-fixation-protection="migrateSession" session-authentication-error-url="/login.do" invalid-session-url="/login.do">
<sec:concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
</sec:session-management>
</sec:http>
<sec:authentication-manager>
<sec:authentication-provider ref='loginAuthenticator' />
</sec:authentication-manager>
我已尝试登录相同的帐户,但仍然可以通过。你能告诉我我错过了什么吗?我需要实现或扩展一些东西吗?我的xml配置错了吗?
感谢。
编辑:按要求登录
INFO: Initializing Coyote HTTP/1.1 on http-8080
Apr 04, 2013 4:40:15 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
INFO : com.addressbook.controllers.LoginController - ----------> LoginController - displayLoginPage()
INFO : com.addressbook.security.LoginAuthenticator - ----------> authenticate() - authenticating user credentials
INFO : com.addressbook.utils.HashService - ----------> finally block hashing function
INFO : com.addressbook.security.LoginAuthenticator - ----------> username: testuser1
INFO : com.addressbook.security.LoginAuthenticator - ----------> password: 6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090
INFO : com.addressbook.security.LoginAuthenticator - ----------> user xml file path: C:\Users\jlim\addressbook\xml\users.xml
INFO : com.addressbook.security.LoginAuthenticator - ----------> reached finally block fetchUsers: [com.addressbook.pojos.User@2061b97c, com.addressbook.pojos.User@6fd88c7f, com.
addressbook.pojos.User@71f01f36]
INFO : com.addressbook.security.LoginAuthenticator - ----------> user exists?: true
INFO : com.addressbook.controllers.LoginController - ----------> LoginController - showHomePage()
INFO : com.addressbook.controllers.LoginController - ----------> LoginController - user from session: testuser1
INFO : com.addressbook.dao.impl.ContactDaoImpl - ----------> contacts xml file path: C:\Users\jlim\addressbook\xml\contacts.xml
INFO : com.addressbook.dao.impl.ContactDaoImpl - ----------> reached finally block fetchContactsFromXml(): [com.addressbook.pojos.Contact@32983d64, com.addressbook.pojos.Contact@28e68a
2f, com.addressbook.pojos.Contact@377a28a3]
INFO : com.addressbook.controllers.LoginController - ----------> LoginController - displayLoginPage()
INFO : com.addressbook.security.LoginAuthenticator - ----------> authenticate() - authenticating user credentials
INFO : com.addressbook.utils.HashService - ----------> finally block hashing function
INFO : com.addressbook.security.LoginAuthenticator - ----------> username: testuser1
INFO : com.addressbook.security.LoginAuthenticator - ----------> password: 6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090
INFO : com.addressbook.security.LoginAuthenticator - ----------> user xml file path: C:\Users\jlim\addressbook\xml\users.xml
INFO : com.addressbook.security.LoginAuthenticator - ----------> reached finally block fetchUsers: [com.addressbook.pojos.User@5bdb1d55, com.addressbook.pojos.User@e62e690, com.a
ddressbook.pojos.User@7f0eff50]
INFO : com.addressbook.security.LoginAuthenticator - ----------> user exists?: true
INFO : com.addressbook.controllers.LoginController - ----------> LoginController - showHomePage()
INFO : com.addressbook.controllers.LoginController - ----------> LoginController - user from session: testuser1
INFO : com.addressbook.dao.impl.ContactDaoImpl - ----------> contacts xml file path: C:\Users\jlim\addressbook\xml\contacts.xml
INFO : com.addressbook.dao.impl.ContactDaoImpl - ----------> reached finally block fetchContactsFromXml(): [com.addressbook.pojos.Contact@2971bd51, com.addressbook.pojos.Contact@6a4426
18, com.addressbook.pojos.Contact@20212829]
答案 0 :(得分:1)
您是否在web.xml
中添加了听众?:
<listener>
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher
</listener-class>
</listener>
另外,请查看documentation(版本3.2,但在3.x中相同)