Getting current username when rendering a velocity template.

I am looking for a way to get the current user’s username or any information about the user when rendering a velocity template.

Ideally if i were logged into the system and published a page “mgurtzweiler” would be the username printed out by something in the velocity template.

I’ve checked the available $sys, $rx, or $user bindings inside the template but nothing about the current user seems to be available.

I dug around and found this page:

/Rhythmyx/sys_psxCms/userinfo.xml

which returns the following XML when I load it up.

<PSXUserInfo SecurityProvider="" SecurityProviderInstance="" SecurityProviderTypeId="">
<SessionId>someid</SessionId>
<UserName>mgurtzweiler</UserName>
<CommunityId>someId</CommunityId>
<Locale>en-us</Locale>
<Roles>
<Role>Admin</Role>
</Roles>
<SessionTimeOut>7200</SessionTimeOut>
</PSXUserInfo>

But if I pull in that page via the $rs command:

$rx.doc.getDocument("/Rhythmyx/sys_psxCms/userinfo.xml")

So it seems the current “user” when the velocity template is rendered is the rxserver.

<PSXUserInfo SecurityProvider="" SecurityProviderInstance="" SecurityProviderTypeId="">
<SessionId>someId</SessionId>
<UserName>rxserver</UserName>
<CommunityId/>
<Locale/>
<Roles>
<Role>Admin</Role>
</Roles>
<SessionTimeOut>7200</SessionTimeOut>
</PSXUserInfo>

So, any way to do this?

I don’t think this is possible. During the publishing context the current user at the point is and always will be rxserver. You can simulate the context for publishing when previewing a page by changing the sys_context parameter in the URL to 1 if you want to do some more poking around. Can you provide a more detailed explanation on what you are trying accomplish or have i completely missed it?

We use on demand publishing so a user will select a specific content item in Rx, and say “Publish” in the context menu for that item. The menu command runs an edition which creates a call out to “our” content system’s web service which then makes the page available on our website. Sometimes there are errors within the web service call and the Publish.jsp page that shows up in the popup window never knows about these, it is happy as soon as the edition runs.

I wanted to put the username of the person who started the edition into the soap message so i could simply email them if there was some kind of error in our system. The velocity template’s come into play because they format the payload of the soap message passed to the web service.

6.7’s publishing uses ajax to give more information to the end user about the publishing run (ie what its doing, and once it completes if there are errors). You may or may not be able to port that back (or something similar) to 6.52. If i recall correctly, it goes against /Rhythmyx/publisher/status?edition=[edition number] to see the status of the publishing run (See: /Rhythmyx/sys_resources/js/publishing.js). However I don’t know if those files and features exist in 6.52…

We have modified their generic publish now feature to suit our needs (by incorporating the above mention ajax feature), but the popup window (when you hit the publish now on an item) does provide information on what is happening in the publishing run (including failures if they occur).

Are you using 6.7 or 6.52?

Much like what jitendra said, if you are using 6.7 you could modify the generic publishing.jsp to supply you with the current user by simply calling:

String userName = request.getRemoteUser();

This is just an idea…but now that the username is known, could you possibly pass it as a parameter to the template from the JSP?

As for 6.52… I’m not totally sure.