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....