Principle:APIJSON APIJSON Access Control
| Knowledge Sources | |
|---|---|
| Domains | Security, Access_Control, Authorization |
| Last Updated | 2026-10-11 00:00 GMT |
Overview
An authorization pattern that enforces role-based permissions on database operations by combining declarative annotations, runtime access tables, and role hierarchy validation.
Description
Access Control in the APIJSON context is a multi-layered authorization system that determines whether a user with a given role can perform a specific HTTP method on a specific table. It operates after authentication (which establishes who the user is) and before SQL execution.
The system uses three complementary mechanisms:
- Declarative annotations (@MethodAccess): Model classes are annotated with allowed roles per HTTP method. For example, a Moment class might allow GET for all roles but DELETE only for OWNER and ADMIN. These are compiled into SYSTEM_ACCESS_MAP at startup.
- Runtime access table: The Access database table can override or extend the annotation-based rules at runtime, allowing administrators to change permissions without redeploying code. These are loaded into ACCESS_MAP.
- Role hierarchy: Roles form a trust hierarchy: UNKNOWN < LOGIN < CONTACT < CIRCLE < OWNER < ADMIN. Each role implies the permissions of lower roles. Higher roles may require additional validation (e.g., OWNER must verify the user owns the data).
The problem solved is fine-grained, per-table, per-method authorization without hardcoding checks in every endpoint. The declarative approach allows permissions to be expressed as data (annotations or database rows) rather than code.
Usage
Use this principle when:
- Different user roles need different access levels to the same tables
- Permissions need to be configurable at runtime (not just compile-time)
- A role hierarchy is needed (e.g., owners can modify their own data, admins can modify anyone's)
Theoretical Basis
# Abstract algorithm (NOT real implementation):
def verify_access(table, method, role, user):
# Step 1: Validate role is known
if role not in ROLE_HIERARCHY:
raise InvalidRoleError(role)
# Step 2: Non-UNKNOWN roles require authentication
if role != "UNKNOWN":
verify_login(user)
# Step 3: Check if role is allowed for this table+method
allowed_roles = ACCESS_MAP.get(table, {}).get(method, [])
if role not in allowed_roles:
raise AccessDeniedError(f"{role} cannot {method} on {table}")
# Step 4: Validate role-specific conditions
if role == "OWNER":
verify_ownership(user, table, request_conditions)
elif role == "CONTACT":
verify_in_contact_list(user, data_owner)
elif role == "ADMIN":
verify_admin(user)
The @MethodAccess annotation structure:
@MethodAccess(
GET = {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}, // all roles
POST = {OWNER, ADMIN}, // only owner and admin
PUT = {OWNER, ADMIN},
DELETE = {OWNER, ADMIN}
)
public class Moment { ... }
Related Pages
Implemented By
- Implementation:APIJSON_APIJSON_AbstractVerifier_verifyAccess
- Implementation:APIJSON_APIJSON_MethodAccess_Annotation
- Implementation:APIJSON_APIJSON_AbstractVerifier_verifyRequest