Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 6
public class AccountBean implements EntityBean {
int id;
double balance;
String modifiedBy;
EntityContext ejbContext;
PortableContext portableContext;
public void withdraw(Double withdraw)
throws WithdrawLimitException, AccessDeniedException {
// only tellers can withdraw more than 10k
if(withdraw.doubleValue() > 10000) {
Identity tellerIdnty = new RoleIdentity("teller");
boolean isTeller = ejbContext.isCallerInRole(tellerIdnty)
if(!isTeller)
throw new AccessDeniedException();
}
Double limit = (Double)
portableContext.getEnvironmentEntry(
"java:comp/env/withdraw_limit", Double.class);
if (withdraw.doubleValue() > limit.doubleValue())
throw new WithdrawLimitException(limit);
else
balance = balance - withdraw.doubleValue();
Identity identity = ejbContext.getCallerIdentity( );
String modifiedBy = identity.getName();
}
...
}
|
public class AccountBean implements EntityBean {
int id;
double balance;
String modifiedBy;
EntityContext ejbContext;
PortableContext portableContext;
public void withdraw(Double withdraw)
throws WithdrawLimitException, AccessDeniedException {
// only tellers can withdraw more than 10k
if(withdraw.doubleValue() > 10000) {
boolean isTeller = ejbContext.isCallerInRole("teller")
if (!isTeller)
throw new AccessDeniedException( );
}
Double limit = (Double)
portableContext.getEnvironmentEntry(
"java:comp/env/withdraw_limit",Double.class);
if (withdraw.doubleValue() > limit.doubleValue())
throw new WithdrawLimitException(limit);
else
balance = balance - withdraw.doubleValue();
Principal principal = ejbContext.getCallerPrincipal( );
String modifiedBy = principal.getName();
}
...
}
|
PortableContext can hide the EJB 1.0 and EJB 1.1 security models from the bean. To accomplish this, the PortableContext models its abstraction around the EJB 1.1 security model. Below, the abstract PortableContext class has been modified to include two new methods, getCallerPrincipal() and isCallerInRole(), which mimic the new security methods in the EJB 1.1 EJBContext.
import javax.ejb.*; import java.lang.reflect.Method; import java.security.Principal; |
In the PortableContext class, the security methods are abstract, which means that the PortableContext implementations (PortableContext1_0 and PortableContext1_1) must implement these methods.
Server-side Java: Read the whole series -archived on JavaWorld