How to Retrieve the Username from a PNAgent Site

New from Sam Jacobs!

Today, a user on the Citrix Web Interface forum asked how one goes about retrieving a user’s name. As this is something a Web Interface developer does on a daily basis, I was able to respond quite quickly with the answer. His next question was whether the username could be retrieved from a PNAgent site, as he wanted to perform some actions based on the logged in user.

That was another matter altogether, as the Authentication object which exists for a Web Interface site, does not exist for a PNAgent site. At the time I suggested that he use a cookie from the Netscaler logon screen to store the username (which I now realize would not have helped, since there isn’t any Netscaler logon screen for PNAgent). However, he was pretty insistent that there must be a way, and after giving it some more thought, I agreed with him.

So, after a few more hours of digging, I am happy to report that he was right, and it turns out to be quite simple to implement.

As with any development work, there is always more than one way to skin the proverbial cat, and the way I’ve done it is detailed below.

Make sure that you back up the original code before you begin. However, remember that all java modules in a directory will be compiled, so .java files need to either be backed up in a different directory, or be given a different extension.

Back up the file Enumeration.java in the directory InetpubwwwrootCitrixPNAgentapp_codePagesJavacomcitrixwipna.

At line #111 you should see:

AccessToken accessToken = enumRequest.getAccessToken();
SIDBasedToken sidToken = null;
if (accessToken instanceof SIDBasedToken) {
   sidToken = (SIDBasedToken)accessToken;
}

Add the bolded lines (Lines 2, 3 & 4) where indicated:

AccessToken accessToken = enumRequest.getAccessToken();
// save the userID in a session variable so we can use it anywhere
getWebAbstraction().setSessionAttribute("PNAUser",
   accessToken.getShortUserName());
SIDBasedToken sidToken = null;
if (accessToken instanceof SIDBasedToken) {
   sidToken = (SIDBasedToken)accessToken;
}

This creates a session variable that can be used in any module of the site. For example, if you wished to perform some action for the user after applications have been enumerated, you can add the bolded line (Line 3) to the end of enum.aspx:

<%
(new com.citrix.wi.pna.Enumeration(pnaContext, null)).perform();
string userID = Session["PNAUser"] + "";
// perform other actions based on userID ...
%>

Thanks Sam!

TAGS