您好,我正在使用 Spring,但在尝试使用并发控制和身份验证失败 URL 时遇到问题。
我尝试做到同一用户不能同时登录应用程序。为此,我在 security.xml 中将并发控制定义为:
<concurrency-control max-sessions="1" error-if-maximum-exceeded="true" expired-url="/login_page?login_timeout=1"/>
我的想法是当第二个用户尝试登录时,应该使用以下内容调用登录页面:
- login_page?login_max_session_exceed=1"
我也有一个表单登录:
<form-login login-page="/login_page" default-target-url="/index.jsp"
authentication-failure-url="/login_page?login_error=1" />
但是我遇到的问题是,当我尝试登录第二个用户时,登录页面总是被调用
- login_page?login_error=1"(过期网址不会重定向)
有什么问题吗?当第二个用户尝试连接时,如何使用过期网址重定向。
我使用的spring版本是:
Spring.core 3.2.8 和 Spring.security 3.2.3
我的 web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Sistema de Despacho de Contingencia Acindar</display-name>
<servlet>
<servlet-name>sdca-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sdca-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<!-- Spring Security -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/sdca-security.xml
</param-value>
</context-param>
<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>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
我的 security.xml
<http auto-config="true">
<form-login login-page="/login_page" default-target-url="/index.jsp"
authentication-failure-url="/login_page?login_error=1" />
<logout logout-success-url="/login_page?logout=1" invalidate-session="true" delete-cookies="JSESSIONID" />
<session-management invalid-session-url="/login_page"
session-authentication-error-url="/login_page?login_max_session_exceed=1">
<concurrency-control max-sessions="1"
error-if-maximum-exceeded="true" expired-url="/login_page?login_timeout=1"/>
</session-management>
<intercept-url pattern="/login_page" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<intercept-url pattern="/**" access="ROLE_ADMIN" />
</http>
感谢您的帮助!
最佳答案
这里的一些配置选项似乎有点困惑。首先,expired-url
属性不相关,因为您将多次登录视为错误。仅当您允许第二次登录时才适用,这将导致第一次登录“过期”。查看 the namespace configuration 的文档.
session-authentication-error-url
属性也不适用于此。引用the manual :
The second login will then be rejected. By “rejected”, we mean that the user will be sent to the authentication-failure-url if form-based login is being used. If the second authentication takes place through another non-interactive mechanism, such as “remember-me”, an “unauthorized” (402) error will be sent to the client. If instead you want to use an error page, you can add the attribute
session-authentication-error-url
to the session-management element.
因此,只有在使用“记住我”身份验证之类的功能时才会使用它。
关于java - Spring Security/expired-url 无重定向 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23421099/