AEM6.5 how to get user details and the groups the user is associated to in author environment | Community
Skip to main content
srinivas_chann1
Level 7
Jan 5, 2021 6:32 AM UTC
Solved

AEM6.5 how to get user details and the groups the user is associated to in author environment

Hi,

 

Once any user  logs in to the author environment how could I get the details of the groups the user is member of.

 

I am using js so wanted to check if there is any json available through which I could get this details. Instead of me building a new code for this.

 

I noticed that for authorizables.json  we need to provide the username.

http://localhost:4502/bin/security/authorizables.json?filter=username&_charset_=utf-8

 

Now if is the case i would need a way to find the user name in the js and then again send the request. 

 

Please let me know as I could resolve this in a better way .

 

 

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
shelly-goel
shelly-goelAccepted solution
Employee
Jan 5, 2021 7:47 PM UTC

@srinivas_chann1 

In js, you can get the user as Granite.author.ContentFrame.getUserID()

Please refer to the function getUserGroups() here:

http://experience-aem.blogspot.com/2019/09/aem-6510-authoring-restrict-msm-rollout-to-specific-user-groups.html

3 replies

shelly-goel
shelly-goelAccepted solution
Employee
Jan 5, 2021 7:47 PM UTC

@srinivas_chann1 

In js, you can get the user as Granite.author.ContentFrame.getUserID()

Please refer to the function getUserGroups() here:

http://experience-aem.blogspot.com/2019/09/aem-6510-authoring-restrict-msm-rollout-to-specific-user-groups.html

Translate
srinivas_chann1
Level 7
Jan 6, 2021 8:35 AM UTC

I did the below to solve the issue 

 

 

function getLoggedInUserID() {
var currentUserId = "";
var currentUserInfo;
var CURRENT_USER_JSON_PATH = Granite.HTTP.externalize('/libs/granite/security/currentuser.json');
var result = Granite.$.ajax({
type: "GET",
async: false,
url: CURRENT_USER_JSON_PATH
});

if (result.status === 200) {
currentUserInfo = JSON.parse(result.responseText);
currentUserId = currentUserInfo.authorizableId;
}
return currentUserId;
}

 

 

function getUserGroups(userID){

var isMemberOfGroupEveryOne=false;

$.ajax({
url: "/bin/security/authorizables.json?filter=" + userID +'&_charset_=utf-8',
async: false,
success: function(result) {


if (result) {
$.each(result.authorizables,function(index,authObj){


if( (authObj.id !== userID)){
return;
}else {

$.each(authObj.memberOf,function(index,memberOf){
if(memberOf.id === 'everyone'){
isMemberOfGroupEveryOne=true;
}
});


}

});
}

}
});

 


return isMemberOfGroupEveryOne;
}

Translate
Suraj_Kamdi
New Participant
Jan 5, 2021 6:47 AM UTC

@srinivas_chann1 

I would suggest using the service user to get the details of AEM user/groups. Make use of Authorizable API

https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/javadoc/org/apache/jackrabbit/api/security/user/Authorizable.html 

 

see the following code snippet

 

 

public static Group getGroup(String userId, UserManager userManager) { try { return (Group) userManager.getAuthorizable(userId); } catch (RepositoryException e) { logger.error("Error {}", e); } return null; }

 

 

Translate