mike
mike

Reputation: 21

Passing additional parameters from JSF to EJB

In my Java EE 6 application (Weblogic 12c, EJB 3.1, JSF 2) I need to know in EJB who called the method.

But the caller's login obtained from context.getCallerPrincipal().getName() is not enough since logins are not unique in my app. I need to pass additional parameter from JSF layer (user organization id), but I do not want to change each method's signature.

Is there any way to set custom parameter while user is logging into application (or generally in JSF layer), that is later visible for EJBs?

Upvotes: 2

Views: 287

Answers (1)

Mike Braun
Mike Braun

Reputation: 3769

There are a couple of options.

  1. Use JASPIC to set the user/caller principal name to something else than the user used to login with.

For example, if a user logs in with "joe", then with most baked-in modules "joe" will be what's returned from context.getCallerPrincipal().getName().

With JASPIC you can make this any string, eg "joe.theboss::131::9634".

  1. Use CDI to remember something in eg request scope. EJB beans can be injected with request scoped CDI beans (be careful to use CDI @RequestScoped and not the JSF version).

Upvotes: 2

Related Questions