vernac / architecture, expressed.
Browse documentation

Usecase authorization — proposed 0.6.0 contract

Status: language design baseline; production Java runtime foundation implemented. Baseline: 2026-11-12. The runtime/Spring SPI is available; the local permission/requires language and generated guards with module metadata/compatibility are now implemented. Full SaaS integration and installed-IDE acceptance remain OPEN. This is the next design slice of the 0.6.0 SaaS plan, covering D02/D03 and the authorization part of D04. MUST describes the proposed implementation requirement, not current compiler behavior. Merging this document accepts a design baseline; it does not verify A03/A04 or close the Spring feasibility work.

The current usecase contract remains authoritative for existing syntax. All new syntax below is deliberately fenced as text. The implemented 0.6.0 language subset is defined by the local language contract; Module metadata and the explicit-access assembly check are now implemented; this broader plan still includes incomplete SaaS integration.

Technical tenant integration

The technical tenant contract defines the proposed transaction-bound context/storage boundary. TenantId is independent of application AccountId and resource policy inputs. Permission scope resolution cannot replace an already bound tenant. Global usecases/repositories remain valid without a tenant; tenant operations require verified selection and the coordinator before tenant SQL. Necessary worker REQUIRES_NEW phases initialize their own physical binding. Prove these rules together with the authorization entry guard in the next spike.

New prerequisite: tenant isolation

The tenant-isolation design slice is now mandatory 0.6.0 scope. It adds a trusted tenant data boundary independent of actor, organization, account subscription and resource-specific grants. Generated tenant repositories, including byId, must enforce it without repeated application predicates. A permission Allow never bypasses isolation. Resolve D13 before freezing context/storage integration.

The older invoice/account policy example is withdrawn as the normal SaaS isolation approach. on invoiceId remains useful for additional resource rules, but must not be required merely to stop another tenant’s byId access. Where this proposal speaks of an account execution scope, refine it against verified tenant context rather than equating AccountId with TenantId or automatically adding organization fields. Resource-policy data reads must use the tenant-aware repository boundary. Tenant invisibility produces the ordinary repository not-found result; additional policy opacity rules below do not redefine that result or turn all missing rows into 403.

1. Named permissions

Proposed declaration, resolved through ordinary namespace/import rules:

namespace example.billing;

permission InvoicePermissions {
    VIEW;
    EDIT;
    EXPORT;
    ADMINISTER;
}

A permission identity consists of the full Vernac declaration name and member name. example.billing.InvoicePermissions.EXPORT is distinct from the same member in another namespace. A declaration MUST contain at least one distinct member. Member names follow existing identifiers and the Java enum collision checks; uppercase is conventional, not mandatory. Renaming a deployed permission changes its identity and requires deliberate migration of stored grants; no alias or automatic grant exists.

Proposed Java representation: a public enum in <namespace>.authorization, implementing a runtime permission-key interface and exposing stable qualified identities. It is an authorization artifact, not a domain VO or an arbitrary String authority. It MUST NOT silently become a permitted entity field, usecase input or persisted enum value. Permission/type/generated-name collisions need source diagnostics before generation. The final interface spelling is an implementation detail to settle in the spike.

A reusable module MUST explicitly export a permission declaration used by an exported usecase requirement. Extend the existing metadata kind/compatibility rules rather than inventing a second import system. A permission declaration alone grants nothing. An export is not a role assignment, account membership or module activation.

2. Requirements and syntax

A usecase has at most one optional requires clause. Proposed clause order is inputs, optional returns, optional requires, optional uses, optional validates, then behavior. Existing naming, result and dependency rules are unchanged.

A complete proposed declaration with an externally supplied implementation:

namespace example.billing;
id InvoiceId;
value ExportLocation(String);
permission InvoicePermissions { VIEW; EDIT; EXPORT; ADMINISTER; }

usecase ExportInvoice(InvoiceId)
    returns ExportLocation
    requires all {
        permission InvoicePermissions.VIEW on invoiceId;
        permission InvoicePermissions.EXPORT on invoiceId;
    }
