Created
September 26, 2019 13:32
-
-
Save gayashanbc/8be6cfbc9e3a83f42cca7fcb208b9be4 to your computer and use it in GitHub Desktop.
Limiting active user sessions using adaptive JS functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Concurrent-Session-Management from Template... | |
// This script will prompt concurrent session handling | |
// to one of the given roles | |
// If the user has any of the below roles, concurrent session handling will be prompted | |
// and it will either kill sessions or abort login based on number of active concurrent user sessions | |
var rolesToStepUp = ['admin', 'manager']; | |
var maxSessionCount = 1; | |
function onLoginRequest(context) { | |
executeStep(1, { | |
onSuccess: function (context) { | |
// Extracting authenticated subject from the first step | |
var user = context.currentKnownSubject; | |
// Checking if the user is assigned to one of the given roles | |
var hasRole = hasAnyOfTheRoles(user, rolesToStepUp); | |
if (hasRole) { | |
Log.info(user.username + ' Has one of Roles: ' + rolesToStepUp.toString()); | |
sessions = getUserSessions(user); | |
if(sessions.length >= 1) { | |
for(var key in sessions) { | |
terminateUserSession(user, sessions[key].id); | |
} | |
} | |
} | |
} | |
}); | |
} | |
// End of Concurrent-Session-Management....... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment