domain.events.authorization_events¶
src.domain.events.authorization_events
¶
Authorization domain events.
Pattern: 3 events per workflow (ATTEMPTED → SUCCEEDED/FAILED) - *Attempted: Operation initiated (before business logic) - *Succeeded: Operation completed successfully (after commit) - *Failed: Operation failed (validation/commit failure)
Handlers: - LoggingEventHandler: ALL 3 events - AuditEventHandler: ALL 3 events - CacheInvalidationHandler: SUCCEEDED only (invalidate authz:* cache)
Reference
- docs/architecture/authorization-architecture.md
Classes¶
RoleAssignmentAttempted
dataclass
¶
Bases: DomainEvent
Role assignment attempt initiated.
Emitted BEFORE attempting to assign a role. Records the attempt for audit trail, even if assignment fails.
Triggers: - LoggingEventHandler: Log attempt at INFO level - AuditEventHandler: Record ROLE_ASSIGNMENT_ATTEMPTED
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
UUID
|
ID of user to receive role. |
role |
str
|
Role being assigned (admin, user, readonly). |
assigned_by |
UUID
|
ID of user performing the assignment. |
Source code in src/domain/events/authorization_events.py
RoleAssignmentSucceeded
dataclass
¶
Bases: DomainEvent
Role assignment completed successfully.
Emitted AFTER role successfully assigned and committed. Triggers cache invalidation and notifications.
Triggers: - LoggingEventHandler: Log success at INFO level - AuditEventHandler: Record ROLE_ASSIGNED - CacheInvalidationHandler: Invalidate authz:{user_id}:* cache
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
UUID
|
ID of user who received role. |
role |
str
|
Role that was assigned. |
assigned_by |
UUID
|
ID of user who performed the assignment. |
Source code in src/domain/events/authorization_events.py
RoleAssignmentFailed
dataclass
¶
Bases: DomainEvent
Role assignment failed.
Emitted when role assignment fails (validation, already has role, etc.). Captures failure reason for audit and alerting.
Triggers: - LoggingEventHandler: Log failure at WARNING level - AuditEventHandler: Record ROLE_ASSIGNMENT_FAILED
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
UUID
|
ID of user targeted for role. |
role |
str
|
Role that was attempted. |
assigned_by |
UUID
|
ID of user who attempted assignment. |
reason |
str
|
Why assignment failed (e.g., "user_not_found", "already_has_role"). |
Source code in src/domain/events/authorization_events.py
RoleRevocationAttempted
dataclass
¶
Bases: DomainEvent
Role revocation attempt initiated.
Emitted BEFORE attempting to revoke a role. Records the attempt for audit trail, even if revocation fails.
Triggers: - LoggingEventHandler: Log attempt at INFO level - AuditEventHandler: Record ROLE_REVOCATION_ATTEMPTED
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
UUID
|
ID of user to lose role. |
role |
str
|
Role being revoked (admin, user, readonly). |
revoked_by |
UUID
|
ID of user performing the revocation. |
reason |
str | None
|
Optional reason for revocation (for audit). |
Source code in src/domain/events/authorization_events.py
RoleRevocationSucceeded
dataclass
¶
Bases: DomainEvent
Role revocation completed successfully.
Emitted AFTER role successfully revoked and committed. Triggers cache invalidation and may revoke sessions.
Triggers: - LoggingEventHandler: Log success at INFO level - AuditEventHandler: Record ROLE_REVOKED - CacheInvalidationHandler: Invalidate authz:{user_id}:* cache - SessionRevocationHandler: May revoke sessions if admin role removed
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
UUID
|
ID of user who lost role. |
role |
str
|
Role that was revoked. |
revoked_by |
UUID
|
ID of user who performed the revocation. |
reason |
str | None
|
Optional reason for revocation. |
Source code in src/domain/events/authorization_events.py
RoleRevocationFailed
dataclass
¶
Bases: DomainEvent
Role revocation failed.
Emitted when role revocation fails (user doesn't have role, etc.). Captures failure reason for audit and alerting.
Triggers: - LoggingEventHandler: Log failure at WARNING level - AuditEventHandler: Record ROLE_REVOCATION_FAILED
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
UUID
|
ID of user targeted for revocation. |
role |
str
|
Role that was attempted to revoke. |
revoked_by |
UUID
|
ID of user who attempted revocation. |
reason |
str
|
Why revocation failed (e.g., "user_not_found", "does_not_have_role"). |