behavior {
    execute implemented by example.billing.handwritten.ExportInvoiceImplementation;
}

The external implementation retains Access followed by the ordinary typed inputs; it is not passed Spring Authentication, credentials or an alternative public execute signature. Inline and external bodies go through the same generated guard.

Allowed forms:

requires permission InvoicePermissions.EXPORT

requires authenticated

requires public

requires any {
    permission InvoicePermissions.EDIT on invoiceId;
    permission InvoicePermissions.ADMINISTER on invoiceId;
}

requires all {
    permission InvoicePermissions.VIEW on invoiceId;
    any {
        permission InvoicePermissions.EDIT on invoiceId;
        permission InvoicePermissions.ADMINISTER on invoiceId;
    }
}

No not, role literal, plan name, subscription keyword, arbitrary expression or quota consumption is introduced in this first requirement tree. Later restriction contracts must extend this consistently, not overload a permission with side effects.

3. Actor, execution scope and resource

The runtime boundary is typed and independent of a universal User/Account model:

Value Meaning and provenance
Actor Verified subject reference and human/technical kind, obtained from trusted authentication integration
Execution scope Verified account/organization/application context under which work is requested
Resource reference Actual named input value plus its nominal Vernac type identity, not its toString()
Permission key Qualified declaration/member identity
Operation identity Qualified usecase name, for policy routing and safe diagnostics

Authentication maps to an actor; it does not prove account membership. An account selection from a path/header/session is a candidate until membership/scope resolution verifies it. Never trust a browser-supplied role, plan or account claim directly. A global administration operation needs an explicitly configured application scope and policy, not a null/empty scope interpreted as unrestricted access.

See the superseded invoice example for why a manual account query is insufficient, and the tenant slice for the corrected flow. The application explicitly provides resource ownership logic; no repository or ownership field is inferred from the ID type. The example’s binding SPI is proposed, not implemented, and its Java-versus-declarative assembly choice remains for review.

For on invoiceId, the policy can load the invoice or scoped facts to check ownership and capability. A VIEW/EXPORT grant in account A cannot authorize an invoice in B. The policy receives the real nominal ID type; equal UUIDs in different ID types do not collide. Do not pass the entire raw HTTP request, credentials or all input values.

An any alternative is a real alternative: a branch without on does not secretly validate the resource of a skipped branch. In particular, use a scoped ADMINISTER alternative as shown above when administration must retain resource ownership. Account-scoped repository access is still required in the implementation; a header permission tree does not automatically rewrite queries or make returned rows safe.

Scope resolution MUST be shared per invocation and made immutable for that invocation. Two calls must not independently infer different current accounts. A nested call inherits the actor and verified execution scope; its on input does not override them. Ordinary Access MUST NOT expose arbitrary actor/scope setters or impersonation. Explicit delegation/account switching is a later separate contract.

The check is a decision at invocation time, not a permanent authority token or a promise of instantaneous cross-process revocation. Avoid global success caching in this first slice. Membership/entitlement consistency and in-flight revocation limits must be documented and tested, not advertised as stronger database isolation.

4. Provider contract and tree evaluation

Introduce one explicitly bound authorization service per application, using existing module/provider binding. Policies may compose internally; ambiguous bindings MUST fail startup. Protected usecases MUST have their required infrastructure at startup; there is no auto-allow fallback or accidental empty-role interpretation.

The service receives actor, verified execution scope, permission, optional typed resource reference and operation identity. It returns a typed Allow or Deny with a stable, safe reason category, or raises a technical authorization failure. Exact Java names may be selected in the spike; the semantic outcomes are fixed here. Missing grants are Deny; missing/unavailable infrastructure is not a customer denial.

The application/module policy owns the combination of membership rights, explicit grants and plan benefits. This contract does not decide role/group precedence or which permissions are plan-gated (D05 remains OPEN). A paid plan never creates a membership role. Internal policy reasons MUST NOT leak confidential account facts.

Evaluate groups in declaration order and short-circuit:

