spring

spring,第1张

spring

我想知道你是

you are following the correct path
因为用户会话无效

    usersSessions.forEach((session) -> {     sessionRegistry.getSessionInformation(session.getId()).expireNow();    });

注意事项

SessionInformation.expireNow()

并不意味着要从

redis
数据库中删除条目,它只是将您已提到的过期属性附加到会话。

但是,这如何使用户会话无效?

这是ConcurrentSessionFilter发挥作用的地方,

.doFilter()
方法实现了
automatically logging out

这是 ConcurrentSessionFilter* 的代码段 *

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)        throws IOException, ServletException {    HttpServletRequest request = (HttpServletRequest) req;    HttpServletResponse response = (HttpServletResponse) res;    HttpSession session = request.getSession(false);    if (session != null) {        SessionInformation info = sessionRegistry.getSessionInformation(session     .getId());        if (info != null) { if (info.isExpired()) {     // Expired - abort processing     doLogout(request, response);     String targetUrl = determineExpiredUrl(request, info);     if (targetUrl != null) {         redirectStrategy.sendRedirect(request, response, targetUrl);         return;     }     else {         response.getWriter().print(      "This session has been expired (possibly due to multiple concurrent "   + "logins being attempted as the same user).");         response.flushBuffer();     }     return; } else {     // Non-expired - update last request date/time     sessionRegistry.refreshLastRequest(info.getSessionId()); }        }    }    chain.doFilter(request, response);}

为此加油!



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4893887.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存