One source for the tenant on every page, and 404 for unknown tenants #7

Open
dasniko wants to merge 5 commits from participant-tenant-bean into main
Member

Why

The admin pages already got the tenant from the @Named("tenant") bean CurrentTenant (inject:tenant). The participant pages still had it passed in as page data, and it meant something different depending on the page:

  • a bare id string in registration.html and thanks.html
  • the Tenant entity in the meeting pages
  • nothing at all on the remaining pages

The build does not check plain data keys, but it does check inject: expressions. So a wrong expression on a participant page did not fail. It rendered something that looked fine: a dead unsubscribe link, or Tenant(id=…) printed into the page.

A tenant id with a typo (for example in a JUG's iframe) also gave either a page with an empty logo and dead links, or a 500 wherever the events URL was needed.

What changes

  • Participant templates use inject:tenant: registration.html, thanks.html, logoheader.html and the two meeting pages. RegistrationResource and MeetingResource no longer pass tenant as data. A typo such as {inject:tenant.websit} now fails the build, with file and line.
  • CurrentTenant gains getWebsite(), getPrivacy() and getImprint(). It stays a small wrapper rather than exposing the entity, so replyTo, events and css cannot reach a page.
  • TenantAccessFilter answers 404 for an unknown tenant.
    • The check runs after the role check, so a signed-in user cannot probe which tenants exist.
    • The response does not echo the tenant id back.
    • Code after the filter never sees a missing tenant, so it needs no null checks.
  • TenantContext.getTenant() returns null instead of calling Tenant.findById(null) on endpoints that have no {tenant} path segment. This check used to be repeated in TenantStyle.
  • The mail templates keep their tenant data from EmailService. They were left out of this change on purpose.

Behavior change

Request for an unknown tenant Before After
/registration/{x}?eventId=… 500 404
/registration/{x}/delete 200, page with empty data 404
/registration/{x}/ical/{eventId} 500 404
/meeting/{x}/{eventId} 200, empty logo and links 404

Known tenants behave as before.

Pitfall worth knowing

The filter checks that the tenant exists with Tenant.count(...) and does not load it via tenantContext.getTenant(). Loading the entity in the filter caches it outside any transaction. A later @Transactional resource then changes an entity its own session does not manage. That is what happened with the JUG data form: it saved nothing and reported no error. testTenantCssStylesTheParticipantPagesOnly caught it. The reason is written down in the filter's code comment and in CLAUDE.md.

Tests

  • New: the deregistration links. The test checks the full unsubscribe link on the thank-you page, not just the id cut out of it. It also checks the "Dann klicke hier" link on the registration form, which no test covered before.
  • New: the meeting pages. The tests check the JUG name, the privacy and imprint links in the logo header, and the homepage button on the "not available" page. The expected values come from tenantFieldOfTemplate(...) instead of being hardcoded.
  • New: unknown tenants. A parameterized test expects 404 for an unknown tenant on all four endpoint types.
  • The new tests can fail: each was checked by breaking the template expression it covers and watching it go red.
  • Full suite: all 53 tests pass with ./mvnw test.
  • Manual check in dev mode: registration, the thank-you page and the unsubscribe link, both meeting page variants, and the admin JUG data page all work. Unknown tenants get a 404 there too.

Docs

CLAUDE.md and the javadoc of CurrentTenant, TenantStyle and TenantContext are updated. Two new notes in CLAUDE.md:

  • why the filter uses count() (the pitfall above)
  • dev mode: hot reload compiles without Lombok, so editing a Lombok class while quarkus:dev runs needs a restart with ./mvnw clean compile quarkus:dev
### Why The admin pages already got the tenant from the `@Named("tenant")` bean `CurrentTenant` (`inject:tenant`). The participant pages still had it passed in as page data, and it meant something different depending on the page: - a bare id string in `registration.html` and `thanks.html` - the `Tenant` entity in the meeting pages - nothing at all on the remaining pages The build does not check plain data keys, but it does check `inject:` expressions. So a wrong expression on a participant page did not fail. It rendered something that looked fine: a dead unsubscribe link, or `Tenant(id=…)` printed into the page. A tenant id with a typo (for example in a JUG's iframe) also gave either a page with an empty logo and dead links, or a 500 wherever the events URL was needed. ### What changes - **Participant templates use `inject:tenant`**: `registration.html`, `thanks.html`, `logoheader.html` and the two meeting pages. `RegistrationResource` and `MeetingResource` no longer pass `tenant` as data. A typo such as `{inject:tenant.websit}` now fails the build, with file and line. - **`CurrentTenant`** gains `getWebsite()`, `getPrivacy()` and `getImprint()`. It stays a small wrapper rather than exposing the entity, so `replyTo`, `events` and `css` cannot reach a page. - **`TenantAccessFilter` answers 404 for an unknown tenant.** - The check runs after the role check, so a signed-in user cannot probe which tenants exist. - The response does not echo the tenant id back. - Code after the filter never sees a missing tenant, so it needs no null checks. - **`TenantContext.getTenant()`** returns `null` instead of calling `Tenant.findById(null)` on endpoints that have no `{tenant}` path segment. This check used to be repeated in `TenantStyle`. - **The mail templates keep their tenant data** from `EmailService`. They were left out of this change on purpose. ### Behavior change | Request for an unknown tenant | Before | After | |---|---|---| | `/registration/{x}?eventId=…` | 500 | 404 | | `/registration/{x}/delete` | 200, page with empty data | 404 | | `/registration/{x}/ical/{eventId}` | 500 | 404 | | `/meeting/{x}/{eventId}` | 200, empty logo and links | 404 | Known tenants behave as before. ### Pitfall worth knowing The filter checks that the tenant exists with `Tenant.count(...)` and does **not** load it via `tenantContext.getTenant()`. Loading the entity in the filter caches it outside any transaction. A later `@Transactional` resource then changes an entity its own session does not manage. That is what happened with the JUG data form: it saved nothing and reported no error. `testTenantCssStylesTheParticipantPagesOnly` caught it. The reason is written down in the filter's code comment and in `CLAUDE.md`. ### Tests - **New: the deregistration links.** The test checks the full unsubscribe link on the thank-you page, not just the id cut out of it. It also checks the "Dann klicke hier" link on the registration form, which no test covered before. - **New: the meeting pages.** The tests check the JUG name, the privacy and imprint links in the logo header, and the homepage button on the "not available" page. The expected values come from `tenantFieldOfTemplate(...)` instead of being hardcoded. - **New: unknown tenants.** A parameterized test expects 404 for an unknown tenant on all four endpoint types. - **The new tests can fail:** each was checked by breaking the template expression it covers and watching it go red. - **Full suite:** all 53 tests pass with `./mvnw test`. - **Manual check in dev mode:** registration, the thank-you page and the unsubscribe link, both meeting page variants, and the admin JUG data page all work. Unknown tenants get a 404 there too. ### Docs `CLAUDE.md` and the javadoc of `CurrentTenant`, `TenantStyle` and `TenantContext` are updated. Two new notes in `CLAUDE.md`: - why the filter uses `count()` (the pitfall above) - **dev mode:** hot reload compiles without Lombok, so editing a Lombok class while `quarkus:dev` runs needs a restart with `./mvnw clean compile quarkus:dev`
The participant pages are about to read the tenant from a different source.
Every expression involved renders something plausible when it is wrong, and
the suite could not tell: the unsubscribe tests cut the id out of the href
and built their own URL, the deregistration link on the form was not checked
at all, and the meeting page was only checked through a structural XML path
that stays green when logo, name and legal links all render empty.

Signed-off-by: Niko Köbler <niko@n-k.de>
`tenant` meant a bare id string on the registration pages, the Tenant entity
on the meeting pages and nothing at all on the rest, so a wrong expression
still rendered: an entity printed via toString, or an unsubscribe link with
the wrong prefix. Plain data keys are not validated at build time, inject:
expressions are -- moving the participant pages onto CurrentTenant gives them
the same protection the admin pages already have. The bean stays a narrow
delegate so replyTo, events and css never become reachable from a page.

The mail templates keep their own tenant data: they render on a worker thread
and should not depend on a request context being active there.

Signed-off-by: Niko Köbler <niko@n-k.de>
CLAUDE.md and the CurrentTenant/TenantStyle javadoc still explained the design
by the participant pages passing their own, inconsistent `tenant` data. That
is no longer true, and TenantStyle needed its real reason for being a bean
written down instead of a symptom that has now been fixed.

Signed-off-by: Niko Köbler <niko@n-k.de>
CurrentTenant and TenantStyle each carried the same "no tenant id" guard, and
every further bean reading the tenant would have copied it a third time. The
check belongs where the entity is loaded: TenantContext.getTenant() now
answers null instead of calling Tenant.findById(null), so readers only have to
handle the one case they already had to, an unknown tenant.

The new test assertions read the expected tenant fields through the existing
tenantFieldOfTemplate helper instead of repeating the seed data, and the
unsubscribe test takes the id from the same pattern that checks the href.

Signed-off-by: Niko Köbler <niko@n-k.de>
Reject unknown tenants with 404 in TenantAccessFilter
All checks were successful
CI Build / build (push) Successful in 2m6s
CI Build / build (pull_request) Successful in 2m10s
52a76cb4e2
A tenant id mistyped in a JUG's iframe or link used to render a page with an
empty logo and dead links, or a 500 wherever the events URL was needed --
anyone could trigger either, and a visitor got no hint what went wrong.
Answering 404 where the tenant is resolved means nothing downstream has to
cope with a missing tenant, so CurrentTenant drops its null handling again.

The check counts instead of loading the entity: caching it in TenantContext
from the filter, outside any transaction, left it detached for the JUG data
form, which then saved nothing without an error.

Also corrects the reason given for the mail templates keeping their tenant
data -- they were not migrated, the worker thread is no obstacle -- and
records the dev-mode Lombok hot-reload trap hit along the way.

Signed-off-by: Niko Köbler <niko@n-k.de>
All checks were successful
CI Build / build (push) Successful in 2m6s
CI Build / build (pull_request) Successful in 2m10s
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'participant-tenant-bean:participant-tenant-bean'
git switch 'participant-tenant-bean'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'participant-tenant-bean'
git switch 'participant-tenant-bean'
git rebase 'main'
git switch 'main'
git merge --ff-only 'participant-tenant-bean'
git switch 'participant-tenant-bean'
git rebase 'main'
git switch 'main'
git merge --no-ff 'participant-tenant-bean'
git switch 'main'
git merge --squash 'participant-tenant-bean'
git switch 'main'
git merge --ff-only 'participant-tenant-bean'
git switch 'main'
git merge 'participant-tenant-bean'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ijug-ev/registration!7
No description provided.