public class RunAsAdminUtil extends BaseScopableProcessorExtension {
/**
* This method runs javascript function with Admin privileges
* @param func
*
*/
public void runAsAdmin(final Function func) {
final Context cx = Context.getCurrentContext(); final Scriptable scope = getScope();
RunAsWork raw = new RunAsWork() {
public Object doWork() throws Exception {
func.call(cx, scope, scope, new Object[] {}); return null;
}
};
AuthenticationUtil.runAs(raw,
AuthenticationUtil.getSystemUserName());
}
}
Below is the *-contex.xml entry,
runAsAdminUtil
Below is the code of javascript where you would be using custom created javascript api to run function with admin privileges
function main() { if (!people.isAdmin(person)) { //if current logged in user is not admin run function with admin privileges runAsAdminUtil.runAsAdmin(createGroupsDynamically); }else{ createFolderStructureFromTemplate(); } } var createGroupsDynamically = function createGroupsDynamically() { var name = document.properties.name; var TEST_READ = name + ‘_read’; var TEST_WRITE = name + ‘_write’; people.createGroup(TEST_READ); people.createGroup(TEST_WRITE); } main();
Get free consultation and let us know your project idea to turn
it into an amazing digital product.