aah Subject
Without question, the most important concept in aah framework is the Subject
. Subject is just a security term that means a security-specific view
of an application user. A aah Subject instance represents both security state and operations for a single application user.
These operations include:
- Authorization (access control)
- Session access
- Logout
aah originally wanted to call it User
since that “just makes sense”, but we decided against it.: too many applications have existing APIs that already have their own User struct
, and aah didn’t want to conflict with those. Also, in the security world, the term Subject
is actually the recognized nomenclature.
aah framework API encourages a Subject
-centric programming paradigm for applications. When coding application logic, most application developers want to know who the currently executing user is. While the application can usually look up any user via their own mechanisms (UserService, etc), when it comes to security, the most important question is “Who is the current user?”
Application code based on only the current user/Subject is much more natural and intuitive.
The Current Subject
You can obtain the currently executing Subject
by using
After you acquire the current Subject
, what can you do with it?
You can access Session
If you want to make things available to the user during their current session with the application, you can get their session:
Ok, so by now, we have a logged in user. What else can we do?
Let’s say who they are:
Let’s access the primary principal value (in this case username):
We can also test to see if they have specific role or not:
We can also see if they have a permission to act on a certain type of entity:
Also, we can perform an extremely powerful instance-level
permission check - the ability to see if the user has the ability to access a specific instance of a type:
Piece of cake, right?
Finally, when the user is done using the application, they can log out:
This simple API constitutes 90% of what aah framework end-users will ever have to deal with when using aah security.