Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to switch principal in the same ejb client  RSS feed

Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am implementing a unit test that

1) run as a Admin. user (via file and locate my EJBs) and set up user accounts and permission via my EJBs.

2) run as the newly create user (via a run-time InitialContext and locate my EJBs) and test permission implementation by calling EJBs require certain permission.

All EJBs are stateless session beans.

I am having the following problem, because my client first runs as the admin. user (i.e., InitialContext has security.principal as admin. user), I could not again run as a different user, even though I have created another initial context having security.pincipal as the new user.

What I see via debugger is that, first, a bean instance was created and keep the SessionContext parameter which has the admin. user as security principal. Then, my test creates the new user, and then it creates an initial context with the new user and locates the bean, however, no bean instance is created, the same session bean instance is used. Later on, when I get current user from the session context, it is still the admin. user, not the newly create user.

On the EJB side, I am getting current user info. from SessionContext's getCallerPrincipal().getName();

I expect to get the newly created user from session context since I am creating initial context with that user, what am I missing?

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!