Change guard expressions order
Check of allowed user sessions count moved to head for avoid unnecessary fetching all user sessions.
This commit is contained in:
parent
9cf3129d7a
commit
a362ab53bc
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -94,17 +94,17 @@ public class ConcurrentSessionControlAuthenticationStrategy
|
||||||
@Override
|
@Override
|
||||||
public void onAuthentication(Authentication authentication, HttpServletRequest request,
|
public void onAuthentication(Authentication authentication, HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
List<SessionInformation> sessions = this.sessionRegistry.getAllSessions(authentication.getPrincipal(), false);
|
|
||||||
int sessionCount = sessions.size();
|
|
||||||
int allowedSessions = getMaximumSessionsForThisUser(authentication);
|
int allowedSessions = getMaximumSessionsForThisUser(authentication);
|
||||||
if (sessionCount < allowedSessions) {
|
|
||||||
// They haven't got too many login sessions running at present
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (allowedSessions == -1) {
|
if (allowedSessions == -1) {
|
||||||
// We permit unlimited logins
|
// We permit unlimited logins
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
List<SessionInformation> sessions = this.sessionRegistry.getAllSessions(authentication.getPrincipal(), false);
|
||||||
|
int sessionCount = sessions.size();
|
||||||
|
if (sessionCount < allowedSessions) {
|
||||||
|
// They haven't got too many login sessions running at present
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (sessionCount == allowedSessions) {
|
if (sessionCount == allowedSessions) {
|
||||||
HttpSession session = request.getSession(false);
|
HttpSession session = request.getSession(false);
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
|
|
Loading…
Reference in New Issue