Implement a robust and flexible role-based authentication logic with dynamic permission management. This feature will allow to define roles and assign granular permissions to users dynamically, ensuring that access to specific functionalities and resources is controlled based on the user's role and permissions.