Skip to content

Permissions in YAML

A YAML-only app restricts what each user sees and does with the same rules the annotations @EyesOnly, @ReadOnlyUnless and @DisabledUnless express in Java. Same four dimensions, same matching, same evaluator: the YAML keys are read by the very Authorizer that reads the annotations. There is one rule, written two ways.

specs/ui/routes.yaml
routes:
- route: admin/users
layout: users.yaml
access: {roles: [admin]} # anybody else gets 403, here and on every nested route
# specs/ui/app.yaml (type: AppShell)
menu:
- {type: RouteLink, label: Users, route: admin/users} # hidden: it inherits the route's access
- {type: RouteLink, label: Audit, route: audit, access: {roles: [auditor]}}
# specs/ui/users.yaml (a page definition)
actions:
- id: delete
access: {roles: [manager]} # not advertised, buttons naming it disabled, 403 if called
restAction: {source: {ref: users-delete}}
layout:
type: VerticalLayout
content:
- {type: FormField, id: salary, label: Salary, readOnlyUnless: {roles: [hr]}}
- {type: FormField, id: notes, label: Notes, eyesOnly: {groups: [staff]}}
- {type: Button, label: Archive, actionId: archive, disabledUnless: {roles: [manager]}}

Every key takes the same object:

access:
roles: [admin, manager] # Keycloak realm/client roles, or a top-level `roles` claim
groups: [staff] # the `groups` claim
scopes: [orders:write] # `scope` (space-delimited) or `scp`
permissions: [orders.delete] # the `permissions` claim
  • AND across dimensions, OR within one. The example needs (admin or manager) and staff and orders:write and orders.delete.
  • A restriction with no dimension lets everybody through.
  • No token, or a malformed one, is denied. Restricted content needs a Bearer token.
  • Shorthand: access: admin or access: [admin, hr] lists roles.

The caller’s identity is resolved exactly as for the annotations: the principal your framework authenticated — Mateu does not authenticate, and never reads a Bearer token itself (see Security).

Annotation (Java)YAML keyWhereUnauthorized caller
@EyesOnly on a @UI classaccess:a route entry in routes.yaml403 for the route and every route nested under it (its children, a crud’s /new, /:id/edit)
@EyesOnly on a menu fieldaccess:an app-shell menu itemthe item is not sent. A RouteLink with no access: of its own inherits its route’s, so a link to a page you cannot open is not offered. A Menu group left empty disappears too
@EyesOnly / @DisabledUnless on an action methodaccess:an entry of a definition’s actions:the action is not advertised, every Button naming it is disabled, and a call that reaches the server anyway (dispatched, or proxied through __restfetch__) answers 403
@EyesOnly on a fieldeyesOnly:any component of a definitionthe component (and everything inside it) is removed
@EyesOnly on a @UI classeyesOnly: / access:the ROOT of a definition (its layout:, or a bare layout)nothing of the page is left for the caller: 403, before any state is hydrated or any action of its view model runs
@ReadOnlyUnlessreadOnlyUnless:any componentreadOnly: true on it and on every FormField inside it
@DisabledUnlessdisabledUnless:any componentdisabled: true (a Button, a RouteLink, a Menu…); a FormField, which has no disabled state, becomes read-only

A field that ends up hidden or read-only for the caller is also locked on the way in: its value is dropped from the state the client sends, so the server keeps its own value. A read-only field whose value the server accepted from the browser would be a suggestion, not a rule — the same reason the Hydrater ignores such fields for the annotations.

The keys name what the restriction does:

  • access: is about reaching or invoking something — a route you navigate to, a menu item you click, an action you run. Refused, it is simply not there for you (and 403 if you insist).
  • eyesOnly:, readOnlyUnless: and disabledUnless: are presentation states of a component on a screen you can open. They keep the annotations’ names on purpose, so a Java developer reads a YAML definition the same way they read a class.

A component also accepts access: as a synonym of eyesOnly:; the schema advertises eyesOnly.

Nothing about a restriction is decided in the browser. For every request the server resolves the caller’s identity, rewrites the definition (or the app shell) for it before mapping it to the wire, and strips the keys: what reaches the client is what this caller may see. A restriction the browser enforced would be a suggestion — the same reason pinned route parameters are re-applied on the server.

A partial is no exception: the keys inside a type: Partial (and its ${i18n.…} texts) are applied exactly as if its content were written in the page that references it — the server expands the partials into the definition first, then applies access and translations to the whole tree. So is a business component of components.yaml (a type: ComponentRef), and so is a partial or business component drawn inside a page written in code (new Partial("payroll") / new ComponentRef("Payroll") in a Java ComponentTreeSupplier, a C# or Python view building its own tree, or a YAML layout bound to a code view model).

Hiding a field or drawing it read-only only changes the screen; a client can still post any state it likes. So the server enforces the same keys on the way in: before the incoming state is written into the view model — the routed view, a nested form, a crud editor, a wizard step, an embedded island — every field the caller may not see (eyesOnly:) or may not edit (readOnlyUnless:, disabledUnless:) is dropped from it, and the view model keeps its server-side value. This holds wherever the field is declared: in the page’s own definition, in a partial or business component it uses (followed through the partials they nest — a piece inside a section the caller may not see locks all of its fields), and in the annotations of a code view. The value is never echoed back either.

The check is strict: a view that can draw partials or business components — a code view that builds its own component tree (or holds components, or has a method returning them), an adapted model, a YAML layout — is checked against every partial and business component of the app that declares access keys, every time, not only against the pieces it happens to draw. A page may draw a piece only in some state (if (state.showBonus) …), so what the server saw it render before can never decide what is writable now. (On .NET and Python a partial can only be used from YAML, where it is part of the page’s own definition, so there the app-wide check covers the business components.)

That has one consequence worth knowing: field names are app-wide for this purpose. If some partial or business component locks a field called bonus for the caller, a bonus posted to an unrelated view that can draw pieces is dropped too, even though that view never shows that piece. The WARN names the piece that locked it — rename one of the two fields if they are unrelated.

It fails closed: if the access keys of a partial or business component cannot be evaluated for the request, none of its fields is writable. When no spec file declares access keys at all, none of this costs anything. Each dropped field is logged once at WARN, naming the partial or component that locks it (then at DEBUG).

Hiding is UX, not authorization. As with the annotations, the REST endpoints your screens call must still check who is calling.

A statically deployed bundle has no server and no identity to check a restriction against, so there the keys are cosmetic:

  • staticOnly (-Dmateu.bundle.static=true) fails the build when a route declares access: or its definition declares any of the keys (StaticSafetyCheck) — exactly as it does for @EyesOnly. A screen that depends on who asks cannot be one file for everyone.
  • A non-static (hybrid) bundle keeps those routes backend-served: they are not pre-rendered nor shipped as raw definitions, and the backend answers them per user. A definition that declares access keys (in itself or in a partial it uses) never travels in manifest.json; one shared by a public route and a route with access: does, and the browser still refuses to expand it for the restricted route — it asks the backend.
  • The browser-side expander (specs-only bundles, the visual editor’s ▶ Play) has no identity either: it renders the definition as authored, unrestricted, and warns once in the console. Play shows you everything; check restrictions against a running backend.

See it live in the Explorer: Permissions (role switcher)