SEC-1013: Refactored out use of ConfigAttributeDefinition from remaining interfaces

This commit is contained in:
Luke Taylor
2008-10-30 04:10:54 +00:00
parent c7abdadc06
commit a7d046357b
102 changed files with 896 additions and 1417 deletions

View File

@@ -5,47 +5,53 @@ package bigbank;
* encapsulate business logic (methods) and state in the domain object.
* Nevertheless, this demo is intended to reflect what people usually do,
* as opposed to what they ideally would be doing.
*
*
* @author Ben Alex
* @version $Id$
*/
public class Account {
private long id = -1;
private String holder;
private double balance;
public Account(String holder) {
super();
this.holder = holder;
}
private long id = -1;
private String holder;
private double balance;
private double overdraft = 500.00;
public long getId() {
return id;
}
public Account(String holder) {
this.holder = holder;
}
public void setId(long id) {
this.id = id;
}
public long getId() {
return id;
}
public String getHolder() {
return holder;
}
public void setId(long id) {
this.id = id;
}
public void setHolder(String holder) {
this.holder = holder;
}
public String getHolder() {
return holder;
}
public double getBalance() {
return balance;
}
public void setHolder(String holder) {
this.holder = holder;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getBalance() {
return balance;
}
public String toString() {
return "Account[id=" + id + ",balance=" + balance +",holder=" + holder + "]";
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getOverdraft() {
return overdraft;
}
public void setOverdraft(double overdraft) {
this.overdraft = overdraft;
}
public String toString() {
return "Account[id=" + id + ",balance=" + balance +",holder=" + holder + ", overdraft=" + overdraft + "]";
}
}

View File

@@ -1,15 +1,16 @@
package bigbank;
import org.springframework.security.annotation.Secured;
import org.springframework.security.expression.annotation.PreAuthorize;
public interface BankService {
@Secured("IS_AUTHENTICATED_ANONYMOUSLY")
public Account readAccount(Long id);
@Secured("IS_AUTHENTICATED_ANONYMOUSLY")
public Account[] findAccounts();
@Secured("ROLE_TELLER")
public Account post(Account account, double amount);
public Account readAccount(Long id);
public Account[] findAccounts();
@PreAuthorize(
"hasRole('ROLE_SUPERVISOR') or " +
"hasRole('ROLE_TELLER') and (#account.balance + #amount >= -#account.overdraft)" )
public Account post(Account account, double amount);
}

View File

@@ -4,37 +4,36 @@ import org.aspectj.lang.annotation.Pointcut;
import org.springframework.util.Assert;
public class BankServiceImpl implements BankService {
private BankDao bankDao;
private BankDao bankDao;
// Not used unless you declare a <protect-pointcut>
@Pointcut("execution(* bigbank.BankServiceImpl.*(..))")
public void myPointcut() {}
// Not used unless you declare a <protect-pointcut>
@Pointcut("execution(* bigbank.BankServiceImpl.*(..))")
public void myPointcut() {}
public BankServiceImpl(BankDao bankDao) {
Assert.notNull(bankDao);
this.bankDao = bankDao;
}
public BankServiceImpl(BankDao bankDao) {
Assert.notNull(bankDao);
this.bankDao = bankDao;
}
public Account[] findAccounts() {
return this.bankDao.findAccounts();
}
public Account[] findAccounts() {
return this.bankDao.findAccounts();
}
public Account post(Account account, double amount) {
Assert.notNull(account);
Assert.notNull(account.getId());
// We read account bank from DAO so it reflects the latest balance
Account a = bankDao.readAccount(account.getId());
if (account == null) {
throw new IllegalArgumentException("Couldn't find requested account");
}
a.setBalance(a.getBalance() + amount);
bankDao.createOrUpdateAccount(a);
return a;
}
public Account post(Account account, double amount) {
Assert.notNull(account);
public Account readAccount(Long id) {
return bankDao.readAccount(id);
}
// We read account bank from DAO so it reflects the latest balance
Account a = bankDao.readAccount(account.getId());
if (account == null) {
throw new IllegalArgumentException("Couldn't find requested account");
}
a.setBalance(a.getBalance() + amount);
bankDao.createOrUpdateAccount(a);
return a;
}
public Account readAccount(Long id) {
return bankDao.readAccount(id);
}
}