• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

EPractice Lab mock exam 2, question 48

Posts: 2413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this question from EPractice Lab:

Which two statement about EJBContext.isCallerInRole method are correct?

a: Message driven bean must not call the isCallerInRole method.
b: The isCallerInRole method may be called in a session bean constructor.
c: The isCallerInRole method can be called in any business method of a stateless or stateful bean.
d: The isCallerInRole method can be called in the PostConstruct and PreDestroy method of a stateless bean

Explanation: A and C are correct.

I think the answer is C .
According to p.149 of the spec, MessageDrivenContext.isCallerInRole can be called in business method/interceptor / timeout callback method.
Posts: 3648
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I understand answer A is correct because MDB does not know the caller.

From the API if you try the container should throw IllegalStateException.

MZ notes mentioned this here

Oreilly MDB info also states here

Only the transactional methods the MessageDrivenContext inherits from EJBContext are available to message-driven beans. The home methods--getEJBHome() and getEJBLocalHome()--throw a RuntimeException if invoked, because MDBs do not have home interfaces or EJB home objects. The security methods--getCallerPrincipal() and isCallerInRole()--also throw a RuntimeException if invoked on a MessageDrivenContext. When an MDB services a JMS message there is no "caller," so there is no security context to be obtained from the caller. Remember that JMS is asynchronous and doesn't propagate the sender's security context to the receiver--that wouldn't make sense, since senders and receivers tend to operate in different environments.

Creator of Enthuware JWS+ V6
Posts: 3411
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to agree with Himai here. On page 149 of the specs, you can read that the security related methods (getCallerPrincipal, isCallerInRole) can be called from a business method of a MDB.

Apart from that table, you can see why they can be called over here (p 143)

5.4.13 Security Context of Message-Driven Bean Methods
A caller principal may propagate into a message-driven bean’s message listener methods. Whether this occurs is a function of the specific message-listener interface and associated messaging provider, but is not governed by this specification.

The mentioned IllegalStateException must therefore come from the EJB2.x specs.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic