|
| 1 | +# Access Restrictions Module - Complete Documentation |
| 2 | + |
| 3 | +## Overview |
| 4 | +The Access Restrictions module in Mediastream Platform provides two different interfaces for managing content access control: |
| 5 | + |
| 6 | +1. **Legacy View** - Traditional interface with predefined restriction types |
| 7 | +2. **Advanced View** - Flexible rule-based system with granular control |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +### Database Schema |
| 12 | +**File:** `src/server/model/schemas/access_restrictions.coffee` |
| 13 | + |
| 14 | +```coffeescript |
| 15 | +AccessRestrictionSchema = new Schema |
| 16 | + _name: String (unique) |
| 17 | + name: String (required, indexed) |
| 18 | + account: ObjectId (ref: 'Account', required, indexed) |
| 19 | + is_default: Boolean (indexed) |
| 20 | + default_type: String (enum: ['media', 'event'], indexed) |
| 21 | + categories: [ObjectId] (ref: 'Category', indexed) |
| 22 | + apply_to_sub_categories: Boolean (default: true) |
| 23 | + date_created: Date (default: new Date, indexed) |
| 24 | + closed_access: |
| 25 | + enabled: Boolean (default: false) |
| 26 | + allow: Boolean (default: false) |
| 27 | + aes: |
| 28 | + enabled: Boolean (default: false) |
| 29 | + allow: Boolean (default: false) |
| 30 | + drm: |
| 31 | + enabled: Boolean (default: false) |
| 32 | + allow: Boolean (default: false) |
| 33 | + allow_incompatible: Boolean (default: false) |
| 34 | + access_rules: [AccessRuleItemSchema] |
| 35 | +``` |
| 36 | + |
| 37 | +### Access Rule Item Schema |
| 38 | +```coffeescript |
| 39 | +AccessRuleItemSchema = new Schema |
| 40 | + context: String (required) |
| 41 | + access: Boolean (default: true) |
| 42 | + type: String |
| 43 | + exclusive: Boolean (default: false) |
| 44 | + client_validation: Boolean (default: false) |
| 45 | + allow_unknown: Boolean (default: true) |
| 46 | + rules: [String] |
| 47 | + allow_regex: Boolean (default: false) |
| 48 | + regex: String |
| 49 | +``` |
| 50 | + |
| 51 | +## 1. Legacy Access Restrictions |
| 52 | + |
| 53 | +### Frontend Client |
| 54 | +**File:** `src/client/settings/access_restrictions/legacy.coffee` |
| 55 | + |
| 56 | +**Features:** |
| 57 | +- Simple radio-button interface for each restriction type |
| 58 | +- Fixed set of restriction categories |
| 59 | +- Direct form submission to `/api/account/access-restrictions` |
| 60 | + |
| 61 | +**Available Restrictions:** |
| 62 | +- **Geo Restriction** - Allow/deny countries |
| 63 | +- **Cellular Networks** - Allow/deny mobile networks |
| 64 | +- **Device Restrictions** - Basic mobile/TV blocking |
| 65 | +- **Advanced Device Options** - OS, Browser, Brand, Type restrictions |
| 66 | +- **Referrer Restriction** - Domain-based access control |
| 67 | +- **IP Restriction** - IP address/range filtering |
| 68 | +- **User Agent Restriction** - Browser/device filtering with regex support |
| 69 | +- **Closed Access** - Enable/disable content access |
| 70 | +- **DRM** - Digital Rights Management settings |
| 71 | + |
| 72 | +### Backend View |
| 73 | +**File:** `views/settings/access_restrictions/legacy.coffee` |
| 74 | + |
| 75 | +**UI Components:** |
| 76 | +- Traditional form layout with radio buttons |
| 77 | +- Chosen.js for multi-select fields |
| 78 | +- AutoComplete integration for dynamic inputs |
| 79 | +- Responsive grid layout |
| 80 | + |
| 81 | +## 2. Advanced Access Restrictions |
| 82 | + |
| 83 | +### Frontend Client |
| 84 | +**File:** `src/client/settings/access_restrictions/advanced/detail.coffee` |
| 85 | + |
| 86 | +**Features:** |
| 87 | +- Rule-based system with drag-and-drop ordering |
| 88 | +- Dynamic rule creation/editing/deletion |
| 89 | +- Rule testing functionality |
| 90 | +- Category-based application |
| 91 | +- Client-side validation options |
| 92 | + |
| 93 | +**Rule Contexts Available:** |
| 94 | +- `*` - Everything (catch-all rule) |
| 95 | +- `geo` - Geographic fencing by country |
| 96 | +- `device` - Device type (Mobile, TV) |
| 97 | +- `os` - Operating system |
| 98 | +- `device_type` - Device category |
| 99 | +- `browser` - Browser type |
| 100 | +- `brand` - Device brand |
| 101 | +- `referrer` - Referer domain |
| 102 | +- `cellular` - Cellular network detection |
| 103 | +- `ip` - IP address/range |
| 104 | +- `asn` - Autonomous System Number |
| 105 | +- `user-agent` - User agent string with regex support |
| 106 | + |
| 107 | +**Rule Properties:** |
| 108 | +- **Access** - Allow/Deny toggle |
| 109 | +- **Exclusive** - "Is" vs "Is not" logic |
| 110 | +- **Client Validation** - Client-side blocking option |
| 111 | +- **Allow Unknown** - Include unidentified requests |
| 112 | +- **Rules List** - Specific values to match |
| 113 | +- **Regex Support** - Pattern matching for user-agents |
| 114 | + |
| 115 | +### Backend View |
| 116 | +**File:** `views/settings/access_restrictions/advanced/detail.coffee` |
| 117 | + |
| 118 | +**UI Components:** |
| 119 | +- Interactive rule table with ordering controls |
| 120 | +- Modal dialogs for rule creation/editing |
| 121 | +- Test modal for rule validation |
| 122 | +- Category selection with sub-category options |
| 123 | +- Security settings (Closed Access, AES, DRM) |
| 124 | + |
| 125 | +### List View |
| 126 | +**File:** `views/settings/access_restrictions/advanced/index.coffee` |
| 127 | + |
| 128 | +**Features:** |
| 129 | +- Table view of all access restrictions |
| 130 | +- Create new restriction button |
| 131 | +- Edit/delete actions |
| 132 | +- Date created tracking |
| 133 | + |
| 134 | +## 3. API Endpoints |
| 135 | + |
| 136 | +### Legacy API |
| 137 | +- **POST** `/api/account/access-restrictions` - Update legacy restrictions |
| 138 | + |
| 139 | +### Advanced API |
| 140 | +**File:** `docs/swagger/platform/settings-access-restrictions.yaml` |
| 141 | + |
| 142 | +- **GET** `/api/settings/advanced-access-restrictions` - List all restrictions |
| 143 | +- **GET** `/api/settings/advanced-access-restrictions/{id}` - Get specific restriction |
| 144 | +- **POST** `/api/settings/advanced-access-restrictions` - Create new restriction |
| 145 | +- **POST** `/api/settings/advanced-access-restrictions/{id}` - Update restriction |
| 146 | +- **DELETE** `/api/settings/advanced-access-restrictions/{id}` - Delete restriction |
| 147 | + |
| 148 | +### API Response Structure |
| 149 | +```json |
| 150 | +{ |
| 151 | + "status": "OK", |
| 152 | + "data": { |
| 153 | + "_id": "string", |
| 154 | + "name": "string", |
| 155 | + "account": "string", |
| 156 | + "is_default": boolean, |
| 157 | + "default_type": "media|event", |
| 158 | + "categories": ["string"], |
| 159 | + "apply_to_sub_categories": boolean, |
| 160 | + "date_created": "ISO date", |
| 161 | + "closed_access": { |
| 162 | + "enabled": boolean, |
| 163 | + "allow": boolean |
| 164 | + }, |
| 165 | + "aes": { |
| 166 | + "enabled": boolean, |
| 167 | + "allow": boolean |
| 168 | + }, |
| 169 | + "drm": { |
| 170 | + "enabled": boolean, |
| 171 | + "allow": boolean, |
| 172 | + "allow_incompatible": boolean |
| 173 | + }, |
| 174 | + "access_rules": [AccessRuleItem] |
| 175 | + } |
| 176 | +} |
| 177 | +``` |
| 178 | + |
| 179 | +## 4. Rule Processing Logic |
| 180 | + |
| 181 | +### Validation Methods |
| 182 | +**File:** `src/server/model/schemas/access_restrictions.coffee` (lines 40-100) |
| 183 | + |
| 184 | +**Context-specific validation:** |
| 185 | +- **Geo/ASN** - Country/ASN code matching with case-insensitive comparison |
| 186 | +- **IP** - Range checking using `range_check` library |
| 187 | +- **Referrer** - Domain/subdomain matching with regex patterns |
| 188 | +- **User-Agent** - String matching or regex pattern validation |
| 189 | +- **Device/OS/Browser/Brand** - Exact string matching |
| 190 | +- **Cellular** - Network type detection |
| 191 | + |
| 192 | +### Rule Evaluation Order |
| 193 | +1. Default rules (account-level) |
| 194 | +2. Category-based rules (inherited) |
| 195 | +3. Specific restriction rules (by ID) |
| 196 | + |
| 197 | +Rules are evaluated in order within each restriction, with the first matching rule determining access. |
| 198 | + |
| 199 | +### Caching Strategy |
| 200 | +- **Default Rules** - 60-second TTL with memory caching |
| 201 | +- **Category Rules** - MD5-based cache keys with 60-second TTL |
| 202 | +- **Specific Rules** - ID-based caching with memory storage for events |
| 203 | + |
| 204 | +## 5. Security Features |
| 205 | + |
| 206 | +### Closed Access |
| 207 | +- Complete content blocking |
| 208 | +- Override all other rules when enabled |
| 209 | + |
| 210 | +### AES-128 Encryption |
| 211 | +- Media encryption support |
| 212 | +- Key management integration |
| 213 | + |
| 214 | +### DRM (Digital Rights Management) |
| 215 | +- Multi-device DRM support |
| 216 | +- Incompatible device handling |
| 217 | +- Provider integration (Widevine, PlayReady, FairPlay) |
| 218 | + |
| 219 | +### Client-Side Validation |
| 220 | +- HTML5 Network API integration |
| 221 | +- Pre-request blocking |
| 222 | +- Reduced server load |
| 223 | + |
| 224 | +## 6. Middleware Integration |
| 225 | + |
| 226 | +### Access Checking Middleware |
| 227 | +**Files:** |
| 228 | +- `src/server/middleware-embed/check-access-restrictions.coffee` |
| 229 | +- `src/server/middleware-embed/live-access.coffee` |
| 230 | +- `src/server/middleware-embed/media-access.coffee` |
| 231 | + |
| 232 | +**Process:** |
| 233 | +1. Extract request context (IP, User-Agent, Referrer, etc.) |
| 234 | +2. Retrieve applicable access restrictions |
| 235 | +3. Evaluate rules in order |
| 236 | +4. Apply security settings (DRM, AES, etc.) |
| 237 | +5. Return access decision |
| 238 | + |
| 239 | +## 7. Migration System |
| 240 | + |
| 241 | +### Migration Script |
| 242 | +**File:** `scripts/migrate_access_restrictions.coffee` |
| 243 | + |
| 244 | +Handles conversion from legacy to advanced system: |
| 245 | +- Account rule extraction |
| 246 | +- Category mapping |
| 247 | +- Rule transformation |
| 248 | +- Default rule creation |
| 249 | + |
| 250 | +## 8. Testing Framework |
| 251 | + |
| 252 | +### Rule Testing Interface |
| 253 | +**Location:** Advanced view modal |
| 254 | + |
| 255 | +**Test Parameters:** |
| 256 | +- Device type selection |
| 257 | +- Country selection |
| 258 | +- Referrer input |
| 259 | +- IP address input |
| 260 | +- ASN input |
| 261 | +- Cellular network detection |
| 262 | + |
| 263 | +**Test Results:** |
| 264 | +- Pass/fail indication |
| 265 | +- Rule that triggered the decision |
| 266 | +- Detailed explanation |
| 267 | + |
| 268 | +## 9. Integration Points |
| 269 | + |
| 270 | +### Content Types |
| 271 | +- **Media** - VOD content with full feature support |
| 272 | +- **Events** - Live streaming with limited DRM support |
| 273 | +- **Playlists** - Collection-level restrictions |
| 274 | + |
| 275 | +### Category System |
| 276 | +- Hierarchical category application |
| 277 | +- Sub-category inheritance options |
| 278 | +- Content-based rule assignment |
| 279 | + |
| 280 | +### CDN Integration |
| 281 | +- Edge authentication |
| 282 | +- Token-based access |
| 283 | +- Geographic distribution |
| 284 | + |
| 285 | +## 10. Performance Considerations |
| 286 | + |
| 287 | +### Caching Layers |
| 288 | +- Redis-based rule caching |
| 289 | +- Memory storage for frequently accessed rules |
| 290 | +- CDN-level access enforcement |
| 291 | + |
| 292 | +### Database Optimization |
| 293 | +- Indexed fields for fast queries |
| 294 | +- Lean queries for rule evaluation |
| 295 | +- Batch processing for bulk operations |
| 296 | + |
| 297 | +### Client-Side Optimization |
| 298 | +- Pre-flight validation |
| 299 | +- Local rule caching |
| 300 | +- Reduced server requests |
| 301 | + |
| 302 | +## Summary |
| 303 | + |
| 304 | +The Access Restrictions module provides a comprehensive, multi-layered content protection system with both simple (Legacy) and advanced (Advanced) interfaces. The system supports: |
| 305 | + |
| 306 | +- **Geographic restrictions** by country |
| 307 | +- **Network-based filtering** (IP, ASN, cellular) |
| 308 | +- **Device identification** (type, OS, browser, brand) |
| 309 | +- **Referer validation** for embed control |
| 310 | +- **User-agent filtering** with regex support |
| 311 | +- **Security features** (DRM, AES, closed access) |
| 312 | +- **Category-based application** with inheritance |
| 313 | +- **Rule testing** and validation tools |
| 314 | +- **Performance optimization** through caching |
| 315 | + |
| 316 | +The Advanced system offers superior flexibility and power, while the Legacy system maintains backward compatibility for existing implementations. |
0 commit comments