MODE-2042: Test permissions for principals known to the security context

This pull request modifies logic for permissions checking procedure. Originally only user id was used and in this version the entire security context and thus all principals are involved into the testing process.