Evaluation MUST be side-effect-free with respect to business state and usage. Operational audit events are allowed; reservations, consumption, payment calls or mutations are not. Invocation-local reuse of identical pure facts is acceptable; never reuse an outer Allow as permission for a different operation/resource. Reject exact duplicate sibling leaves with clear diagnostics. Do not silently sort, rewrite or infer specificity in a way that changes visible evaluation order.

5. Generated enforcement and transaction ordering

Proposed enforcement choice: a guard in the generated bean’s public execute, using a Spring-backed authorization service. Keep @Transactional(REQUIRED) and existing constructor injection. Do not add an independent permission check both in an AuthorizationManager interceptor and in the method body.

Normal supported execution order:

  1. Spring’s transaction proxy opens or joins REQUIRED.
  2. Open a properly scoped invocation context; preserve the trusted actor/scope of an outer invocation. Missing actor is representable for public operations.
  3. Run existing required-input DomainChecks. Null mandatory values still raise DomainValidationException; this technical input check performs no resource lookup.
  4. For a protected requirement, authenticate/resolve scope and evaluate the guard. A policy reading a MANDATORY repository is now inside the existing transaction.
  5. Run usecase validates, then inline/external implementation and result checks.
  6. Close invocation context on every exit; commit/rollback through the outer proxy.

A denied call MUST NOT reach domain preconditions with data lookups, implementation, repository writes, event emission or external I/O. Ordinary required-null and HTTP binding failures can occur before authorization and retain their established behavior. A public usecase may still reject invalid inputs, own tokens or domain invariants.

Every actually reached inner generated execute runs its own guard. Calls to a private helper are not new usecases. A rejected inner protected call propagates a runtime failure; existing REQUIRED rollback behavior applies. No independent commit, savepoint, automatic retry or restoration of Java object state is introduced. An application catching a proxied inner failure cannot assume its transaction is still committable; Spring rollback-only semantics remain authoritative.

A body guard is not dependent on an additional authorization proxy. Direct/manual construction still does not create Spring transactions, however. Protected entry MUST require an active transaction and configured trusted authorization service and fail technically before policy/body if either is absent. Do not execute policies with auto-commit after bypassing the supported managed entrypoint. Calling an internal static companion directly is unsupported, like bypassing other generated API guards; this is architecture enforcement, not a sandbox against malicious Java/reflection.

Role/permission checks use Spring Security’s Authentication/SecurityContext mapping and may adapt its AuthorizationManager, but exact supported APIs require a spike against the checked-in Spring Boot 3.4.2 BOM. No upgrade to a newer Spring major is implied. AnonymousAuthenticationToken MUST NOT count as an authenticated actor merely because its isAuthenticated() flag is true. Clear/restorably scope runtime context on errors and pooled-thread reuse. Async/deferred workers start a new explicit technical/continuation context; do not persist bearer credentials in events.

6. Endpoint, UI and system integration

Retain the application’s SecurityFilterChain for login/session or bearer mechanisms, CSRF and URL/HTTP-method restrictions. An integration starter MUST NOT silently replace it. Generated endpoint access metadata is a follow-up contract, not new HTTP/MVC syntax in this PR. SaaS endpoints must have an audited explicit access mode.

No request-bound principal is available magically in jobs/listeners. Choose explicit system grants; no blanket ADMIN fallback. Authorization for outbound port methods remains outside this first slice. Resource policies must not become arbitrary SQL filters or post-filter paginated data as a substitute for proper tenant queries.

7. Failures and presentation

Proposed public-safe default codes are below. All usecase authorization failures are unchecked exceptions outside the generic VernacDomainException/PortRejectedException hierarchies; existing domain rejection rules MUST NOT accidentally turn them into 422 responses. Do not fabricate an outbound AdapterInvocation for authorization.

