Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How can i Check if logged in user is admin or members of the administrators group in javascript

Avatar

Level 2

Hi,

I want to show button on page if logged in user is admin or members of the administrators group in javascript.

I am able to get CQ.User.getCurrentUser() but not able to check if user is admin.

1 Accepted Solution

Avatar

Correct answer by
Level 10

I guess there in no ootb feature, but you can write a simple servlet and make a ajax call. That would be easy.

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

I guess there in no ootb feature, but you can write a simple servlet and make a ajax call. That would be easy.

Avatar

Employee Advisor

The following URI returns all the users who are member of 'administrators' group. You can check the existence current user Id in the JSON response returned by the URI- 

http://localhost:4502/libs/granite/security/search/authorizables.json?query={%22scope%22:{%22groupNa...

Avatar

Administrator

Hi

As mentioned by Praveen, you can achieve the desirable by creating custom service or component.

For more reference please have a look at this forum post :- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

I hope this would help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Administrator

Hi Kunal

I have tried the link specified by you with my test user, but i am not getting the desirable result.

Test user :- "Administrator","home":"/home/users/9/xxxxx"}],"total":2}  (only ending of json response)

Admin User:-  "Administrator","home":"/home/users/9/xxxxx","isImpersonated":false}],"total":2} (only ending of json response, rest all was same.)

 

Could you please help me in understanding it ?

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Employee Advisor

Hi Kautuk, 

The JSON response lists the properties of the user who are member of administrators group. I get the following response back - 

{"authorizables":[{"type":"user","authorizableId_xss":"replication-receiver","authorizableId":"replication-receiver","name_xss":"replication-receiver","name":"replication-receiver","home":"/home/users/system/replication-receiver"},{"type":"user","authorizableId_xss":"admin","authorizableId":"admin","name_xss":"Administrator","name":"Administrator","home":"/home/users/w/wFeT8_d9GMvkvT7eHVMg","isImpersonated":false}],"total":2}

 

As you can see the "type" property of the 2 objects in the json is "user" and the id of the user or name is represented by "authorizableId" property. We can simply check if the returned list of users in the json has the same name as the logged in user name. 

Avatar

Administrator

Hi Kunal,

Thank you, i got this now. 

It really help. 

Thanks and Regards

Kautuk Sahni



Kautuk Sahni