Refactor to the code use wrapper classes

Add AccessContext, Principal, and AccessRequest
Add debug information