Authentication and authorization refactoring