Java and Kotlin SDK#
The public API of sdks/java, with its doc comments. Guide: docs/sdk/java.md.
349 public declarations, 258 with a doc comment.
allowedby-core/ActionClass.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/ActionClass.java
public enum ActionClassHow serious an action is (ABY-3 §4). It sets how long an approval may last and who asks for it: for
WRITE_HARD and IRREVERSIBLE the service itself creates a one-time approval bound to the exact
request (ABY-2 §6).
READ("read", 30L * 86400)Looks at data. Approved once, for up to 30 days.
WRITE("write", 7L * 86400)Changes data that can be undone. Approved once, for up to 7 days.
WRITE_HARD("write-hard", 86400)A change that is hard to undo. Approved every time, for the exact request (at most 24 hours).
IRREVERSIBLE("irreversible", 3600)Money or a final step. Approved every time, for the exact request (at most 1 hour).
public String wire()The name on the wire: read, write, write-hard, irreversible.
public long maxLifetime()The longest an approval of this class may last, in seconds (the reference's CLASS_MAX).
public boolean serious()True for write-hard and irreversible.
public static ActionClass of(String wire)The class of a wire name.
- throws ConfigurationException for an unknown name
allowedby-core/AllowedBy.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/AllowedBy.java
public final class AllowedBy implements AutoCloseableAllowedBy for a service: let AI agents use your API with a person's approval.
AllowedBy aby = AllowedBy.builder() .origin("https://notes.example") .node("https://node.example.org") .org("Notes Ltd", "FR") .route(Route.get("/notes").capability("notes:read").resource("note:\*")) .template("notes:read", "Read your notes") .build(); Outcome o = aby.process(request); // or the servlet filter / Spring Boot starter
What it does (sdks/CONTRACT.md §2): serves /.well-known/allowedby, /openapi.json and
/.well-known/api-catalog; verifies every request on the route map offline (ABY-2 §5); answers 401 with a
challenge and creates the approval itself for write-hard and irreversible routes (ABY-2 §6); refreshes the node
statement and status lists in the background. Thread-safe; build one per application and close() it at
shutdown.
public static final String LINK_PATHThe path of the SDK's link endpoint (ABY-3 §6).
public static Builder builder()A new builder.
public Outcome process(Request req)Everything a middleware does: the SDK's own endpoints, then the check on the route map. Paths outside the map pass with a null context.
public Response handle(Request req)The SDK's own endpoints (GET|HEAD /.well-known/allowedby, /openapi.json,
/.well-known/api-catalog), or null when the path is not one of them.
public boolean concerns(String method, String rawPath)True when the SDK handles this request itself or checks it (a discovery path, or a route of the map). An adapter reads the body only then: other requests reach the application untouched, body unread.
public boolean concerns(String method, String rawPath, String dispatchedPath)concerns(String, String) for a server that decodes and normalises the path before dispatching it
(dispatchedPath, e.g. a servlet's servlet path plus path info): the request concerns the SDK when
either form is on the route map.
public static boolean sameDispatch(String rawPath, String dispatchedPath)True when the server dispatches to the very path the SDK verifies. An adapter refuses a request on the route
map when it is false (/notes;x, //notes, /notes%2F1): otherwise the server could call a
protected handler for a path the route map did not match, unverified.
public boolean sameRoute(String method, String rawPath, String dispatchedPath)For adapters, once concerns(String, String, String) is true: true when the SDK verifies the very
route the server will dispatch to. False (refuse with ambiguousPath()) when only one of the two
forms is on the route map (/v1/notes%3Aarchive dispatched as /v1/notes:archive) or when they
name different paths (/notes;x, //notes, /notes%2F1): the check would otherwise find
no route and let a protected handler run unverified.
public static Response ambiguousPath()The refusal for sameDispatch(String, String) false.
public static String target(String method, String path)What an accepted request was checked as (plan point 14): its method, HEAD read as GET, and its path normalised as
the verifier normalises it (RFC 3986 §6.2.2). Another spelling of the same path gives the same target. Adapters
record it on acceptance and compare it where they see the handler that runs: a forward, a rewrite or a method
override after the check gives another target, and is refused with changedRefusal().
public static Response changedRefusal()The refusal of an accepted request whose method or path changed before its handler ran: never the path.
public static Response refusal(ErrorCode code, String title)A refusal the SDK would send, e.g. for an adapter that cannot read the body.
public boolean isVariant(String method, String rawPath, String query, Map<String, String> headers)True when a router could dispatch this request to a handler of the route map although the request itself is
not that route (CONTRACT §2.10): a trailing or doubled /, a format suffix, or a method override
(X-HTTP-Method-Override, X-HTTP-Method, X-Method-Override, _method) on a
request that touches the map. Such a request is refused, never passed through.
public boolean pathOnMap(String rawPath)True when the path, or a variant of it, is on the route map for any method (form _method checks).
public boolean concerns(String method, String rawPath, String dispatchedPath, String query, Map<String, String> headers)Everything an adapter asks before reading the body: the request concerns the SDK when it is a discovery path,
a route of the map (raw or as dispatched), or a variant of one (isVariant).
public boolean sharesHandler(String method, String rawPath, String handlerPrefix)public boolean isDeclared(String method, String rawPath)True for an exact unprotected entry: it lifts the variant rules too.
public boolean extendsRoute(String method, String rawPath)For an adapter that cannot see which handler the router selects, on a request outside the map: true when the path
extends a route that ends in a parameter (DELETE /notes/7/x with DELETE /notes/{id}), because a
router may give the parameter the rest of the path (CONTRACT §2.10). Refuse with unmappedRefusal(); a
page of your own is declared with Builder#unprotected(String).
public boolean extendsAnyRoute(String rawPath)extendsRoute for any method of the map (a form may carry _method).
public boolean namesMount(String method, String prefix, String rawPath, String query, Map<String, String> headers)For adapters, on a request outside the map in an application mounted at a prefix: true when the map was written
with the prefix, word for word, so that no request would ever match it. Refuse with mountRefusal(String).
public boolean omitsPrefix(String method, String rest)For adapters, on a request outside the map that a handler registered for a prefix gets: true when the rest of the
path, which that handler may route on, is a route of the map, a variant or an extension of one, so that the map
was written without the prefix. The SDK's own documents are not routes: an application below a prefix may have its
own /openapi.json. Refuse with unmappedRefusal().
public static Response mountRefusal(String prefix)The refusal for namesMount(String, String, String, String, Map).
public static Response unmappedRefusal()The refusal for sharesHandler(String, String, String): not a route of the map, though its handler serves one.
public static Response notPlainRefusal()The refusal of a target that is not plain (Paths.canonical): servers and routers read it differently.
public static Response handlerRefusal()The refusal of an adapter that sees the handler (CONTRACT §2.10 rule 5): the handler about to run serves a route of
the map, and the request was not checked for that route. No unprotected entry lifts it, so the title names
the two fixes.
public static Response variantRefusal()The refusal of a variant of a route (CONTRACT §2.10).
public Outcome check(Request req)Verify a request against the route map (ABY-2 §5). A path outside the map passes with a null context (your
own authentication applies); on the map, the request passes with its Context or gets a refusal.
public String linkStart(String account)Your signed-in account page calls this (ABY-3 §6): a one-time linking code for account, valid 600
seconds, which the person gives their agent. The agent sends it to POST /allowedby/link with a single-use
aby:link approval, and the person's pair (home node, pairwise id) is linked to the account.
- throws IllegalArgumentException for an account of 0 or more than 256 characters
- throws IllegalStateException when 10 000 codes are pending
public String linkStart(String account, long ttl)linkStart(String) with a lifetime of ttl seconds (1 to 86 400).
public void refundBudget(Context ctx)Your handler refused an accepted request (a wrong total, an unknown order): give its tenant budget back (ORG-1 §5.3, CONTRACT, Extended: tenant budgets), so the amount it did not spend counts no more. Once: a second call, or one after the SDK's own refund (CONTRACT §2 item 10), does nothing, and so does a call for a request whose route has no budget. The approval itself stays spent. When the store does not take it, the amount stays counted (fail closed), logged without request data.
public boolean started(Context ctx)The adapter is about to hand this accepted request to its handler (or to code it cannot see past): from now on nothing is given back for it. False for a request already refunded: its approval is usable again, so a layer dispatching it once more must not reach a handler (a second use); the adapter refuses it. True again for a request already started (a forward to what was checked).
public static Response refundedRefusal()The refusal of a refunded request dispatched again: it never reaches a handler. Never the path.
public Map<String, Object> wellKnown()/.well-known/allowedby.
public Map<String, Object> openApi()/openapi.json.
public Map<String, Object> apiCatalog()/.well-known/api-catalog.
public String getOrigin()The public origin, normalised.
public String getNode()The node, normalised.
public List<Route> getRoutes()The route map.
public Map<String, Object> getSigningKey()The public signing key (JWK with kid), as published in /.well-known/allowedby.
public List<String> refresh()Refresh the node statement and status lists now, on this thread (the background refresh does it every
refreshSeconds, and Builder#build() waits for its first run). Returns what failed, empty when
everything was refreshed.
public boolean isReady()True once the node is trusted (its statement fetched and verified).
public static final class BuilderBuilds an AllowedBy; build() validates everything and says what to fix.
public Builder origin(String origin)Your service's public origin, e.g. https://api.example.com (what agents sign for).
public Builder node(String node)The AllowedBy node you trust (on first use, its key pinned), e.g. https://node.example.org.
public Builder org(String legalName, String country)Your organisation (ORG-1 §2): legal name and ISO 3166-1 alpha-2 country, e.g. ("Notes Ltd", "FR").
public Builder org(Map<String, ?> org)Your organisation with more members: legal_name, country, and optionally website,
support, privacy_policy (https URLs), logo ({uri, sha256}), exp.
public Builder route(Route route)Add a route.
public Builder routes(Collection<Route> routes)Add routes.
public Builder unprotected(String path)A page of your own whose path looks like a variant or an extension of a route of the map, such as
/notes.txt or /notes/{id}/comments next to /notes/{id}: an exact path, or a template of
whole-segment parameters (which lifts the rule of longer paths only). Without it such a path is refused, never
served unchecked (CONTRACT §2.10). An entry that overlaps a route of the map, as it is
or but for its last /, fails construction.
public Builder unprotected(String method, String path)unprotected(String) for one method.
public Builder template(String capability, String text)The sentence the person approves for a capability, in English (summary and line).
public Builder template(String capability, Map<String, ?> template)A full template: {@code {"summary": {"en": ..., "fr": ...}, "lines": {...}}}, placeholders
{scope}, {amount.max}, {fields} (AMH-1 §4).
public Builder templates(Map<String, ?> templates)Several templates: capability to a sentence (String) or a full template (Map).
public Builder keyFile(Path keyFile)A private JSON file keeping the signing key and the disclosure key across restarts, shared by every instance (created on first use, mode 0600; the same format in every SDK). Without it both keys are new at each start.
public Builder store(Store store)The replay set, single use and counters (default: MemoryStore, one process only).
public Builder trustList(TrustList trustList)A signed trust list (OAID-5) instead of trusting node(String) on first use.
public Builder refreshSeconds(int refreshSeconds)How often the node statement and status lists are refreshed, in seconds (default 5, at most 60).
public Builder nodeMaxLevel(int nodeMaxLevel)The highest level accepted from the node (default 3).
public Builder clock(Clock clock)The clock every time check uses (default: system UTC).
public Builder title(String title)The API title (OpenAPI; default "<legal name> API").
public Builder version(String version)The API version (OpenAPI; default 1.0.0).
public Builder description(String description)The API description (OpenAPI).
public Builder rfc9421(boolean rfc9421)Also accept the RFC 9421 Web Bot Auth profile instead of the proof JWT (ABY-2 §3.1).
public Builder tenants(Map<String, ?> tenants)Tenants (ORG-1 §3.3) and their budgets (§5.3), keyed by the path parameter tenant: {tenant id:
{name, routes: {capability: override}, budgets: {capability: {max, currency, per, tz}}, org,
members_only}}, of JSON values (maps, lists, strings, numbers, booleans). An override only tightens the
route: level (the higher counts), authn (the stronger), mandate (this SDK verifies
none: such a route refuses with 401 mandate_required), require_link (true wins),
max_lifetime (the shorter), amount_max (the lower; above it 403 capability_denied),
operators (an allowlist of operator.id). A budget counts
the amounts accepted per tenant, capability and calendar period in tz (default UTC), in the
store(Store), and refuses one over what is left with 403 budget_exceeded, before any
approval is asked. Any other key or shape, or an override or budget on a capability with a route without
{tenant}, fails build(). The map is copied: later changes to it change nothing.
public Builder nonce(boolean nonce)AllowedBy-Nonce (ABY-2 §3.2), off by default: with it on, a route with Route#nonce(boolean), and every
irreversible route, refuses a proof without a current nonce with 401 invalid_signature and a
fresh nonce in the AllowedBy-Nonce header. A nonce is current for 300 s, on every instance that shares
the keyFile(Path), and across a restart.
public Builder rate(String limit, int calls, Duration per)A rate limit: "actor", per agent (its passport's sub), or "operator", per operator
(operator.id), at most calls calls per per (whole seconds, a sliding window on the
clock(Clock)). The defaults are 600 and 6000 calls per minute; a call over either limit gets
429 rate_limited. Another name, or a limit that is not a positive number of calls in a positive whole
number of seconds, fails build().
public Builder linkAuthorize(LinkAuthorizer linkAuthorize)Your own authorisation of a linked account on a route that needs a link (ABY-3 §6: the check is the
service's, done with the verifier's output). Only an answer of exactly true lets the request on;
false, null or an exception refuses it with 403 human_not_linked.
public AllowedBy build()Build and start the background refresh. Returns once its first refresh is over (done or failed, at most 5 s), so a service that starts cold (a new instance, or one that scales to zero) trusts its node and holds its status lists before its first request: nothing is fetched at request time (ARCH-1 §4, CONTRACT §2 item 4).
- throws ConfigurationException naming what to fix
allowedby-core/ConfigurationException.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/ConfigurationException.java
public class ConfigurationException extends IllegalArgumentExceptionAn invalid configuration, found at construction. The message says what to fix.
public ConfigurationException(String message)With a message that says what to fix.
public ConfigurationException(String message, Throwable cause)With a cause.
allowedby-core/Context.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/Context.java
public final class ContextWhat an accepted request established (ORG-1 §4.1, ABY-2 §5 step 10), given to the handler. Read-only.
Servlet: request.getAttribute(Context.ATTRIBUTE); Spring MVC: a @AllowedByContext Context
parameter. In Kotlin every getter reads as a property (ctx.humanId, ctx.level).
public static final String ATTRIBUTEThe request attribute (servlet) under which adapters store the context.
public static final class ChainLinkOne link of the grant chain, leaf first: the grant id and its revision.
public String getGid()Grant id.
public Long getRev()Revision (0 at issuance), or null.
public String getAgent()The agent: its passport subject (did:oaid:...).
public String getOperator()The operator running the agent (a verified domain, or the node's own operator id).
public String getHumanId()The person, as a pairwise id for this service (different at every service), or null on a level-0 route. Key your data on it: it is stable for one person and one service.
public int getLevel()The identity level reached: 0 (agent only), 1 passkey, 2 verified identity, 3 eIDAS high.
public List<String> getCapabilities()The capabilities the approval grants (e.g. notes:read).
public Map<String, Object> getDisplay()The text the person approved: {summary, lines, lang}, or null on a level-0 route.
public String getGid()The grant id (stable across revisions), or null on a level-0 route.
public Long getRev()The grant revision, or null.
public String getJti()The grant document's jti, or null.
public Map<String, Object> getActingFor()The company the person acts for: always null, company mandates are not in this SDK yet.
public String getTenant()The route's {tenant} value, as in getParams() (decoded once), or null when the route has none:
the tenant whose overrides and budget held for this request (ORG-1 §3.3, §5.3; Builder.tenants).
public Route getRoute()The route of the route map that matched.
public ActionClass getActionClass()The class of this request (for a route classed by amount: the class its amount gave).
public Map<String, String> getParams()The route's path values as the SDK checked them (CONTRACT §2 item 7): each {name} of the route's template,
taken from the normalised path and percent-decoded once (/t/acme%20co gives acme co, %2520
gives %20, an encoded / stays inside its value). Unmodifiable; empty for a route without
parameters. Act on these values, never on your own reading of the raw path, which can differ
(DELETE /notes/7/. is checked as /notes/7).
public List<ChainLink> getChain()The grant chain, leaf first (ABY-2 §5 step 10, for your audit log).
public String getHumanIss()The person's home node, or null.
public String getProofJti()The proof's jti (or the RFC 9421 nonce).
public String getRun()Audit: the agent's run id, when it sent one.
public Long getCall()Audit: the call number within the run, when sent.
public String getLinkedAccount()On a route that needs a link (Route#requireLink(boolean), ABY-3 §6): the account of yours the person's
pair (home node, pairwise id) is linked to, and authorised for. Null on any other route. Key the account's data
on it, never on a path value alone.
allowedby-core/ErrorCode.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/ErrorCode.java
public enum ErrorCodeEvery refusal code and its HTTP status (ABY-2 §6), the same in every AllowedBy SDK (the reference's
verifier.STATUS). The problem type is `https://allowedby.org/errors/``.
INVALID_REQUEST("invalid_request", 400, false)400: malformed request (a body that is not a JSON object, a malformed Allowed-By).
PASSPORT_REQUIRED("passport_required", 401, false)401: no Allowed-By header: the agent shows its passport.
INVALID_SIGNATURE("invalid_signature", 401, false)401: a signature, proof, replay or document check failed.
UNTRUSTED_NODE("untrusted_node", 401, false)401: the document comes from a node this service does not trust.
INSUFFICIENT_WITNESSES("insufficient_witnesses", 401, false)401: the node's log is not witnessed by enough trusted nodes (OAID-5).
GRANT_REQUIRED("grant_required", 401, true)401 challenge: the person's approval is needed.
GRANT_INSUFFICIENT("grant_insufficient", 401, true)401 challenge: the approval does not cover this request.
LEVEL_INSUFFICIENT("level_insufficient", 401, true)401 challenge: a stronger identity check is needed.
QES_REQUIRED("qes_required", 401, true)401 challenge: a qualified electronic signature is needed.
AUTHORITY_REQUIRED("authority_required", 401, true)401 challenge: the organisation's co-approvers are needed (extended, not in this SDK).
MANDATE_REQUIRED("mandate_required", 401, true)401 challenge: a company mandate is needed.
EXPIRED("expired", 401, true)401 challenge: the approval expired.
NOT_YET_VALID("not_yet_valid", 401, false)401: the document is not valid yet.
REVOKED("revoked", 401, true)401 challenge: the approval or the registration was withdrawn.
ACTOR_EXPIRED("actor_expired", 401, true)401 challenge: the agent's key expired; rebind the grant.
CLASS_LIFETIME_EXCEEDED("class_lifetime_exceeded", 401, true)401 challenge: the approval lasts longer than this action allows.
SINGLE_USE_CONSUMED("single_use_consumed", 401, true)401 challenge: a one-time approval was already used.
CAPABILITY_DENIED("capability_denied", 403, false)403: no such capability, or the route refuses this agent.
TIER_INSUFFICIENT("tier_insufficient", 403, false)403: the agent's key custody or the passkey is too weak for this action.
HUMAN_NOT_LINKED("human_not_linked", 403, false)403: the person has not linked their account (extended, not in this SDK).
BUDGET_EXCEEDED("budget_exceeded", 403, false)403: a budget is used up (extended, not in this SDK).
RATE_LIMITED("rate_limited", 429, false)429: too many requests (extended, not in this SDK).
ENVELOPE_TOO_LARGE("envelope_too_large", 431, false)431: Allowed-By and AllowedBy-Proof over 8 KiB, or a chain of more than two JWS (depth 1, ABY-2 §2).
STATUS_STALE("status_stale", 503, false)503: revocation status (or the replay store) temporarily unavailable; retry after Retry-After.
public String code()The wire code, e.g. grant_required.
public int status()The HTTP status.
public boolean challenge()True when the refusal carries an AllowedBy challenge (the reference's CHALLENGE_CODES).
public String type()The problem type URI.
allowedby-core/LinkAuthorizer.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/LinkAuthorizer.java
public interface LinkAuthorizerYour own authorisation of a linked account on a route that needs a link (ABY-3 §6). The SDK has found the account
the person's pair is linked to; you say whether that account may act on this resource. Only Boolean#TRUE
lets the request on: false, null or an exception refuses it with 403 human_not_linked.
Boolean authorize(String account, Route route, Map<String, String> params) throws Exception- param account the account the pair is linked to
- param route the route of the request
- param params its path parameters, decoded once
- return exactly
trueto let it on - throws Exception refuses the request (403), never a 500
allowedby-core/MemoryStore.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/MemoryStore.java
public final class MemoryStore implements StoreThe Store in memory: thread-safe, for ONE process only. Entries live until their own deadline (300 s for
proofs, the grant's expiry or the period's end otherwise). Bounded: when full of live entries it refuses new ones
(fail closed) rather than forget a replay.
public MemoryStore()A store of at most 200 000 live entries (the reference's default).
public MemoryStore(int maxKeys)A store of at most maxKeys live entries.
allowedby-core/Outcome.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/Outcome.java
public final class OutcomeWhat to do with a request (AllowedBy#process(Request)): send the SDK's own getResponse() response
(a discovery document or a refusal), or pass the request to the application, with the getContext() context when it was verified (null on a path outside the route map).
public boolean isAllowed()True when the request goes on to the application.
public Response getResponse()The response to send instead of calling the application, or null.
public Context getContext()The verified context, or null (refused, or a path outside the route map).
allowedby-core/Request.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/Request.java
public final class RequestAn HTTP request as the SDK sees it: what a framework adapter passes to AllowedBy#process(Request).
Immutable. Header names are case-insensitive; a header sent several times is one value joined with ", "
(RFC 9110 §5.3).
public static Request of(String method, String path, String query, Map<String, String> headers, byte[] body)A request.
- param method the HTTP method
- param path the path as sent (percent-encoded, without the query)
- param query the query string without "?", or null
- param headers the headers (any case)
- param body the body as sent, or null when there is none
public Request mountedAt(String prefix)The same request, in an application mounted at prefix (/api; a servlet's context path): the URL the
agent signed has it, the paths of the route map do not (CONTRACT §2.10).
- throws IllegalArgumentException for a prefix that is neither empty nor an absolute path
public String prefix()Where the application is mounted, or "".
public String method()The method, upper case.
public String path()The path as sent, without the query.
public String query()The query string without "?", or "".
public String header(String name)A header, or null.
public Map<String, String> headers()All headers (case-insensitive keys).
public byte[] body()The body bytes (empty when none).
allowedby-core/Response.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/Response.java
public final class ResponseAn answer the SDK sends itself: a discovery document or a refusal (problem+json). Immutable.
public int getStatus()The HTTP status.
public Map<String, String> getHeaders()Headers to send (Content-Type included).
public byte[] getBody()The body bytes.
public String getBodyText()The body as text.
allowedby-core/Route.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/Route.java
public final class RouteOne line of the route map (ABY-3 §4.1): which capability a method and path need, how serious the action is, and the identity level the person must have. Immutable: every method returns a new route.
Route.get("/notes").capability("notes:read").level(1).resource("note:\*") Route.delete("/notes/{id}").capability("notes:delete").actionClass(ActionClass.WRITE_HARD).level(2) .resource("note:{id}") Route.get("/me").level(0) // the agent's passport is enough, no person
The same arguments and validation as the Python reference's route(). AllowedBy.Builder#build()
validates every route; the message names the route and what to fix.
public static final class ThresholdOne amount threshold of a route classed by amount (ABY-3 §4.1).
public static Threshold upTo(String upTo, ActionClass actionClass)Amounts up to and including upTo (a decimal string, e.g. "1000.00") take this class.
public static Threshold otherwise(ActionClass actionClass)The last threshold: every larger (or unreadable) amount takes this class.
public String upTo()The limit, or null for the last threshold.
public ActionClass actionClass()The class.
public static Route route(String method, String path)A route for any method. {param} segments match one path segment.
public static Route get(String path)GET.
public static Route post(String path)POST.
public static Route put(String path)PUT.
public static Route patch(String path)PATCH.
public static Route delete(String path)DELETE.
public Route capability(String capability)The capability the route needs, namespace:action (e.g. notes:read).
public Route actionClass(ActionClass actionClass)The class of the action (default ActionClass#READ).
public Route actionClass(String actionClass)The class by its wire name: read, write, write-hard, irreversible.
public Route classByAmount(Threshold... thresholds)A payment route: the class comes from the amount at amountField(String), e.g.
classByAmount(Threshold.upTo("1000.00", WRITE_HARD), Threshold.otherwise(IRREVERSIBLE)).
public Route level(int level)The identity level the person needs: 0 (the agent's passport only), 1 passkey, 2 verified, 3 eIDAS high.
public Route resource(String resource)The resource the action is on, with {param} from the path (default <namespace>:*).
public Route amountField(String amountField)JSON Pointer to the amount in the body (e.g. /total): the approval caps it.
public Route currencyField(String currencyField)JSON Pointer to the currency in the body (default /currency).
public Route authn(String authn)The weakest passkey accepted: software, synced or hardware.
public Route tier(int tier)The lowest custody tier of the agent's key (OAID-3), default 0.
public Route maxLifetime(Duration maxLifetime)The longest an approval may last on this route, 60 s to 30 days (default: the class's).
public Route levelProfile(String levelProfile)A level-3 route for one profile of level 3 only: eu or na (OAID-7 §5.3).
public Route qes(boolean qes)A qualified electronic signature is required (OAID-7 §10). This SDK has no EU trusted-list snapshot to check
one, so such a route always answers qes_required (fail closed), as the reference does without one.
public Route summary(String summary)What the route does, for agents (OpenAPI).
public Route body(Map<String, ?> body)The JSON body members, for agents (OpenAPI): name to a description or a JSON Schema object.
public Route option(String name, Object value)Set an option by its reference name (as in configuration files): capability, class,
level, resource, amount_field, currency_field, authn, tier,
max_lifetime, level_profile, qes, require_link, account_param,
nonce, summary. The reference's other options (mandate, disclose,
disclose_optional, authority) are not enforced by this SDK yet: setting one makes construction
fail, never silently accepted (CONTRACT §2).
public String method()The HTTP method.
public String path()The path pattern.
public String capability()The capability, or null on a level-0 route without one.
public ActionClass actionClass()The class (for a route classed by amount: its most serious class).
public List<Threshold> thresholds()The amount thresholds, or null.
public int level()The identity level.
public String resource()The resource pattern (default <namespace>:*).
public String amountField()JSON Pointer to the amount, or null.
public String currencyField()JSON Pointer to the currency.
public String authn()The weakest passkey accepted, or null.
public int tier()The lowest custody tier.
public Long maxLifetime()The route's own maximum approval lifetime in seconds, or null.
public String levelProfile()The level-3 profile, or null.
public boolean qes()True when a qualified signature is required.
public Route requireLink(boolean requireLink)The route needs a linked account (ABY-3 §6): the person's pair (home node, pairwise id) must be linked to one of
your accounts through POST /allowedby/link, else 403 human_not_linked. When the path names an
account (accountParam(String), default account), the pair must be linked to that account.
Needs a capability and a level above 0.
public Route accountParam(String accountParam)The path parameter that names one of your accounts (ABY-3 §6), default account: a {name} of the path.
public Route nonce(boolean nonce)The route asks for an AllowedBy-Nonce (ABY-2 §3.2): a proof without a current nonce is refused with
401 invalid_signature and a fresh nonce in the AllowedBy-Nonce header, which the agent retries
with. Needs AllowedBy.Builder#nonce(boolean), or construction fails. Every irreversible route asks
for one when the service has nonces on.
public boolean nonce()True when the route itself asks for an AllowedBy-Nonce (an irreversible route asks whatever this says).
public boolean requireLink()True when the route needs a linked account.
public String accountParam()The path parameter that names an account: the one set, or account.
public String summary()The summary, or null.
public Map<String, Object> body()The documented body members, or null.
public List<String> params()The path parameter names, in order.
allowedby-core/Store.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/Store.java
public interface StoreThe replay set, single-use consumption and counters (ABY-2 §3.3, ABY-1 §7, ABY-3 §3). Every instance of a service
must share one store, or a proof could be replayed on another instance: MemoryStore is for one process
only; use a shared store (e.g. org.allowedby.redis.RedisStore) when you run several.
now always comes from the SDK's clock, never from the store's own wall clock, so an injected clock
governs expiry too. An implementation that cannot answer throws: the SDK then refuses the request (fail closed).
boolean add(String key, long until, long now)Add key unless it is present and live: an atomic check-and-set.
- param key the entry
- param until when it expires (epoch seconds)
- param now the SDK's clock (epoch seconds)
- return false when it already was there (a replay, a second use)
BigDecimal get(String key, long now)The live value of a counter or entry.
- return the value, or zero when absent or expired
boolean charge(List<Charge> charges, long now)All or nothing: add every increment when every total stays within its maximum. Atomic.
A refund (CONTRACT §2 item 10) is a charge too: the same keys with negative increments and no maximum, which must be applied exactly (in decimals, never rounded), the single-use mark included. A store that cannot apply it throws or returns false: the approval then stays spent.
- return false (and nothing changed) when one total would exceed its maximum
public Charge(String key, BigDecimal increment, BigDecimal max, long until)- param key the counter
- param increment what to add
- param max the most the total may reach, or null for no limit
- param until when the counter expires (epoch seconds)
public String key()The counter.
public BigDecimal increment()What to add.
public BigDecimal max()The most the total may reach, or null.
public long until()When the counter expires (epoch seconds).
public Charge until(long newUntil)The same charge with another expiry.
allowedby-core/TrustList.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/TrustList.java
public final class TrustListA signed trust list (OAID-5 §2, oaid-trust+jwt) used instead of trust on first use: anchors, trust
programs, vouching and witnesses. It is signed by one of the service's own keys (configuration integrity).
public static TrustList parse(String jws, Map<String, Object> serviceKey)Parse and check a trust list.
- param jws the compact JWS
- param serviceKey the public JWK (with its
kid) of the service key that signed it - throws ConfigurationException when the signature, the key or the members are wrong
public static TrustList load(Path path, Map<String, Object> serviceKey) throws IOExceptionparse(String, Map) from a file.
public long exp()Expiry (epoch seconds): after it, no node is trusted.
public List<Map<String, Object>> anchors()The anchors ({node, kid, max_level}).
public Set<String> denied()Nodes never trusted.
public Map<String, Object> vouching()Vouching rules ({enabled, max_depth, min_vouchers, vouched_max_level, inherit_max_level}).
public List<Map<String, Object>> programs()Trust programs ({url, kids, max_level, refresh}).
public int witnessesMin()How many trusted witnesses must cosign a node's log (0: not checked).
public Map<String, Object> payload()The signed payload.
allowedby-core/httpserver/AllowedByHttpFilter.java#
sdks/java/allowedby-core/src/main/java/org/allowedby/httpserver/AllowedByHttpFilter.java
public final class AllowedByHttpFilter extends FilterA filter for the JDK's own HTTP server (com.sun.net.httpserver, no dependency): the SDK's endpoints first,
then the check on every route of the map, then your handler. Paths outside the map reach the handler with the body
unread. On the map the body is read once and given back intact.
The handler reads the accepted Context with exchange.getAttribute(Context.ATTRIBUTE) (null
outside the route map). It is held by the exchange the handler receives, never in the JDK's attribute map, which
the JDK shares between every exchange of an HttpContext.
server.createContext("/", handler).getFilters().add(new AllowedByHttpFilter(aby));
public static final int MAX_BODYLargest body read on a route of the map: 1 MiB.
public AllowedByHttpFilter(AllowedBy aby)A filter for one AllowedBy.
allowedby-redis/redis/RedisStore.java#
sdks/java/allowedby-redis/src/main/java/org/allowedby/redis/RedisStore.java
public final class RedisStore implements Store, AutoCloseableThe Store in Redis, shared by every instance of a service (ABY-2 §3.3): the replay set, single-use
consumption and counters.
Expiry follows the SDK's clock: each value carries its own deadline (`value|until`), checked against
the `now` the SDK passes; Redis' own TTL only collects old entries.
`add` is one Lua script (check-and-set).
`charge` computes the new totals in exact decimals in Java, then writes them with one Lua
compare-and-set over every key; when another instance changed a counter meanwhile, it reads again.
One Redis primary (or Sentinel). Redis Cluster is not supported: one charge touches several keys.AllowedBy.builder()...store(new RedisStore("redis://redis.internal:6379")).build();
public RedisStore(String url)A store on a Redis URL, e.g. redis://host:6379 or rediss://user:pass@host:6380/0.
public RedisStore(UnifiedJedis redis)A store on your client (you close it). Keys start with allowedby:.
public RedisStore(UnifiedJedis redis, String prefix)A store on your client with another key prefix (several services on one Redis).
allowedby-servlet/servlet/AllowedByFilter.java#
sdks/java/allowedby-servlet/src/main/java/org/allowedby/servlet/AllowedByFilter.java
public final class AllowedByFilter implements Filterpublic static final int MAX_BODYLargest body read on a route of the map: 1 MiB (the reference's MAX_BODY).
public static final String TARGETThe request attribute that holds what an accepted request was checked as (AllowedBy#target): compare it
with target(HttpServletRequest) where the handler is known.
public AllowedByFilter(AllowedBy aby)A filter for one AllowedBy.
public AllowedByFilter(AllowedBy aby, String handlerAwareServlet)A filter for one AllowedBy. handlerAwareServlet: the name of a servlet that checks the handler it
selects itself (the Spring Boot starter's dispatcherServlet), so that a path that merely extends a route
of the map goes on to it. Every other servlet gets the rules of a plain filter. Null: none.
The filter still starts an accepted request before it hands it on (CONTRACT §2 item 10): a refusal after that
refunds nothing.
public AllowedByFilter(AllowedBy aby, java.util.function.Supplier<String> handlerAwareServlet)AllowedByFilter(AllowedBy, String) with the servlet's name known only once the application has started
(the Spring Boot starter checks every handler mapping first). Until then, and when it gives null, every servlet
gets the rules of a plain filter.
public static String target(HttpServletRequest req)What this request would be checked as now (AllowedBy#target): its method and the path below the context
path, the included one for an include (null when an include does not say which).
public static boolean changed(HttpServletRequest req)True when an accepted request is no longer the one checked: another method or path (another spelling of the same
path is the same), or no record of what was checked at all. Both forms of the path must be the ones checked: as
sent, normalised, and as the container maps it (decoded, normalised, path parameters stripped), since a segment
such as ..; is a literal in one and dot-dot in the other.
public static boolean movedOntoMap(AllowedBy aby, HttpServletRequest req)True when an accepted request now runs for another method or path that the route map protects: a route of the map or a longer path of one, or a path an include does not name. A path off the map (a view, a static page) is not: what runs there is not a handler of the map.
allowedby-spring-boot-starter/spring/AllowedByAutoConfiguration.java#
sdks/java/allowedby-spring-boot-starter/src/main/java/org/allowedby/spring/AllowedByAutoConfiguration.java
public class AllowedByAutoConfigurationSpring Boot auto-configuration: an AllowedBy bean from allowedby.* (and every
AllowedByCustomizer), the servlet filter on every path, and the AllowedByContext argument resolver
for Spring MVC controllers. A user-defined AllowedBy bean replaces the one built here; a Store bean
replaces the in-memory store.
public AllowedBy allowedBy(AllowedByProperties p, ObjectProvider<Store> store, ObjectProvider<AllowedByCustomizer> customizers)The service SDK, from the properties and the customizers: built once its first refresh is over (done or failed, at most 5 s, CONTRACT §2 item 4), so a node that answers is trusted before the first request. Closed (refresh stopped) with the context.
public FilterRegistrationBean<AllowedByFilter> allowedByFilter(AllowedBy aby, AllowedByProperties p, HandlerCheck check)The servlet filter on every path: the SDK's endpoints, then the route map, then the application.
public static class Mvc implements WebMvcConfigurer@AllowedByContext Context ctx in Spring MVC controllers.
allowedby-spring-boot-starter/spring/AllowedByContext.java#
sdks/java/allowedby-spring-boot-starter/src/main/java/org/allowedby/spring/AllowedByContext.java
public @interface AllowedByContextInjects the verified org.allowedby.Context into a Spring MVC handler parameter.
@GetMapping("/notes") List<Note> notes(@AllowedByContext Context ctx) { String person = ctx.getHumanId(); if (person == null) // level 0: no person, and never a key throw new ResponseStatusException(HttpStatus.FORBIDDEN, "no person at level 0"); return store.of(person); }
With required = true (the default) a handler never runs without a verified context: on a path that is
not on the route map the request is refused with 401.
boolean required() default trueRefuse (401) when there is no verified context; false gives null instead.
allowedby-spring-boot-starter/spring/AllowedByContextResolver.java#
sdks/java/allowedby-spring-boot-starter/src/main/java/org/allowedby/spring/AllowedByContextResolver.java
public final class AllowedByContextResolver implements HandlerMethodArgumentResolverResolves AllowedByContext parameters from the request attribute the filter set.
allowedby-spring-boot-starter/spring/AllowedByCustomizer.java#
sdks/java/allowedby-spring-boot-starter/src/main/java/org/allowedby/spring/AllowedByCustomizer.java
public interface AllowedByCustomizerAdjusts the AllowedBy the starter builds, after the allowedby.* properties: add routes and
templates in code, a trust list, a clock.
@Bean AllowedByCustomizer routes() { return b -> b.route(Route.get("/notes").capability("notes:read")).template("notes:read", "Read your notes"); }
void customize(AllowedBy.Builder builder)Change the builder.
allowedby-spring-boot-starter/spring/AllowedByProperties.java#
sdks/java/allowedby-spring-boot-starter/src/main/java/org/allowedby/spring/AllowedByProperties.java
public class AllowedByPropertiesallowedby.* properties. Unknown keys fail the start (ignoreUnknownFields = false): a misspelt or
unsupported option is never silently ignored.
allowedby: origin: https://api.example.com node: https://node.example.org org: { legal-name: Example Ltd, country: FR } routes:
- { method: GET, path: /notes, capability: "notes:read", level: 1, resource: "note:*" }
- { method: DELETE, path: "/notes/{id}", capability: "notes:delete", action-class: write-hard, level: 2, resource: "note:{id}" } templates: "[notes:read]": Read your notes "[notes:delete]": Delete note {scope}
public static class RateA rate limit: at most calls calls per per.
public int getCalls()public void setCalls(int calls)public Duration getPer()public void setPer(Duration per)public static class OrgYour organisation (ORG-1 §2).
public String getLegalName()public void setLegalName(String legalName)public String getCountry()public void setCountry(String country)public String getWebsite()public void setWebsite(String website)public String getSupport()public void setSupport(String support)public String getPrivacyPolicy()public void setPrivacyPolicy(String privacyPolicy)public static class RoutePropertiesOne route (ABY-3 §4.1). The reference's other options are accepted here only to refuse them by name:
nonce, mandate, require-link, authority, disclose,
disclose-optional are not enforced by this SDK yet, so setting one fails the start.
public String getMethod()public void setMethod(String method)public String getPath()public void setPath(String path)public String getCapability()public void setCapability(String capability)public String getActionClass()public void setActionClass(String actionClass)public Integer getLevel()public void setLevel(Integer level)public String getResource()public void setResource(String resource)public String getAmountField()public void setAmountField(String amountField)public String getCurrencyField()public void setCurrencyField(String currencyField)public String getAuthn()public void setAuthn(String authn)public Integer getTier()public void setTier(Integer tier)public Duration getMaxLifetime()public void setMaxLifetime(Duration maxLifetime)public String getLevelProfile()public void setLevelProfile(String levelProfile)public Boolean getQes()public void setQes(Boolean qes)public String getSummary()public void setSummary(String summary)public Boolean getNonce()public void setNonce(Boolean nonce)public Boolean getMandate()public void setMandate(Boolean mandate)public Boolean getRequireLink()public void setRequireLink(Boolean requireLink)public String getAccountParam()The path parameter that names one of your accounts, for require-link (default account).
public void setAccountParam(String accountParam)public Boolean getAuthority()public void setAuthority(Boolean authority)public List<String> getDisclose()public void setDisclose(List<String> disclose)public List<String> getDiscloseOptional()public void setDiscloseOptional(List<String> discloseOptional)public boolean isEnabled()public void setEnabled(boolean enabled)public String getOrigin()public void setOrigin(String origin)public String getNode()public void setNode(String node)public Org getOrg()public void setOrg(Org org)public List<RouteProperties> getRoutes()public void setRoutes(List<RouteProperties> routes)public Map<String, Object> getTemplates()public void setTemplates(Map<String, Object> templates)public List<String> getUnprotected()public void setUnprotected(List<String> unprotected)public Path getKeyFile()public void setKeyFile(Path keyFile)public int getRefreshSeconds()public void setRefreshSeconds(int refreshSeconds)public int getNodeMaxLevel()public void setNodeMaxLevel(int nodeMaxLevel)public String getTitle()public void setTitle(String title)public String getVersion()public void setVersion(String version)public String getDescription()public void setDescription(String description)public boolean isRfc9421()public void setRfc9421(boolean rfc9421)public boolean isNonce()public void setNonce(boolean nonce)public Map<String, Rate> getRate()public void setRate(Map<String, Rate> rate)public int getFilterOrder()public void setFilterOrder(int filterOrder)