Grant Admin Access Via Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 05:06 AM
Hi All,
We have a catalog process where one can request for Admin access for a given window. This is generally used by our support teams to manage releases and issues on Production.
It was working fine but now it has stopped working after the version upgrade.
Here is the script that I am using, earlier this was in the workflow run script activity, i changed it to a script include and still it did not work, Now I changed this to a script action but it is still not working.
I am getting all the logs.
**************************************************
var usr = event.parm1;
gs.log('usr= '+usr);
//session.onlineImpersonate("admin");
var adminRole = '';
var roleGR = new GlideRecord('sys_user_role');
roleGR.addQuery('name', 'admin');
roleGR.query();
if (roleGR.next()) {
gs.log('2');
adminRole = roleGR.sys_id;
}
gs.log('adminRole= '+adminRole);
var grUserRoleGR = new GlideRecord("sys_user_has_role");
grUserRoleGR.intialize();
grUserRoleGR.user = usr;
grUserRoleGR.role = '' + adminRole;
grUserRoleGR.state = 'active';
grUserRoleGR.inherits = true;
gs.log('3');
grUserRoleGR.insert();
***********************************************
I think the issue is that now to give admin access one should have admin themselves, how to get past this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 09:26 AM
You may need to try to Elevate Privilege, before assigning the Admin role.
Sample script below:
gs.getSession().impersonate('ea898b00233ba610b22961b64254c0ab'); // impersonate user with security_admin role, that is your admin account
GlideSecurityManager.get().enableElevatedRole('security_admin'); //elevate to security_admin
//do things here that require elevation