Sponsered Links
Categories
Sponsered Links

Simple POJO with Control of Security

 

shows a simple BankAccount class with typical business logic methods (transfer, closeout, changeRates). These method implementations are cluttered with nearly duplicate security-related checks, obscuring the original intent of the business logic. In addition, the SecurityManager calls add a dependency that will be difficult to work with when we unit test this class.

public class BankAccount {
public void transfer(BigDecimal amount, BankAccount recipient) {
SecurityManager.hasPermission(this, Permission.TRANSFER,
SecurityContext.getCurrentUser());
recipient.deposit(this.withdraw(amount));
}
public void closeOut() {
SecurityManager.hasPermission(this, Permission.CLOSE_OUT,
SecurityContext.getCurrentUser());
this.open = false;
}
public void changeRates(BigDecimal newRate) {
SecurityManager.hasPermission(this, Permission.CHANGE_RATES,
SecurityContext.getCurrentUser());
this.rate = newRate;
}
}

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved