Design: Authentication and Authorization System
Design covers user identity verification and access control mechanisms. Does not cover user registration or password recovery flows.
Functional Requirements
Non-Functional Requirements
+-------------+ +----------------+ +--------------+
| | | | | |
| Client +------>+ Authentication +------>+ Token Service|
| | | Service | | (JWT Issuer)|
+-------------+ +----------------+ +--------------+
| | |
| | v
| | +---------------+
| | | Authorization |
| | | Service |
| | +---------------+
| | |
| | v
| | +---------------+
| | | User Database |
| | +---------------+
| | |
| | v
| | +---------------+
| | | Audit Logging |
| | +---------------+authentication in system design?user.role == 'admin'.def access_resource(user):
if not user.is_authenticated:
return "Access Denied"
if user.permission != 'read':
return "Permission Denied"
return "Resource Content"user.is_authenticated is True but user.permission is 'write'?True), so the first if condition fails and does not return "Access Denied".if returns "Permission Denied".if user.is_authorized:
print("Access granted")
else:
print("Access denied")is_authorized depends on authentication, but authentication is missing, it will always be false or unset, denying access.Pass the test and this pattern moves unknown