There are safe ways to get and assume the users identity in JSP via a SOAP call in a Zimlet. I wouldn't rely on the appCtxt.get(ZmSetting.USERNAME) call in Javascript as this could potentially be spoofed.
Instead, I use a combination of methods that rely on a few things:
1) That Zimbra will not serve a .JSP page without a valid ZM_AUTH_TOKEN.
2) That you can get the users name with a valid ZM_AUTH_TOKEN
3) That you can limit access to external pages by IP address
For instance, to validate a specific user, we:
1) Check for a a ZM_AUTH_TOKEN in a Zimlet .JSP
2) If the cookie exists, do a "GetInfoRequest" call to the Zimbra SOAP interface using that user's credentials.
3) Lock down the external code to only accept requests from the Zimbra server.
Here is the code we use to do the GetInfoRequest, to validate the user:
Code:
// Get the user attached to this authcookie
SoapHttpTransport trans = null;
trans = new SoapHttpTransport(soapurl);
trans.setAuthToken(authcookie);
Element trequest = Element.XMLElement.mFactory.createElement("GetInfoRequest").addAttribute("xmlns", "urn:zimbraAccount");
Element tresponse = trans.invoke(trequest);
String user = tresponse.getElement("name").toString(); Although this method doesn't pass the users credentials directly to the external page, it ensures that the request if from a valid user and that it is being called from the Zimbra server itself.
-Rob