Runtime outcome Default HTTP result MVC / application reaction
Missing, anonymous or expired actor 401 / AUTHENTICATION_REQUIRED Safe local login path for browser pages; explicit API denial
Actor lacks required permission 403 / ACCESS_DENIED Explain lack of access without disclosing grants/resource existence
No selected scope when one is required 403 / SCOPE_REQUIRED Offer authorized account selection; never infer a global scope
Requested scope/resource is not authorized 403 / ACCESS_DENIED Same safe denial for hidden/missing resource facts
Misconfiguration or invalid runtime context 500 / AUTHORIZATION_CONFIGURATION_ERROR Operator action; no role/subscription upgrade suggestion
Authorization backend temporarily unavailable 503 / AUTHORIZATION_UNAVAILABLE Safe temporary-failure message; no implicit retry of the operation

A legitimate domain byId absence after authorization retains the existing 404 behavior. For resource authorization, a policy MUST NOT reveal hidden existence: missing and inaccessible lookup facts yield the same safe denial. This deliberately means a protected resource-specific call can return 403 before its body would have returned 404. Do not inspect arbitrary cause chains or translate every policy bug into ACCESS_DENIED. Unexpected policy exceptions are technical 500 failures.

Use one shared classifier for in-method failures and Spring entrypoint/access-denied handlers so REST and MVC agree. Preserve the public {code, message} shape; runtime errors may carry an opaque correlation reference for safe logging, with no new mandatory response field implied here. Browser login redirects need configured local paths/validated return targets; no password or token values in logs or URLs.

Auth failures are terminal for this first slice: existing adapter errors policies and Java hooks MUST NOT convert them into success, generic validation or a redisplay loader. Default classifier handling precedes those generic policies. New declarative auth error selectors/customization are a separate explicit design change. This avoids silently widening existing otherwise/domain rejection contracts. A payment/limit/ quota denial is not authentication failure; their own taxonomy follows later.

Log stable safe decision/failure codes, operation identity and an opaque correlation reference. Do not log parameters, resource/subject/account IDs by default, tokens, private policy detail, raw backend exceptions or sensitive stack-trace messages. Use proportionate logging for expected denials. See the plan’s allowlisted logging and seeded-secret tests; a log is not an authorization ledger.

8. Compatibility, tooling and acceptance

Generated Java callers keep the same execute parameter/result API. Keep Spring types out of domain objects and ordinary implementations. Permission requirements MUST be included in exported module usecase metadata so consumer tooling and startup audits see them. Changing a requirement is security-relevant even when Java ABI is unchanged; module compatibility checks must report it for review, not ignore it as body noise or silently accept it as an additive behavior change. Exact metadata version/migration rules need the module implementation review before adding a new kind.

Compiler diagnostics must cover unresolved/duplicate permissions, illegal scope inputs, empty/invalid groups, malformed clause order and generated Java collisions. IDE/LSP must support symbol completion, references/hover, module-source navigation and useful errors before generation, including incomplete edits. Vocabulary documentation should associate permission declarations by the existing exact-name convention when applicable. No Java injection is added inside a pure requirement tree.

Before this contract becomes implemented, prove at least:

These are test requirements, not tests already executed. A03/A04/A15/A18 in the release ledger stay OPEN. D02/D03 are proposed here, not all resolved. Dynamic limit/capacity/quota APIs, role/plan combination and complete SaaS features remain mandatory later slices; this contract does not reduce 0.6.0’s outcome.

Review decisions and next step

Review explicitly: .authorization permission enums; the proposed clause order and public/authenticated forms; omitted-clause compatibility plus strict SaaS startup audit; on binding to required typed inputs; body-guard ordering; safe 403 resource opacity; and terminal auth handling before existing adapter error customization. These choices refine agreed principles but have not been silently approved by the previous plan merge. Resolve objections before compiler implementation.

The authorization-entry experiment now provides partial AUTH-03/04/06/07 evidence against the managed dependency versions. It is handwritten, test-only code, not generated enforcement or a complete startup/web-security audit. The production runtime/Spring foundation now supplies actor/policy/guard APIs and terminal HTTP/MVC handling; the same experiment uses those APIs. The local compiler now emits guards, with an optional provider for public entry and a required Guard for protected entry. Module metadata/compatibility is now implemented under the module authorization contract. Next deepen tooling, retaining the full acceptance requirements above. Reference sources (not proof that the spike has run):