|
| 1 | +# 🔐 Authorization & Policies |
| 2 | + |
| 3 | +UltimateAuth provides a flexible and extensible authorization system based on: |
| 4 | + |
| 5 | +- Roles |
| 6 | +- Permissions |
| 7 | +- Policies |
| 8 | +- Access orchestration |
| 9 | + |
| 10 | +## 🧩 Core Concepts |
| 11 | + |
| 12 | +### 🔑 Permissions |
| 13 | + |
| 14 | +In UltimateAuth, permissions are not just arbitrary strings. |
| 15 | + |
| 16 | +They follow a **structured action model**. |
| 17 | + |
| 18 | +#### 🧩 Permission Structure |
| 19 | + |
| 20 | +Permissions are built using a consistent format: |
| 21 | + |
| 22 | +``` |
| 23 | +resource.operation.scope |
| 24 | +``` |
| 25 | +or |
| 26 | +``` |
| 27 | +resource.subresource.operation.scope |
| 28 | +``` |
| 29 | + |
| 30 | +#### ✅ Examples |
| 31 | + |
| 32 | +- `users.create.admin` |
| 33 | +- `users.profile.update.self` |
| 34 | +- `sessions.revokechain.admin` |
| 35 | +- `credentials.change.self` |
| 36 | + |
| 37 | +👉 This structure is not accidental — |
| 38 | +it is **designed for consistency, readability, and policy evaluation**. |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +### ⚙️ Built-in Action Catalog |
| 43 | + |
| 44 | +UltimateAuth provides a predefined action catalog. |
| 45 | + |
| 46 | +Examples: |
| 47 | + |
| 48 | +- `flows.logout.self` |
| 49 | +- `sessions.listchains.admin` |
| 50 | +- `users.delete.self` |
| 51 | +- `credentials.revoke.admin` |
| 52 | +- `authorization.roles.assign.admin` |
| 53 | + |
| 54 | +👉 This ensures: |
| 55 | + |
| 56 | +- No magic strings |
| 57 | +- Discoverable permissions |
| 58 | +- Consistent naming across the system |
| 59 | + |
| 60 | +<br> |
| 61 | + |
| 62 | +### 🧠 Scope Semantics |
| 63 | + |
| 64 | +The last part of the permission defines **scope**: |
| 65 | + |
| 66 | +| Scope | Meaning | |
| 67 | +|------------|----------------------------------| |
| 68 | +| `self` | User acts on own resources | |
| 69 | +| `admin` | User acts on other users | |
| 70 | +| `anonymous`| No authentication required | |
| 71 | + |
| 72 | +<br> |
| 73 | + |
| 74 | +### 🌲 Wildcards & Grouping |
| 75 | + |
| 76 | +Permissions support hierarchical matching: |
| 77 | + |
| 78 | +- `users.*` → all user actions |
| 79 | +- `users.profile.*` → all profile operations |
| 80 | +- `*` → full access |
| 81 | + |
| 82 | +### ⚡ Normalization |
| 83 | + |
| 84 | +Permissions are automatically normalized: |
| 85 | + |
| 86 | +- Full coverage → replaced with `*` |
| 87 | +- Full group → replaced with `prefix.*` |
| 88 | + |
| 89 | +<br> |
| 90 | + |
| 91 | +### Role |
| 92 | + |
| 93 | +A role is a collection of permissions. |
| 94 | + |
| 95 | +- Roles are tenant-scoped |
| 96 | +- Roles can be dynamically updated |
| 97 | +- Permissions are normalized internally |
| 98 | + |
| 99 | +### UserRole |
| 100 | + |
| 101 | +Users are assigned roles: |
| 102 | + |
| 103 | +- Many-to-many relationship |
| 104 | +- Assignment is timestamped |
| 105 | +- Role resolution is runtime-based |
| 106 | + |
| 107 | +<br> |
| 108 | + |
| 109 | +## 🔄 Permission Resolution |
| 110 | + |
| 111 | +Permissions are evaluated using: |
| 112 | + |
| 113 | +- Exact match |
| 114 | +- Prefix match |
| 115 | +- Wildcard match |
| 116 | + |
| 117 | +CompiledPermissionSet optimizes runtime checks. |
| 118 | + |
| 119 | +<br> |
| 120 | + |
| 121 | +## 🧠 Claims Integration |
| 122 | + |
| 123 | +Authorization integrates with authentication via claims: |
| 124 | + |
| 125 | +- Roles → `ClaimTypes.Role` |
| 126 | +- Permissions → `permission` claim |
| 127 | +- Tenant → `tenant` |
| 128 | + |
| 129 | +This allows: |
| 130 | + |
| 131 | +- Token-based authorization |
| 132 | +- Stateless permission checks (for JWT modes) |
| 133 | + |
| 134 | +<br> |
| 135 | + |
| 136 | +## ⚙️ Authorization Flow |
| 137 | + |
| 138 | +Authorization is executed through: |
| 139 | + |
| 140 | +👉 AccessOrchestrator |
| 141 | + |
| 142 | +Steps: |
| 143 | + |
| 144 | +1. Build AccessContext |
| 145 | +2. Execute policies |
| 146 | +3. Allow or deny operation |
| 147 | + |
| 148 | +<br> |
| 149 | + |
| 150 | +## 🛡 Policies |
| 151 | + |
| 152 | +Policies are the core of authorization logic. |
| 153 | + |
| 154 | +Default policies include: |
| 155 | + |
| 156 | +- RequireAuthenticated |
| 157 | +- DenyCrossTenant |
| 158 | +- RequireActiveUser |
| 159 | +- RequireSelf |
| 160 | +- RequireSystem |
| 161 | +- MustHavePermission |
| 162 | + |
| 163 | +<br> |
| 164 | + |
| 165 | +## 🔌 Plugin Integration |
| 166 | + |
| 167 | +Authorization is a plugin domain. |
| 168 | + |
| 169 | +It: |
| 170 | + |
| 171 | +- Does NOT depend on other domains |
| 172 | +- Uses contracts only |
| 173 | +- Integrates via policies and claims |
| 174 | + |
| 175 | +## 🎯 Key Takeaways |
| 176 | + |
| 177 | +- Authorization is policy-driven |
| 178 | +- Roles are permission containers |
| 179 | +- Permissions support wildcard & prefix |
| 180 | +- Policies enforce rules |
| 181 | +- Fully extensible and replaceable |
0 commit comments