Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

ejbcertificate.com question on ejbActivate()

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The exhibit excerpt is from a container managed persistence entity bean, which one of the following statements is correct?

...
public void ejbActivate() {
try{
// get the caller principal
Principal callerPrincipal=myEntityCtx.getCallerPrincipal();
// get the distinguished name fromthe principal
log(callerPrincipal.getName());
} catch(Throwable t) {
//Oooops!!
}
}
...

1.There will be an entry in the log with the return value from "callerPrincipal.getName()".

2.There will not be an entry in the log as the code will not execute the line "log(callerPrincipal.getName());".

3 .There will be an entry in the log of "null".

4.This code will not compile as the method getCallerPrincipal() on the javax.ejb.EntityContext returns a boolean result not a reference to an instance of java.security.Principal.


Answer 2 is correct, this is the ejbActivate method of an entity bean. The container invokes the ejbActivate() method on an instance, when an instance needs to be activated to service an invocation on an existing entity object. This occurs because there is no suitable instance in the ready state to service the client's call. The getCallerPrincipal() method returns the java.security.Principal that identifies the invoker of the bean instance's EJB object. When ejbActivate() is invoked in an entity bean there is no client (the bean is not associated with the client at this point), this means that the Container cannot return a Principal. Instead a java.lang.IllegalStateException will be thrown by the Container so the code will go into the catch block.


My View: ejbActivate() is called when a client make a call on business method. so on that time ,it's possible to get client security informations.

so,how this answer is right? Pleas explain....
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you're thinking that the ejbActivate method can only be invoked as a direct consequence of a client invoking some business methods? This is not exactly correct.

You need to be clear that ejbActivate can only be invoked by the container. A client can never get to invoke this method since its not being exposed to them at all.

Now what if my calling client is a MDB. Can you still say that you'll have a client security context? A MDB does not have any clients at all. Hence, no client security context. And if it happens to use an entity bean, there'll be no propagation of client context.
 
Poo Kan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Lee, Now it's clear to me
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Poobhathy Kannan:
Thanks Lee, Now it's clear to me



No problem.

Study hard!
 
I AM MIGHTY! Especially when I hold this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic