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
>`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,50 @@ 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 |
357
+
|`registration.guard.allowed-domain`|`@example.com`| Domain that form/passwordless registrations must match |
358
+
359
+
With the profile active, registering a non-matching email returns the friendly denial message `Registration is restricted to <domain> email addresses.`
360
+
361
+
**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:
362
+
363
+
```java
364
+
@Component
365
+
public class InviteCodeGuard implements RegistrationGuard {
366
+
@Override
367
+
public RegistrationDecision evaluate(RegistrationContext context) {
368
+
// e.g. look up an invite code carried on the request, check an allowlist, etc.
369
+
returnisInvited(context.email())
370
+
?RegistrationDecision.allow()
371
+
: RegistrationDecision.deny("An invitation is required to register.");
372
+
}
373
+
}
374
+
```
375
+
376
+
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.
377
+
378
+
---
379
+
330
380
#### **Mail Sending (SMTP)**
331
381
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