You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3c6d536
Browse filesBrowse the repository at this point in the historyBrowse files
docs: document the RegistrationGuard SPI demo in the README
Completes the outstanding documentation task from #58. The demo's
DomainRegistrationGuard (and the framework's RegistrationGuard SPI) was
only described in CLAUDE.md / Javadoc, not the README.
- Add a "Registration Guard (restricting who can register)" section under
Configuration: what the SPI is, how the sample domain guard works, how to
enable it (registration-guard profile + registration.guard.allowed-domain),
and how to write a custom guard, with a link to the framework's
REGISTRATION-GUARD.md.
- List the mfa and registration-guard opt-in profiles in the Configuration
Profiles table.
- Add Features bullets for MFA and the RegistrationGuard SPI.
>`mfa` and `registration-guard` are *opt-in add-on* profiles — activate them alongside a base profile (e.g. `--spring.profiles.active=local,registration-guard`). See [Registration Guard (restricting who can register)](#registration-guard-restricting-who-can-register) below.
301
307
302
308
### Quick Configuration Setup
303
309
@@ -327,6 +333,49 @@ If you're running the application in a production-like environment, ensure you s
327
333
328
334
---
329
335
336
+
### Registration Guard (restricting who can register)
337
+
338
+
The Spring User Framework exposes a `RegistrationGuard` SPI that lets a consuming app allow or deny each registration attempt — useful for invite-code gating, email allowlists, or domain restrictions. The framework calls every `RegistrationGuard` bean for form, passwordless, and OAuth2/OIDC sign-ups; if any guard denies, registration is rejected with the guard's message.
339
+
340
+
This demo ships a sample implementation, [`DomainRegistrationGuard`](src/main/java/com/digitalsanctuary/spring/demo/registration/DomainRegistrationGuard.java), that restricts **form and passwordless** registration to a single email domain while allowing **all OAuth2/OIDC** registrations. It is gated behind the `registration-guard` Spring profile so the default demo experience is unaffected.
341
+
342
+
**Try it:**
343
+
344
+
```bash
345
+
# Only @example.com email addresses can register via the form (OAuth2/OIDC still allowed)
|`registration-guard` profile | off | Activates the sample guard bean |
356
+
|`registration.guard.allowed-domain`|`@example.com`| Domain that form/passwordless registrations must match |
357
+
358
+
With the profile active, registering a non-matching email returns the friendly denial message `Registration is restricted to <domain> email addresses.`
359
+
360
+
**Writing your own guard:** implement `RegistrationGuard` as a Spring bean and return`RegistrationDecision.allow()` or `RegistrationDecision.deny(reason)`. The `RegistrationContext` exposes the email, `RegistrationSource` (FORM / PASSWORDLESS / OAUTH2 / OIDC), and provider name so you can apply different rules per source:
361
+
362
+
```java
363
+
@Component
364
+
public class InviteCodeGuard implements RegistrationGuard {
365
+
@Override
366
+
public RegistrationDecision evaluate(RegistrationContext context) {
367
+
// e.g. look up an invite code carried on the request, check an allowlist, etc.
368
+
returnisInvited(context.email())
369
+
?RegistrationDecision.allow()
370
+
: RegistrationDecision.deny("An invitation is required to register.");
371
+
}
372
+
}
373
+
```
374
+
375
+
Multiple guards compose — all must allow. See the framework's [Registration Guard documentation](https://github.com/devondragon/SpringUserFramework/blob/main/REGISTRATION-GUARD.md) for the full SPI reference.
376
+
377
+
---
378
+
330
379
#### **Mail Sending (SMTP)**
331
380
The application requires an SMTP server for sending emails (e.g., account verification and password reset). Update the SMTP settings in your configuration file:
0 commit comments