Multiple choice technology programming languages

From which of the following methods can you call the isCallerInRole() method of the SessionContext?

  1. setSessionContext()

  2. ejbCreate() method of a stateless session bean

  3. ejbCreate() method of a stateful session bean

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The isCallerInRole() method requires an established security context, which is available only after setSessionContext() has been called. For stateless session beans, ejbCreate() is called BEFORE setSessionContext(), so the security context isn't available yet. For stateful session beans, setSessionContext() is called BEFORE ejbCreate(), making the security context available. The setSessionContext() method itself cannot call isCallerInRole() because the context is still being initialized.