Skip to content

Commit 2b48466

Browse files
committed
Skip /users restriction when signup mgmt is disabled
1 parent ed3ccbf commit 2b48466

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

accounts/src/main/java/org/restheart/accounts/AccountsInitializer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ public void init() {
8080
if (!"users".equals(mr.getCollectionName())) return false;
8181
if (!RequestOverrides.db(mr, conf).equals(mr.getDBName())) return false;
8282

83+
// A tenant that never enabled Sign-up Management never opted into
84+
// restheart-accounts's opinions on /users — see RequestOverrides.SIGNUP_MGMT_ENABLED.
85+
// Must be checked here (during authorization) rather than via a post-auth
86+
// interceptor: vetoes are evaluated as part of authorization, which runs
87+
// before any REQUEST_AFTER_AUTH interceptor gets a chance to run.
88+
if (!RequestOverrides.signupMgmtEnabled(mr, conf)) return false;
89+
8390
// Roles configured via `users-unrestricted-roles` (e.g. an admin console
8491
// role) bypass this restriction entirely — see AccountsConfigData. Reads
8592
// the per-team override first (set by e.g. TeamConfigInterceptor), falling

accounts/src/main/java/org/restheart/accounts/util/RequestOverrides.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ public final class RequestOverrides {
152152
/** Roles exempt from the {@code /users} self-service write restriction (override for multi-team). */
153153
public static final String USERS_UNRESTRICTED_ROLES = "override-accounts-users-unrestricted-roles";
154154

155+
/**
156+
* Whether Sign-up Management is enabled for this tenant (override for multi-team).
157+
* When explicitly {@code false}, the {@code /users} self-service write restriction
158+
* is skipped entirely — a tenant that never opted into restheart-accounts never
159+
* opted into its opinions on {@code /users}. Must be set before authentication
160+
* (e.g. {@code REQUEST_BEFORE_EXCHANGE_INIT}), since the veto is evaluated as part
161+
* of authorization, before any {@code REQUEST_AFTER_AUTH} interceptor runs.
162+
*/
163+
public static final String SIGNUP_MGMT_ENABLED = "override-accounts-signup-mgmt-enabled";
164+
155165
private RequestOverrides() {}
156166

157167
// ── Accessor methods ──────────────────────────────────────────────────────
@@ -219,6 +229,15 @@ public static List<String> usersUnrestrictedRoles(ServiceRequest<?> req, Account
219229
return list(req, USERS_UNRESTRICTED_ROLES, conf.usersUnrestrictedRoles());
220230
}
221231

232+
/**
233+
* Whether Sign-up Management is enabled for this tenant. Defaults to {@code true}
234+
* (restriction fully enforced) unless a deployment-layer interceptor explicitly
235+
* attaches {@code false}.
236+
*/
237+
public static boolean signupMgmtEnabled(ServiceRequest<?> req, AccountsConfigData conf) {
238+
return bool(req, SIGNUP_MGMT_ENABLED, true);
239+
}
240+
222241
/**
223242
* Per-team Google OAuth config, or {@code null} if not overridden.
224243
* When non-null, this takes precedence over the static {@link OAuthConfig}.

0 commit comments

Comments
 (0)