Skip to main content
manank71376227
Level 2
Dec 15, 2015 8:59 AM UTC
Solved

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

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
edubey
edubeyAccepted solution
Level 10
Dec 15, 2015 2:25 PM UTC

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

6 replies

edubey
edubeyAccepted solution
Level 10
Dec 15, 2015 2:25 PM UTC

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

Translate
Kunal_Gaba_
New Member
Dec 15, 2015 7:00 PM UTC

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:{%22groupName%22:%22administrators%22}}
Translate
kautuk_sahni
Level 9
Dec 16, 2015 10:35 AM UTC

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-manager.topic.html/forum__ujsa-hi_team_i_needt.html

I hope this would help you.

Thanks and Regards

Kautuk Sahni

Translate
Kautuk Sahni
kautuk_sahni
Level 9
Dec 16, 2015 10:40 AM UTC

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

Translate
Kautuk Sahni
Kunal_Gaba_
New Member
Dec 17, 2015 1:11 AM UTC

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. 

Translate
kautuk_sahni
Level 9
Dec 17, 2015 6:33 AM UTC

Hi Kunal,

Thank you, i got this now. 

It really help. 

Thanks and Regards

Kautuk Sahni

Translate
Kautuk Sahni