|
4 | 4 | import org.restheart.accounts.oauth.OAuthConfig; |
5 | 5 | import org.restheart.exchange.ServiceRequest; |
6 | 6 |
|
| 7 | +import java.util.List; |
| 8 | + |
7 | 9 | /** |
8 | 10 | * Reads per-request override parameters and returns the effective values, |
9 | 11 | * falling back to the plugin's static configuration. |
|
66 | 68 | * <td>Google OAuth client secret for this team</td> |
67 | 69 | * <td>{@code null}</td> |
68 | 70 | * </tr> |
| 71 | + * <tr> |
| 72 | + * <td>{@code override-accounts-users-unrestricted-roles}</td> |
| 73 | + * <td>Roles exempt from the {@code /users} self-service write restriction |
| 74 | + * (see {@code AccountsInitializer})</td> |
| 75 | + * <td>{@link AccountsConfigData#usersUnrestrictedRoles()}</td> |
| 76 | + * </tr> |
69 | 77 | * </table> |
70 | 78 | * |
71 | 79 | * <h2>Multi-team usage (restheart-cloud)</h2> |
@@ -139,6 +147,11 @@ public final class RequestOverrides { |
139 | 147 | /** Team role for the user who creates a team (override for multi-team). */ |
140 | 148 | public static final String OWNERSHIP_ROLE = "override-accounts-ownership-role"; |
141 | 149 |
|
| 150 | + // ── Users self-service write restriction override ─────────────────────── |
| 151 | + |
| 152 | + /** Roles exempt from the {@code /users} self-service write restriction (override for multi-team). */ |
| 153 | + public static final String USERS_UNRESTRICTED_ROLES = "override-accounts-users-unrestricted-roles"; |
| 154 | + |
142 | 155 | private RequestOverrides() {} |
143 | 156 |
|
144 | 157 | // ── Accessor methods ────────────────────────────────────────────────────── |
@@ -201,6 +214,11 @@ public static String ownershipRole(ServiceRequest<?> req, AccountsConfigData con |
201 | 214 | return str(req, OWNERSHIP_ROLE, conf.ownershipRole()); |
202 | 215 | } |
203 | 216 |
|
| 217 | + /** Effective roles exempt from the {@code /users} self-service write restriction. */ |
| 218 | + public static List<String> usersUnrestrictedRoles(ServiceRequest<?> req, AccountsConfigData conf) { |
| 219 | + return list(req, USERS_UNRESTRICTED_ROLES, conf.usersUnrestrictedRoles()); |
| 220 | + } |
| 221 | + |
204 | 222 | /** |
205 | 223 | * Per-team Google OAuth config, or {@code null} if not overridden. |
206 | 224 | * When non-null, this takes precedence over the static {@link OAuthConfig}. |
@@ -228,4 +246,13 @@ private static boolean bool(ServiceRequest<?> req, String key, boolean defaultVa |
228 | 246 | if (v instanceof String s) return Boolean.parseBoolean(s); |
229 | 247 | return defaultValue; |
230 | 248 | } |
| 249 | + |
| 250 | + @SuppressWarnings("unchecked") |
| 251 | + private static List<String> list(ServiceRequest<?> req, String key, List<String> defaultValue) { |
| 252 | + var v = req.attachedParam(key); |
| 253 | + if (v instanceof List<?> l && !l.isEmpty()) { |
| 254 | + return (List<String>) l; |
| 255 | + } |
| 256 | + return defaultValue; |
| 257 | + } |
231 | 258 | } |
0 commit comments