0
0
Flaskframework~5 mins

Role-based access control in Flask - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Role-based Access Control (RBAC)?
RBAC is a way to control who can do what in an app by assigning roles to users. Each role has permissions that allow certain actions.
Click to reveal answer
intermediate
How do you define roles in a Flask app using Flask-Login and Flask-Principal?
You create roles as strings or database entries and assign them to users. Flask-Principal helps check these roles to allow or deny access.
Click to reveal answer
beginner
What is the purpose of the @login_required decorator in Flask?
It ensures that only logged-in users can access a route. It is often combined with role checks for RBAC.
Click to reveal answer
intermediate
How can you restrict a Flask route to only users with the 'admin' role?
You check the user's roles inside the route or use Flask-Principal's @roles_required('admin') decorator to allow access only to admins.
Click to reveal answer
beginner
Why is RBAC better than giving permissions directly to users?
RBAC makes managing permissions easier by grouping them into roles. When a user's role changes, their permissions update automatically.
Click to reveal answer
In Flask RBAC, what does a 'role' represent?
AA database table
BA user’s password
CA Flask extension
DA group of permissions assigned to users
Which Flask extension helps manage user sessions and login status?
AFlask-WTF
BFlask-Migrate
CFlask-Login
DFlask-SQLAlchemy
What decorator would you use to require a user to be logged in before accessing a route?
A@login_required
B@roles_required
C@app.route
D@permission_required
How do you check if a user has the 'admin' role in Flask?
ACheck if 'admin' is in user.roles
BCheck if user.is_admin is True
CCheck if user.password == 'admin'
DCheck if user.id == 'admin'
Why is it better to assign roles instead of individual permissions to users?
AUsers prefer roles over permissions
BRoles simplify permission management
CPermissions are not secure
DRoles make the app slower
Explain how Role-based Access Control works in a Flask application.
Think about how you decide who can enter certain rooms in a building.
You got /4 concepts.
    Describe how you would implement a route that only 'admin' users can access in Flask.
    Consider using decorators and role membership checks.
    You got /4 concepts.