Refresh user's Roles without logging out

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2021 10:38 PM
Hey everyone,
I'm looking at building an "Elevate to Admin" tool which will let our developers have a single account, without being granted Admin until they need it in Production. I've found some mentions online for a "GlideSecurityManager" API which is "undocumented" but in theory, should do what I need. (found here: https://snprotips.com/undocumented-servicenow-apis)
I am creating a "sys_user_has_role" record for a user, with the role of Admin, and would love to let them not have to log out and back in to apply these changes.
Does anyone know exactly how to use the GlideSecurityManager API? I've tried a few ways - Background script, BR on sys_user_has_role, Flow Designer Action, and none seem to work. e.g.
Any help is appreciated,
Thanks,
Andrew
- Labels:
-
Instance Configuration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2021 01:18 AM
Hi Andrew,
Did the above comments work for you?
Thanks
Aishwarya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2021 05:13 AM
I'm not sure if it is in line with what you are trying to do, but according to your example you are trying to work with the current user, so maybe
var gsm = GlideSecurityManager.get();
gsm.enableElevatedRole('< role needing elevation >');
will enable you to achieve your goal?
If I run the script in Scripts - Background, with security_admin as parameter, the role is "turned on". I am able to edit ACLs (without using the profile menu item).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2024 06:25 AM
Hey Andrew,
had a similar use case and got to know that getUserByID() returns an object of GlideUser type which can be used to refresh the session of that loaded user. Attaching a screenshot of the same if that helps.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2024 01:25 AM
Hi Andrew, appreciate you may well have resolved/moved on with this, but i've recently built something similar to grant admin privileges temporarily. The problem has always been elevating privileges in a script to then add the role. The below is how I have got it working in a script action within flow;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2024 02:01 AM
Do you make sure that the job that assigns roles of the group to the user is finished by the time you try to reset the session?
That is an asynchronous job and if you run your reset code before that (highly likely), the session will in fact be reset, but the new roles are not yet created by then.