spring limit max sessions ; limit max users

后端 未结 3 1815
你的背包
你的背包 2020-12-16 07:04

may i know possible to use spring security to limit max number of users able to login to website at the same time?

definately, not concurrent-session-control parame

3条回答
  •  清酒与你
    2020-12-16 07:35

    I do not have enough reputation to add a comment. But getAllPrincipals returns all principals including ones from expired sessions. Use some method like below to getAllActiveSessions.

    private List getActiveSessions(SessionRegistry sessionRegistry) {
        final List principals = sessionRegistry.getAllPrincipals();
        if (principals != null) {
            List sessions = new ArrayList<>();
            for (Object principal : principals) {
                sessions.addAll(sessionRegistry.getAllSessions(principal,     false));
            }
            return sessions;
        }
        return Collections.emptyList();
    }
    
        

    提交回复
    热议问题