on 03-11-2010 3:56 PM
Hello all,
I have written some custom code that asks the user for data that will in turn get printed out.
I am able to create the Activity, Attach it to a button within a POD, it pops up fine and I can collect the data, but I cannot tell who the User was.
The request object has the SFC, Site Operation, etc, but no User information.
I also tried the session object, but that has no data at all.
Any ideas on how I would be able to get the Username?
Thanks,
Mike
Hello Mike,
Have you found a solution already? If so, please, share it with the community and close this thread.
Regards,
Alex.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can try this:
session.getAttribute(u201CLOGON_IDu201D);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I have changed the "Type" dropdown in the Activity Maintenance to each one with no luck.
EJB, Standalone GUI, Button/plugin GUI, and Native Executable.
The code in the jsp file I am calling is as follows:
UserBOHandle tempUserBOHandle = (UserBOHandle)request.getSession().getAttribute("USER_BO"); // this line throws NPE
out.println("Value = "tempUserBOHandle.getUser()"<br>"); // never gets here
It fails on the first line with a NPE because it does not exist.
When printing out the session elements I do not get any printouts:
java.util.Enumeration en = session.getAttributeNames();
while(en.hasMoreElements())
{
String paramName = (String) en.nextElement();
out.println(paramName + " = " + session.getAttribute(paramName) + "<br/>");
}
Any other thoughts?
Thanks,
Mike
The current user is the user which has been authenticated through JAAS and this user is referred to as Principal in J2EE world. It is the responsibility of the container to provide API to obtain the current user.
Such API exists for servlet API(Servlet.getUserPrinicipal) and EJB (EjbContext.getCallerPrincipal() which is injected as a SessionContext for session beans and EntityContext for entity beans).
java.security.Principal.getName() should return the user name.
Sorry but the explanation and code snipet does not quite make sense to me.
Could you please try to clarify it a little bit more for me? Perhaps some sample code might help?
Here is what I have tried in the jsp code:
<%
try
{
out.println("Getting Principal<br>");
java.security.Principal p = request.getUserPrincipal();
out.println("Got Principal<br>");
if(p == null)
out.println("Principal is NULL<br>");
else
{
out.println("Principal toString = "p.toString()"<br>");
out.println("Getting Principal Name<br>");
String n = p.getName();
out.println("Got Principal Name = "n"<br>");
}
}
catch(Exception e)
{
out.println(e);
}
%>
Here are the results:
Getting Principal
Got Principal
Principal is NULL
Thanks for helping out it is much appreciated,
Mike
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.