You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Guillaume Lucazeau <gl...@gmail.com> on 2016/03/16 15:24:51 UTC
Display user node properties
Hello,
I would need to display some properties from a user node, for now the
displayName property.
I need it for the current logged in user, the users that have jcr:write
privileges on a resource, and also for the "lastModifiedBy" property of a
resource.
I know how to get privileges list in JSON, and I can get properties like
this:
Session session = resourceResolver.adaptTo(Session.class);
UserManager userManager = AccessControlUtil.getUserManager(session);
Authorizable auth = userManager.getAuthorizable(session.getUserID());
Value[] names = auth.getProperty("displayName");
String displayName = names[0].toString();
Sometimes I can write the displayName directly in the view from JSP code,
some other times I would need to get it in JSON because this would
refreshed with an Ajax call.
Is it possible to get the displayName in a JSP just by adapting some
resources? I couldn't find how. The usermanager bundle provided as an
example does this:
function displayName(path) {
var res = request.getResourceResolver().resolve(path);
var resValueMap =
res.adaptTo(Packages.org.apache.sling.api.resource.ValueMap);
var value = resValueMap.get("displayName");
if (value == null) {
value = path.substring(path.lastIndexOf('/') + 1)
}
return value;
}
But I don't know how to get the path to the user node from this:
${slingRequest.remoteUser}
Is it a good idea to create a service to return an Authorizable or
displayName from a user ID, and store this displayName value on my model,
to easily get it in a JSP (<c:out var="${model.lastmodifiedByDisplayName}"
/>
What would be the best way to map the IDs returned by <some
resource>.eacl.json to their displayName ?
Thank you very much for your help
Regards,
Guillaume