CS 3360 - Design and Implementation of Programming Languages PROJECT 1: ASPECT-ORIENTED PROGRAMMING WITH ASPECTJ (File $Date: 2011/02/28 18:19:21 $) Due: March 3, 2011 The purpose of this project is to understand the basic concepts of aspect-oriented programming and have a taste of AOP by writing small AspectJ programs. Download the bank account classes from the course website and do the following problems. 1. (20 points) Write an aspect named LogBankAccount that logs every deposit and withdrawal transaction on every bank account. However, if a transaction is originated from another bank account method such as payInterest and postCheck, it should not be logged. For each transaction, the log message should contain the account number, the transaction type (either deposit or withdrawal), the transaction amount, and the new balance of the account, e.g., Account: 100, Transaction: deposit, Amount: 100, Balance: 200 Account: 100, Transaction: withdraw, Amount: 50, Balance: 150 You should print the log messages to the console, i.e., System.out. 2. (20 points) In this problem, you will improve the robustness of the bank account implementation. One way to do this is to make implicit implementation assumptions explicit by enforcing them using AspectJ. Two such implicit assumptions of the BankAccount class implementation are: (a) Transaction amounts are positive. (b) The balance is always non-negative. These properties are often called safety properties, and the second properties is also called a class invariant. Write an aspect named CheckBankAccount that checks for the above two implementation assumptions. If a violation of the assumptions is detected, your aspect should indicate it by throwing an instance of IllegalArgumentException for the first assumption and an instance of IllegalStateException for the second. 3. (20 points) In this problem, you will extend the features of checking accounts. A checking account can now be linked to an optional savings account for overdraft protection. For this, you will first extend the interface of the CheckingAccount class by writing an aspect named ProtectCheckingAccount that adds the following new methods to the CheckingAccount class. // Sets the given account as the overdraft protection account. void setAssociatedAccount(SavingsAccount acc) // Remove the overdraft protection account. void clearAssociatedAccount() // Return the current overdraft protection account. SavingsAccount getAssociatedAccount() // Test if an overdraft protection account exists. boolean hasAssociatedAccount() You will next change the behavior of the postCheck method of the CheckingAccount class by extending the ProtectCheckingAccount aspect. When a check is posted to a checking account, (a) if the account has sufficient balance, it is cleared as before. (b) if the account doesn't have sufficient balance but has an overdraft protection account with enough balance, it is cleared by first exhausting the funds of the checking account and then using the associated savings account. (c) otherwise, the check is returned; a returned check is indicated by throwing an instance of the IllegalArgumentException exception class. 4. (40 points) In this problem, you will improve the security of the bank account implementation. For this, you will introduce authentication and authorization to the implementation. Write an aspect named SecureBankAccount that: (a) Assigns two passwords to each bank account when the account is first created. The first password, called a normal password, is used to control the execution of all bank transactions except for the withdrawal and postCheck transactions. The withdrawal and postCheck transactions are to be controlled by the second password, called a secure password. (b) Authorizes a withdrawal/postCheck transaction if and only if the user is authenticated with the secure password. The user needs to be authenticated for each individual withdrawal and postCheck transaction. However, a withdrawal/postcheck transaction needs not be authenticated if it is embedded in another withdrawal/postcheck transaction. If the user fails to authenticate, your aspect should throw an instance of the SecurityException exception class. (c) Authorizes all other kinds of transactions (e.g., balance, account number, and deposit) if and only if the user is authenticated with the normal password. Unlike the withdrawal/deposit transaction, however, the user needs to be authenticated only once when the first transaction is requested; all subsequent non-withdrawal/deposit transactions will proceed normally without requiring a further authentication. HINTS For Problem 4 above, you need to set up a pair of passwords for each new bank account. For this, you may use the PasswordPrompter class available from the course website. It prompts for and reads a password using the console. TESTING Your code should compile with AspectJ 1.6 or later and run correctly under Java 1.6 or later version. You should test your programs thoroughly. WHAT AND HOW TO TURN IN Submit your programs and test outputs through the Assignment Submission page found in the Homework section of the course website. The page will ask you to zip, jar, or tar your programs, and upload a single file. The zip (jar or tar) file should include only a single directory named YourFirstNameLastName which contains all your source code files and other support files needed to compile and run your program; DO NOT INCLUDE BYTECODE (.class) FILES OR HTML FILES. You should submit your programs before the class time on the due date. Note that the submission page will be automatically closed exactly on the sixth day from the due date and time. GRADING You will be graded, in part, on how clear your code is. Excessively long code will be penalized: don't repeat code in multiple places. Your code should be well documented with Javadoc or AspectJdoc and sensibly indented so it is easy to read. Be sure your name is in the comments in your code.