Skip to content

Instantly share code, notes, and snippets.

@gayashanbc
Created September 26, 2019 13:04
Show Gist options
  • Save gayashanbc/23ca973dfd4bb00694c8bc52558f2fb4 to your computer and use it in GitHub Desktop.
Save gayashanbc/23ca973dfd4bb00694c8bc52558f2fb4 to your computer and use it in GitHub Desktop.
Adaptive JS Script for Active Sessions Limit Handler
// 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());
executeStep(2, {
authenticatorParams: {
local: {
SessionExecutor: {
MaxSessionCount: '1'
}
}
}
}, {});
}
}
});
}
// End of Concurrent-Session-Management.......
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment