I'm trying to accomplish something similar found in this post.
I have this in my "scripts.js" file:
use(function() { var resolver = resource.getResourceResolver(); var session = resolver.adaptTo(Packages.javax.jcr.Session); var userManager = resolver.adaptTo(Packages.org.apache.jackrabbit.api.security.user.UserManager); var auth = userManager.getAuthorizable(session.getUserID()); var groups = auth.memberOf(); return { isAnonymous: isAnonymous, groups: groups }; });
And in my component, I have this:
<ul data-sly-use.user="scripts.js" data-sly-list="${user.groups}"> <li>${itemList.index}: ${item}</li> </ul>
It's just displaying an index list of blank items:
Any ideas?
Thanks in advance!
Solved! Go to Solution.
Try this, It works
use(function() { var resolver = resource.getResourceResolver(); var session = resolver.adaptTo(Packages.javax.jcr.Session); var userManager = resolver.adaptTo(Packages.org.apache.jackrabbit.api.security.user.UserManager); var auth = userManager.getAuthorizable(session.getUserID()); var groups = auth.memberOf(); return { groups: groups }; });
<ul data-sly-use.user="file.js" data-sly-list="${user.groups}"> <li>${itemList.index}: ${item.principal.name} </li> </ul>
Try this, It works
use(function() { var resolver = resource.getResourceResolver(); var session = resolver.adaptTo(Packages.javax.jcr.Session); var userManager = resolver.adaptTo(Packages.org.apache.jackrabbit.api.security.user.UserManager); var auth = userManager.getAuthorizable(session.getUserID()); var groups = auth.memberOf(); return { groups: groups }; });
<ul data-sly-use.user="file.js" data-sly-list="${user.groups}"> <li>${itemList.index}: ${item.principal.name} </li> </ul>
You can do it even shorter:
I appreciate the responses everyone! @edubey, how did you know that "principal.name" was available?
Views
Replies
Total Likes
There is no rocket science here....just check returned object type :)
userManager.getAuthorizable(session.getUserID()); returns object of this class https://jackrabbit.apache.org/api/2.6/org/apache/jackrabbit/api/security/user/Authorizable.html which has method getPrincipal which has getName method
Reference:
https://jackrabbit.apache.org/api/2.6/org/apache/jackrabbit/api/security/user/UserManager.html
https://jackrabbit.apache.org/api/2.6/org/apache/jackrabbit/api/security/user/Authorizable.html
http://docs.oracle.com/javase/6/docs/api/java/security/Principal.html?is-external=true
Views
Replies
Total Likes
Ah thanks - makes sense! :)
Views
Replies
Total Likes