cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the current user id in cas

Former Member
0 Kudos

Hi All,

Can anyone help to determine the current user id entered in the portal for login through a composite application service?

Is there any way of getting the IUser object without knowing the unique id?

We are working with CE 7.1

Thanks in advance.

Regards,

Srinivasan Subbiah

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

It is CAF. But context is not visible.

How can i get the context and also how to get request object

Former Member
0 Kudos

You get the Context via the below Annotation

@Resource

private SessionContext context;

So, your code will look something like this....

public class TestBeanImpl extends com.sap.demo.modeled.appsrv.service.TestBean {

@Resource

private SessionContext context;

@com.sap.caf.dt.CAFOperation(name = "getStatusSummaryByUser")

public String com.sap.demo.types.StatusSummaryList getCARStatusSummary()

{

String userId = context.getCallerPrincipal().getName();

return ("Hello " + userId);

}

}

Not sure what you mean by "request"....

Rao

Former Member
0 Kudos

Hi,

But from where will i get the current session. Now i am getting the NullPointerException at context.getCallerPrincipal()...

Former Member
0 Kudos

If the client (VC, WD4J, etc) that's invoking the CAF service has already authenticated the user, then the user information can be passed to the service via LogonTickets (configured within NWA). Once you do that, you don't need to explicitly "get" the session.

Rao

Answers (1)

Answers (1)

Former Member
0 Kudos

within CAF or a JEE (EJB project), you can use the below statement to get the userId....

String userName = context.getCallerPrincipal().getName();

Rao