java 如何在登录屏幕上重定向 Spring 安全并发会话控制“消息”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10328290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:35:36  来源:igfitidea点击:

How to redirect Spring security concurrent session control 'message' on login screen?

javaspringjakarta-eespring-securityspring-webflow

提问by DHRUV BANSAL

I have web application, in which I have used Spring framework. For the concurrent session control I have use spring feature where only 1 logged in session will be maintained for 1 user as soon as that user logs in to another session , he/her previous session will be expired.

我有 Web 应用程序,其中使用了 Spring 框架。对于并发会话控制,我使用了 spring 功能,其中只要 1 个用户登录到另一个会话,就会为 1 个用户维护 1 个登录会话,他/她之前的会话将过期。

Now in this case I am getting this message "This session has been expired (possibly due to multiple concurrent logins being attempted as the same user)."

现在在这种情况下,我收到此消息“此会话已过期(可能是由于以同一用户身份尝试多个并发登录)。

But I get this message on complete white page on browser. I want this message to come on my login screen only.

但是我在浏览器的完整白页上收到此消息。我希望这条消息只出现在我的登录屏幕上。

Here is the part of my spring security xml where I have handled concurrent session for user.

这是我为用户处理并发会话的 spring 安全 xml 的一部分。

<security:session-management invalid-session-url="/login.jsp?error=sessionExpired" session-authentication-error-url="/login.jsp?error=alreadyLogin">
                    <security:concurrency-control max-sessions="1" error-if-maximum-exceeded="false" />
</security:session-management>

Any links specially for customizing this message and redirecting this message on desired web application page will be appreciated.

任何专门用于自定义此消息并将此消息重定向到所需 Web 应用程序页面的链接将不胜感激。

Thanks in advance.

提前致谢。

采纳答案by DHRUV BANSAL

Original XML entry in spring-security.xml

spring-security.xml 中的原始 XML 条目

<security:session-management session-authentication-error-url="/login.jsp?error=alreadyLogin">
                    <security:concurrency-control max-sessions="1" error-if-maximum-exceeded="false" />
</security:session-management>

Just You have to added following parameter in xml to redirect the Login expired action or invalid session url

只是您必须在 xml 中添加以下参数以重定向登录过期操作或无效会话 url

expired-url="url value"

过期 url="url 值"

invalid-session-url="url value"

invalid-session-url="url 值"

Modified XML entry

修改后的 XML 条目

<security:session-management invalid-session-url="/login.jsp?error=sessionExpired" session-authentication-error-url="/login.jsp?error=alreadyLogin">
                    <security:concurrency-control max-sessions="1" expired-url="/login.jsp?error=sessionExpiredDuplicateLogin" error-if-maximum-exceeded="false" />
</security:session-management>

回答by tom

In the jar spring-security-core there are .properties files.

在 jar spring-security-core 中有 .properties 文件。

You will need to override the properties you want with your custom messages in your application.

您需要使用应用程序中的自定义消息覆盖所需的属性。