cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Username within custom code

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Hello Mike,

Have you found a solution already? If so, please, share it with the community and close this thread.

Regards,

Alex.

sergiy_katerinich
Active Contributor
0 Kudos

You can try this:

session.getAttribute(u201CLOGON_IDu201D);

Former Member
0 Kudos

Hi,

As I mentioned the session object has no data in it. It is empty.

Mike

sergiy_katerinich
Active Contributor
0 Kudos

Another option:

session.getAttribute(u201CUSER_BOu201D);

and then parse it from there.

Former Member
0 Kudos

Hi,

As I mentioned the session object has no data in it. It is still empty.

Any other ideas?

Thanks,

Mike

sergiy_katerinich
Active Contributor
0 Kudos

They suggested you playing with "Type" settings in Activity Maintenance.

And another try with request.getSession().getAttribute("USER_BO").

Normally, session should not be empty. If it is not passed, that could be configuration issue with custom activity.

Former Member
0 Kudos

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

Jerry_Lowery
Product and Topic Expert
Product and Topic Expert
0 Kudos

Which version of ME are you using and are you using our SDK?

Former Member
0 Kudos

Hi,

We are using 4.3.1 which does not have any SDK.

Mike

rusty_baldwin
Advisor
Advisor
0 Kudos

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.

Former Member
0 Kudos

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