public interface Javax.ejb.EJBContext { public Javax.ejb.EJBHome getEJBHome(); public Java.util.PRoperties getEnvironment(); public Java.security.Identity getCallerIdentity(); public boolean isCallerInRole(Java.security.Identity); public Javax.jts.UserTransaction getUserTransaction(); public void setRollbackOnly(); public boolean getRollbackOnly(); }
Properties props = System.getProperties(); props.put(Context.SECURITY_PRINCipAL, "EmployeeA"); props.put(Context.SECURITY_CREDENTIALS, "myPassWord1"); Context ctx = new InitialContext(props); // Use the initial context to lookup home objects...
isCallerInRole() import Java.security.Identity; ... public class Mybeans implements Sessionbeans { private SessionContext ctx; ... public void foo() { Identity id = new MyIdentity("administrators"); if (ctx.isCallerInRole(id)) { System.out.println("An admin called me"); return; } System.out.println("A non-admin called me"); } }
import Java.security.Identity; public class MyIdentity extends Identity { public MyIdentity(String id) { super(id); } } getCallerIdentity() import Java.security.Identity; ... public class Mybeans implements Sessionbeans { private SessionContext ctx; ... public void bar() { Identity id = ctx.getCallerIdentity(); String name = id.getName(); System.out.println("The caller′s name is " + name); } }
// First, get the EJB object handle from the EJB object. Javax.ejb.Handle myHandle = myEJBObject.getHandle(); // Next, serialize myHandle, and then save it in // permanent storage. ObjectOutputStream stream = ...; stream.writeObject(myHandle); // time passes... // When we want to use the EJB object again, // deserialize the EJB object handle ObjectInputStream stream = ...; Handle myHandle = (Handle) stream.readObject(); // Convert the EJB object handle back into an EJB object MyRemoteInterface myEJBObject = (MyRemoteInterface) myHandle.getEJBObject(); // Resume calling methods again myEJBObject.callMethod();