I have requirement to get author name who has created the page. I am able to get fetch pageProperties.jcr:createdBy but its giving me author user Id. I want the actual name of the author(full name). How we can achieve this.
Solved! Go to Solution.
Views
Replies
Total Likes
This is an example User profile. The user ID is set in pageproperties jcr:createdBy
This is the user data in CRX stored. You need to fetch the user familyName and givenName.
Now when this user is creating a page userID will place in pageProperties.jcr:createdBy
Read this user ID and place it in Java code
UserManager userManager = request.getResourceResolver().adaptTo(UserManager.class);
Authorizable authorizable = userManager.getAuthorizable("userID");
Now actually you will know the actual user profile path by
authorizable.getPath()
Now resolve the resource and get the necessary values:
String fName = request.getResourceResolver().getResource(authorizable.getPath() + "/profile").getValueMap().get("givenName", "");
String lName = request.getResourceResolver().getResource(authorizable.getPath() + "/profile").getValueMap().get("familyName", "");
Note: You might not have access to read value under /home/users/ except for the administrator user role. In that case, you can create a service user instead of request.getResourceResolver() use only resourceResolver which has the permission of the service user.
Hello you can do it in 2 ways:
Follow this document: https://www.albinsblog.com/2015/03/how-to-get-userinfo-through-java-api-in.html#.ZDfbs9JBxH4
Or,
You can use this code snippet
UserManager userManager = request.getResourceResolver().adaptTo(UserManager.class);
Authorizable authorizable = userManager.getAuthorizable("userIDFromCRX");
String fName = request.getResourceResolver().getResource(authorizable.getPath() + "/profile").getValueMap().get("givenName", "");
User data in CRX: /home/users/we-retail/DSCP-athB1NYLBXvdTuN
Hi @Sady_Rifat can give more insight on this i am new to this concept
This is an example User profile. The user ID is set in pageproperties jcr:createdBy
This is the user data in CRX stored. You need to fetch the user familyName and givenName.
Now when this user is creating a page userID will place in pageProperties.jcr:createdBy
Read this user ID and place it in Java code
UserManager userManager = request.getResourceResolver().adaptTo(UserManager.class);
Authorizable authorizable = userManager.getAuthorizable("userID");
Now actually you will know the actual user profile path by
authorizable.getPath()
Now resolve the resource and get the necessary values:
String fName = request.getResourceResolver().getResource(authorizable.getPath() + "/profile").getValueMap().get("givenName", "");
String lName = request.getResourceResolver().getResource(authorizable.getPath() + "/profile").getValueMap().get("familyName", "");
Note: You might not have access to read value under /home/users/ except for the administrator user role. In that case, you can create a service user instead of request.getResourceResolver() use only resourceResolver which has the permission of the service user.
Views
Likes
Replies
Views
Likes
Replies