Take a look at Apache Shiro .
It allows you to pull out user authorization once and cache it for the entire session. In addition, if all users can VIEW all ACCOUNTS, you do not need to explicitly define this, which will significantly reduce overhead.
If your solution requires real-time access handlers, Shiro has a way to reset Permissions dynamically at runtime.
Shiro allows you to implement a typical RBAC and define permissions as follows:
domain:action:instance
So, in your case, user permissions might look like this:
account:deposit:* // deposit all accounts account:view:1111 account:view:2222 account:view:3333 // view on these accounts account:withdraw:5555 account:withdraw:6666 // withdraw on these accounts
In code, you can do something like this:
if (SecurityUtils.getSubject().isPermitted("account:withdraw:"+account.getAccountNumber() ) {
Ciro also has annotation-driven permissions for added abstraction.
EDIT
Shiro permissions are the end result, not the one where you start. I used a set of tables representing user-to-role mappings and roles to resolve along with other mappings for the instance. Following AuthN is usually a simple set of queries indexed by a user PK to create the data structures needed to grant permissions.
Jeff source share