MATIH Platform is in active MVP development. Documentation reflects current implementation status.
6. Identity & Access Management
Impersonation Endpoints

Impersonation Endpoints

The impersonation endpoints allow authorized administrators to assume the identity of other users for troubleshooting purposes. All impersonation actions are fully audited. Requires ADMIN role or users:impersonate authority. Served by ImpersonationController at /api/v1/impersonation.


Endpoints

MethodEndpointDescription
POST/api/v1/impersonation/startStart impersonation session
POST/api/v1/impersonation/:sessionId/endEnd impersonation session
GET/api/v1/impersonation/sessions/activeGet active sessions
GET/api/v1/impersonation/sessions/:sessionIdGet session details
GET/api/v1/impersonation/sessions/:sessionId/validateValidate session
POST/api/v1/impersonation/sessions/:sessionId/record-actionRecord audit action
GET/api/v1/impersonation/auditGet audit history (paginated)
GET/api/v1/impersonation/audit/rangeGet audit by time range
POST/api/v1/impersonation/sessions/:sessionId/force-endForce-end session (Admin)
DELETE/api/v1/impersonation/users/:userId/sessionsRevoke all user sessions
GET/api/v1/impersonation/statsGet impersonation statistics

POST /api/v1/impersonation/start

Starts an impersonation session. Returns a token that can be used to act as the target user.

{
  "targetUserId": 42,
  "reason": "Investigating user-reported dashboard rendering issue",
  "ticketReference": "SUPPORT-1234"
}

The reason field must be between 10 and 1000 characters. The ticketReference is optional but recommended for compliance.

StatusDescription
200Session started, impersonation token returned
403Not authorized to impersonate
404Target user not found
409Cannot impersonate (protected role or same-tenant restriction)

Audit Trail

Every impersonation session records:

  • The admin who initiated the session
  • The target user being impersonated
  • Start and end timestamps
  • IP address and user agent of the admin
  • The stated reason and ticket reference
  • All actions performed during the session (via record-action)

Error Codes

CodeStatusDescription
UNAUTHORIZED_IMPERSONATION403Caller lacks impersonation permissions
INVALID_IMPERSONATION409Target has protected role or same-tenant restriction
USER_NOT_FOUND404Target user does not exist
SESSION_NOT_FOUND404Impersonation session not found
MAX_SESSIONS_EXCEEDED429Too many concurrent impersonation sessions