Why AuthorizationInterceptor rules decide who sees what in HAPI FHIR
The AuthorizationInterceptor is the HAPI FHIR building block that enforces allow and deny rules on each request, so it decides which resources, compartments and operations a caller can reach. HAPI FHIR does not ship a single security layer. The project describes a set of building blocks instead, and the rules you write in this interceptor are the part that turns an authenticated caller into a concrete list of permitted reads, searches and writes. If your JPA server holds patient data, or serves more than one application or user population, you need these rules before go-live, because a server with no rules will return data to any caller who gets past authentication.
Teams usually need rules when they move from a single trusted client to several apps or users with different scopes: a clinician portal that should see only its own patients, a scheduling app that should write Appointment resources but never read Observation, or a bulk integration that should be limited to a fixed set of resource types. Rules sit alongside authentication, which establishes who the caller is, and alongside consent and search narrowing, which handle finer patient-level and result-level limits. Rules do not replace those controls. Before you write any rule, confirm with your security and compliance owners which of these layers they expect you to enforce, and record that split in your design.
Start by listing the request patterns your real clients send, including searches, conditional updates, $everything style operations and batch bundles, since the interceptor evaluates each one differently. Then confirm the version of HAPI FHIR you run and its JDK requirement against the HAPI FHIR versions page, and check the interceptor's current configuration options in the security documentation for that version. Plan to test rules against captured or replayed requests from each client before release, because a rule that looks correct for a single read can still leak data through a search or a bundle.
Choosing rules by resource type, compartment and operation
Resource type rules allow or deny access based on the kind of resource in the request, such as Patient, Observation or Binary. They are the simplest basis to reason about and the easiest to review with a security team, because the rule reads like a plain statement of which data categories a role may touch. They fit coarse controls, such as keeping a scheduling application away from clinical notes or keeping a reporting role to read-only access on a few types.
- Coarse by design: A type rule cannot tell one patient's Observation from another's, so it is a boundary between categories, not between people.
- Fragile with related types: Some data appears inside other resources or in Bundles, so denying a type does not always deny its content. Test that the denied type cannot be reached through a parent, a search include or a bundle entry.
- Hard to keep current: New resource types added in a later FHIR release need a deliberate decision, so confirm the default for unlisted types.
- Version-sensitive names: Confirm the exact resource names and rule builder methods for the HAPI FHIR version in use before relying on them.
Check that every type you intend to protect is listed in a rule and that the default for unlisted types is deny.
Compartment rules tie access to a patient or other subject. FHIR defines compartments that group resources belonging to one patient, so a rule can allow a clinician or patient to see only resources linked to the patients they are permitted to see. This is the usual basis for patient-scoped access, and it is what most healthcare teams mean when they ask for patient-level control.
- Patient-level control: A compartment rule expresses the question "is this resource about a patient I may see?" which matches how clinical access is reviewed.
- Resources outside the compartment: Some resources, such as Practitioner, Organization or terminology content, do not belong to a patient compartment, so decide explicitly whether they are open, shared or denied.
- Linkage errors: The rule depends on the reference that places a resource in the compartment. Malformed or missing references can make data fall outside the rule, so test with incomplete records.
- Search interaction: Compartment checks on single reads do not automatically restrict searches. Pair them with search narrowing where the outline calls for it.
Confirm how the installed version determines compartment membership for each resource type you hold.
Operation rules separate what a caller does with a resource: read, search, create, update, delete, transaction and export. The same caller may need to read a patient record but never delete it, or may run searches but not bulk export. Operation rules express least privilege most directly, and they are where most accidental over-permission appears when a team grants a broad role and forgets the write or export paths.
- Separate verbs: Grant read and search separately from write operations, and treat delete and expunge as privileged actions.
- Transactions hide writes: A transaction or batch Bundle can carry create, update and delete entries, so a rule that only checks the outer request may miss the writes inside it.
- Export is different: Bulk export reads many resources and writes files, so it needs its own rule and should be reviewed alongside Binary access.
- Conditional operations: Conditional create and update use search criteria, so a caller with search rights may influence writes.
Test each operation with a dedicated account and confirm how the installed version classifies transactions and conditional requests.
Query-based rules inspect the search parameters or the request content and decide whether the request is allowed or must be narrowed. They are used when access depends on what is being asked for, such as limiting searches to a set of patient identifiers or refusing queries without a patient parameter. They sit closest to the data but are the most sensitive to how clients build requests.
- Parameter dependence: A rule that requires a patient parameter stops broad searches, but clients can still use chained, included or reverse-chained parameters to reach other data.
- Narrowing versus refusing: Decide whether an out-of-scope query should be rejected or narrowed to permitted results, since each produces different client behavior.
- Include and revinclude paths: Included resources can carry data the caller is not meant to see, so test these paths specifically.
- Illustrative example: A rule allowing searches only when the patient parameter matches the caller's permitted patient is easy to state, but a search for Observation by another parameter may still return rows unless a second rule covers it.
Run representative client queries from your application logs against each rule set before accepting it.
How to build and test rules step by step
This sequence takes you from observed client traffic to a tested AuthorizationInterceptor policy, so each allow rule traces back to a real access need and each deny is confirmed by a negative test. The output is a versioned rule set with recorded test evidence that your security and clinical stakeholders can review.
Inventory real client request patterns
Collect the requests your clients actually send before writing any rule. Pull access logs from an existing environment or capture traffic from a staging server with the same client apps, recording the HTTP method, resource type, operation (read, search, create, update, history, operations), query parameters and the identity making each call. Group the results by client and by user role. The step is done when you have a list of distinct request patterns per client that a reviewer can check against the source logs, and when you know which patterns contain patient identifiers. Capture only what you are permitted to keep, and remove or pseudonymize identifiers in any copy that leaves the environment.
Define roles and the access each needs
Turn the grouped patterns into a short matrix of roles, such as clinician, care coordinator, integration client and administrator. For each role, list the resource types it reads or writes, the operations it needs, and whether its access is limited to particular patients. Mark administrative operations separately, since they should sit outside general application roles. Have a clinical or business owner and a security reviewer sign off on the matrix. The step is complete when every pattern from the inventory maps to a role, and every role has a written justification for each allowed operation. Unmapped patterns are a signal to either add a role or drop the request.
Write default deny with narrow allows
In the AuthorizationInterceptor, start with a rule set that denies everything not explicitly allowed. Then add allow rules built from the matrix, scoping each by resource type and operation rather than granting broad system-level access. Keep each role's rules in its own block so reviewers can read them in isolation. Store the rule code in version control with a change record for each edit. Verify the result by starting the server with the rules loaded and confirming that an unauthenticated request and a request from a role with no rules both return an authorization failure. The check is that the deny behavior is observed on the running server, not only read in the code.
Add patient-scoped rules
For roles that should see only certain patients, add rules that tie access to a compartment such as Patient, using the patient identity the authenticated user is entitled to. Decide how each access path is covered: direct reads by resource ID, searches with a patient parameter, and resources that reference the patient indirectly. Note which patterns the rules cannot express on their own and mark them for handling by search narrowing or consent controls covered in sibling topics. The check is a short table listing each patient-scoped pattern from the inventory with the rule that covers it and a test case that proves it, including a case where a user requests a patient outside their entitlement.
Wire the interceptor to identity claims
Connect the rules to the claims issued by your external identity provider, so the interceptor reads the role and patient entitlement from a validated token rather than from client-supplied fields. Confirm the token issuer, audience and signature checks happen before the rules are evaluated, and map each claim the rules depend on to a documented name. Test with at least one token per role, one expired token and one token signed by an unexpected issuer. The check is that each role resolves to the expected rule set in the server logs, and that the rejected tokens never reach rule evaluation. Confirm the exact claim names and validation options with your identity provider and the HAPI FHIR security documentation for your version.
Test with recorded request patterns
Replay the request patterns captured in the first step against a staging server running the new rules, using the same tokens each original client would send. Record for every request whether the outcome matches the expected result in the matrix. Store the replay script and its results with the rule version so the test can be rerun after each change. The check is a pass or fail table covering every pattern in the inventory, with any mismatch investigated and either fixed in the rules or recorded as an accepted gap with an owner. Do not promote the rules until the table is complete.
Test negative cases and close gaps
Write negative tests that try to exceed each role: cross-patient reads, searches without a patient parameter, writes by read-only roles, history and bulk operations, administrative endpoints, and requests that omit or alter filter parameters. Include attempts to use the patient ID of another user and to reach resources through included or chained references. Each denied request should return an authorization failure and produce an audit record if auditing is enabled. The final check is that every negative test fails closed, the results are archived with the rule version, and a reviewer has accepted the remaining known limits in writing before go-live.
Rule design options and when each fits
This table compares the main design choices for AuthorizationInterceptor rules, from the default stance to how rules are grouped by role or client. Read each row as a decision: the option, what it costs to maintain, what it does to search behavior, and the situation where it is the better starting point. The main takeaway is that the default stance and the rule grouping decide most of the maintenance burden, so settle them before writing individual rules.
| Design choice | Trade-off | When it fits |
|---|---|---|
| Default deny | Every permitted resource type and operation must be granted explicitly, so new resource types stay blocked until someone adds a rule. | Regulated data with a small, known set of clients and interactions, where a missed grant is safer than an unintended exposure. |
| Default allow | Less upfront writing, but any resource type or operation not covered by a deny rule is reachable, so gaps are easy to miss. | Internal test or sandbox servers with non-sensitive data, or only when a complete deny list is reviewed on every release. |
| Compartment-based patient scoping | Rules follow the Patient compartment, which keeps patient rules short, but resources outside a compartment need separate handling. | Patient-facing apps where each user reads only their own record and the compartment model fits the data. |
| Explicit resource lists | Each resource type and operation is named, which is verbose and needs updates when new types are used, but intent is easy to audit. | Workforce or clinical roles with defined duties, and assessors who ask for a readable list of what each role can reach. |
| Query filter rules | Filters restrict which search results a rule allows, giving fine control, but each filter adds matching work to every search it covers. | Narrow cases such as limiting a role to records with a specific tag or category, where the filter is simple and well tested. |
| Narrowing interceptor scoping | Searches are rewritten to the permitted compartments, which keeps results inside scope but adds search-time behavior that must be tested with the authorization rules. | Searches that must return only a user's patients, typically paired with authorization rules for the same users. |
| Per-role rule sets | Shared rules are easy to reason about and change in one place, but a role that needs a one-off exception can make the set harder to follow. | Several users with the same job function who need the same access across clients. |
| Per-client rule sets | Each application gets exact permissions and is easy to revoke, but many clients multiply the rules to maintain and test. | Small numbers of integrations or SMART-style apps, where each client's scopes differ and need separate review. |
How a request passes through authentication and authorization
The flow starts with a client app that obtains a token from the external identity provider, then sends the FHIR request through a reverse proxy to the HAPI FHIR JPA server. Inside the server, the authentication interceptor validates the token before the AuthorizationInterceptor evaluates allow and deny rules against the resource type, compartment and operation. Only permitted requests reach the database. Check that the trust boundary sits where token validation happens, and that the audit and search narrowing interceptors see the same identity the rules used.
Request path from client through the identity provider, interceptors and JPA server to the database.
Common rule mistakes that expose data
Most AuthorizationInterceptor failures are not missing rules. They are rules that match more requests than the author intended, or requests the author never considered. The cards below cover the gaps we see most often, each with a check you can run against your own rule set before go-live.
Allow rules that are too broad
A rule such as allowing all reads on a resource type grants access to every record of that type, including patients outside the user's care team. In the AuthorizationInterceptor, an allow rule with no compartment or instance restriction is a full grant. Check each allow rule by asking which records a single client identity could read if it sent any valid request, and confirm the answer matches the access policy in writing.
HAPI FHIR security docsForgotten history and batch operations
Rules written around read and search are often silent on history at the server, type and instance level, on $everything-style operations, and on transaction bundles. A batch or transaction can carry writes for many resources in one request, so a rule that only checks the outer request can miss inner entries. Check that each interaction and operation is either explicitly permitted for the role or denied, and test a transaction bundle that mixes permitted and forbidden resource types.
Search parameters that skip compartment checks
A rule scoped to a patient compartment can be bypassed when a search uses parameters that point at resources outside that compartment, or when chained parameters reach into another patient's data. The rule checks the resource type named in the URL, not every resource the result set might include. Check searches on each permitted type with patient, subject and chained parameters, and confirm that results only include records the user may see.
Conditional updates and deletes
Conditional create, update and delete select target resources by search criteria rather than by ID. If the rule evaluates the write using the ID in the body or URL and not the criteria that the server resolves, a client can change a record it was never granted. Check that conditional writes are evaluated against the matched resources, and test a conditional update whose criteria match a record outside the user's compartment.
Trusting client-supplied patient identifiers
Rules that take the patient ID from a request parameter, a header or a body field trust the client to name its own scope. A client can name any patient ID it likes, so the check must bind the patient to the authenticated token or to a server-side lookup, not to what the request claims. Check that every patient-scoped rule derives the patient from the verified identity source, and send requests that change only the patient parameter to confirm they are denied.
Rules that were never retested
Rules drift when resource types, search parameters or HAPI FHIR versions change, and a rule that passed last quarter can now leak through a new parameter. Upgrades can also change how operations and interceptors behave, so behavior must be confirmed in the target version. Keep a fixed set of allowed and denied requests per role, run it on every rule change and every upgrade, and record the results. Confirm the release you run against the HAPI FHIR versions page before you build the suite.
HAPI FHIR versionsQuestions teams ask before writing AuthorizationInterceptor rules
How much effort does designing and testing AuthorizationInterceptor rules take?
The effort depends mostly on how many resource types, roles and access patterns the server must separate, not on the interceptor itself. A small server with a few client types and read-only access is far simpler than a multi-tenant or patient-facing deployment with compartments, query filters and write rules. Cost components are the analysis of who needs what, the rule implementation, a test suite built from real request patterns, and the review cycle with stakeholders. Most of the cost is one-time, but rules need ongoing work whenever new applications, roles or resource types are added. Ask any partner for a quote that lists these components separately and names the request patterns it will test.
Can an internal team write AuthorizationInterceptor rules without outside help?
Yes, if the team has Java and Spring experience, a working knowledge of FHIR search and compartments, and time to test thoroughly. The hard part is rarely the Java code. It is deciding what each role may see and do, then proving that the rules deny what they should. Teams without a security engineer or a clinical informatics contact often miss edge cases such as chained searches, included resources and conditional writes. An outside review of the rule set and its tests is a common middle path. DeployOpen can plan, implement and test these rules inside your infrastructure under a written scope, but your team keeps ownership of the server.
What do identity and clinical stakeholders need to provide?
Rules are only as accurate as the access model behind them, so both groups must be involved early. Identity teams provide the token claims, scopes or roles that the identity provider issues, along with how they map to applications and users. Clinical or business stakeholders define which patients, encounters or record types each role may see, and which exceptions, such as break-glass access, are approved. Ask for a written access matrix signed off by both groups before implementation starts. Without it, rules tend to be written around whatever the identity provider happens to issue, which creates gaps later.
How do AuthorizationInterceptor rules change across HAPI FHIR upgrades?
Rules are Java code that runs against the server's request handling, so each upgrade needs a review of the interceptor behavior, the FHIR version in use and any changes to search or compartment handling. Check the release notes for the version you are moving to and rerun the full rule test suite before promoting the upgrade. The upgrade path also covers the Java runtime, since HAPI FHIR 8.2.0 requires JDK 17, and the database schema. Plan the rule tests as part of the upgrade, not as an afterthought, and confirm the target version in the HAPI FHIR versions documentation before scheduling work.
Do authorization rules alone meet privacy obligations?
No. Rules control which requests a client may make, but privacy and security obligations also cover authentication, audit records, consent decisions, data at rest, backups, administrative access and staff procedures. HAPI FHIR describes its security features as building blocks rather than a single complete security layer, so the operator must combine them with other controls. Consent management, search narrowing and audit logging are separate pieces of work that interact with the rules. Confirm with your compliance lead and legal counsel which obligations apply to your data and which controls you must document. DeployOpen prepares systems and evidence for compliance assessments, but independent auditors and certification bodies issue any audit reports or certifications.
What makes a rule test suite good enough to trust?
A useful test suite runs real request patterns against the server with each role or client identity, and checks both the allowed and the denied outcomes. Cover each resource type in scope, read, search, create, update and delete, and include searches that pull in related resources, since those are a common source of leaks. Record the request patterns from your applications and integration partners, then turn them into repeatable tests. Keep the suite in version control and run it on every change to rules, the server version or the identity provider configuration. Ask a partner to show how their test plan maps back to your access matrix.
Which parts of the rule work drive the cost up the most?
The biggest drivers are the number of roles and clients, the depth of patient-scoped access, the number of write operations and the size of the existing data and integration footprint. Compartment logic and query filters add work because each search path needs its own check. Existing applications that send unusual requests, such as large batch bundles or custom operations, add test time. Unclear stakeholder decisions are another common driver, because rework follows every change of policy. A written scope that lists roles, resource types, operations and integrations makes a quote far easier to compare across providers.
Limits to confirm in your environment
The AuthorizationInterceptor rule API, Java requirements, and how rules behave under chained searches, includes and partitions are the points where a design that looks correct on paper can fail in a running server. Confirm each one against the documentation for your exact HAPI FHIR version and against your own tests before you write production rules.
Rule API for your version
The builder methods, rule ordering and classes you use to allow or deny access are tied to a specific release, so a sample from a blog post or an older guide may not compile or may behave differently. Check the versions page and the release notes for the version you plan to run, then pin that version in your build. Record which rule types your design depends on so an upgrade review knows what to retest.
HAPI FHIR versionsJDK 17 requirement
HAPI FHIR 8.2.0 requires JDK 17, so any server build that carries your rule set must run on that JDK or later. Confirm the JDK your application server, container base image and CI pipeline use, because a mismatch fails at startup rather than in a rule test. Include the JDK in the same change record as the HAPI FHIR version so the two are reviewed together.
Chained searches and includes
A rule that permits access to Observation resources does not automatically govern what a chained search or an _include returns from related resource types. Write test requests that chain from an allowed type into a restricted one, and that include restricted resources from an allowed search, then confirm whether the server filters, rejects or leaks the results. Pair this check with the search narrowing design for your patient scope.
Interaction with partitioning
When JPA partitioning places resources in separate partitions for tenancy or regional separation, a rule written against resource type alone may not express the partition boundary you need. Confirm how the authorization decision is made for a request that targets a partition, and whether a user allowed in one partition can read another. Test with at least two partitions holding comparable data before you rely on the rules for isolation.
Partitioning docsRule order and default deny
Rules are evaluated in sequence, and the first match often decides the outcome, so an early broad allow can hide a later narrow deny. Confirm the default behavior when no rule matches for your version, and document the order your rule chain expects. Test a request that matches several rules to see which result the server returns.
Operations outside the rule set
Some operations, such as bulk export, batch processing, history and metadata, may follow code paths that your rules do not cover in the way you expect. Ask your team to list every interaction the server exposes and confirm how each one is authorized for your version. Pair this list with the privileged operation review so that unused interactions are disabled rather than left open.
How DeployOpen scopes and delivers authorization rule work
DeployOpen scopes authorization rule work as a fixed-scope engagement, agreed in writing before any rule is written. The scope starts from a request inventory: every endpoint, resource type, operation, search pattern and admin path the HAPI FHIR server exposes, paired with the role model that the external identity provider and token claims will supply. Without that inventory, an AuthorizationInterceptor rule set tends to cover the requests someone remembered and leave the rest to default behavior. The written scope should name which clients (EHR integrations, portals, bulk export jobs, administrative tools) are in play, which patient compartments apply, and which query filters are expected to narrow results.
Delivery produces the rules themselves, a test suite that replays representative requests against them, and documentation that maps each role to its allowed and denied operations. The tests should include negative cases, such as a clinician token searching outside an assigned patient set, a client with read-only scope attempting a write, and an unauthenticated request to a privileged operation. Your security or compliance team should confirm the role model and the test expectations before sign-off, because the tests only prove what the rules were designed to allow. Ask for the request inventory, the test cases and the change log as named deliverables in the quote. Where HAPI FHIR documentation describes a building block that your scope depends on, confirm the behavior against the HAPI FHIR security introduction for your server version. DeployOpen can prepare systems, controls and evidence for a compliance assessment, but it does not issue audit reports, attestations or certifications; independent auditors and certification bodies do that work. Retainers are available for upgrades and continuous testing, because rules tend to need revision when HAPI FHIR versions change or when new clients are added.

