How can i Check if logged in user is admin or members of the administrators group in javascript | Community
Skip to main content
manank71376227
Level 2
December 15, 2015
Solved

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

  • December 15, 2015
  • 6 replies
  • 3466 views

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.
Best answer by edubey

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
December 15, 2015

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

Kunal_Gaba_
December 15, 2015

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}}
kautuk_sahni
Community Manager
Community Manager
December 16, 2015

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

Kautuk Sahni
kautuk_sahni
Community Manager
Community Manager
December 16, 2015

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
Kunal_Gaba_
December 17, 2015

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. 

kautuk_sahni
Community Manager
Community Manager
December 17, 2015

Hi Kunal,

Thank you, i got this now. 

It really help. 

Thanks and Regards

Kautuk Sahni

Kautuk Sahni