Run Javascript Function as Admin Privileges

Sep 23rd, 2013

Run Javascript Function as Admin Privileges

Share

  • In Alfresco, create group, user, add user to group, set permission are allowed only to Admin group users.
  • Many times we get a requirement where we need to create group and users dynamically on some action.
  • Now javascript API are available to create group but works only for Admin group users.
  • I had a requirement to create groups dynamically when rule is executed. But rule was executed action taken by non-admin user.
  • So I created custom javascript API to run entire javascript function as Admin privileges.
  • For this you have to create one Java class which extends BaseScopableProcessorExtension. BaseScopableProcessorExtension class is extended whenever you want to create custom javascript API.
  • Register your javascript API in *-context.xml
  • Then use your API in your javascript.

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();

Comments are closed.

Let's Discuss Your Project

Get free consultation and let us know your project idea to turn
it into an amazing digital product.

Let’s talk

NEWS & BLOG

Related Blogs

Why should you hire React Native developers for your project?

Hire Developer Jun 19th, 2023

Why should you hire React Native developers for your pr...

Read more
Explorando A 1xbet: Uma Análise Detalhada Da Plataforma Sobre Apostas Online

Hire Developer Feb 24th, 2023

Explorando A 1xbet: Uma Análise Detalhada Da Plataform...

Read more
Explorando A 1xbet: Uma Análise Detalhada Da Plataforma Sobre Apostas Online

Hire Developer Feb 23rd, 2023

Explorando A 1xbet: Uma Análise Detalhada Da Plataform...

Read more

INQUIRY

Let's get in touch

UNITED STATES

31236 Meadowview Square,
Delmar, DE 19940, USA

Sales: +1 667 771 6758

UNITED KINGDOM

13 Layton Road, Hounslow,
London, TW3 1YJ

Sales: +44 7404 607567

INDIA

2nd Floor, Sun Avenue One, Bhudarpura, Ayojan Nagar, Nr. Shyamal Cross Road, Ahmedabad, Gujarat-380006

Sales: +91 635-261-6164

For Project Inquiries

biolah

depo 25 bonus 25 to 5x

depo 25 bonus 25

depo 25 bonus 25

mndrmndr.com

bonusdeposit.net

https://www.greentourstanzania.com/wp-includes/customize/

https://temp1.novotest.biz/id/

depo 25 bonus 25

https://sumberjo-blitar.desa.id/images

https://sumberjo-blitar.desa.id/data

depo 25 bonus 25 to 5x

depo 25 bonus 25

https://www.greentourstanzania.com/wp-includes/js/product/

https://smpabbs.sch.id/gacor/100/

https://smpabbs.sch.id/gacor/bonus/

deposit 25 bonus 25

depo 25 bonus 25

bonus new member 100

https://ppdb.smk-kosgoro.sch.id/data/depo 25 bonus 25https://jesus.nouvellevie.com/wp-includes/images/Getoko.iddepo 25 bonus 25https://bonus-baru.s3.ap-southeast-1.amazonaws.com/link-daftar-slot-gacor.htmlhttps://bonus-baru.s3.ap-southeast-1.amazonaws.com/scatter-pink-paling-gacor.htmlhttps://worldlisteningproject.org/wp-includes/depo25bonus25/bonus new member 100depo 25 bonus 25