Repository navigation
Add UserRoles, a supported way for plugins to set a user's role - #73
Merged
Merged
Conversation
OIDC Authentication sets a user's role from identity provider groups, and the LDAP plugin, not released yet, does the same from directory groups. Both call rbac's repository by reflection. Those calls bypass rbac's last-admin check, cache refresh and audit event, so each plugin repeats the check and the refresh itself. com.diridium.rbac.UserRoles is the supported way. Plugins still call it by reflection: - isReady, roleNames, adminRoleName, currentRoleName and assign, all static. - Roles by name, compared exactly on every database. - assign returns ASSIGNED, ALREADY_ASSIGNED, NO_SUCH_ROLE, LAST_ADMIN or NOT_READY, and throws on unexpected failures. - It keeps the last admin on the admin role, refreshes that user's cached permissions, and records an audit event naming the plugin. Role changes on one engine now run one at a time: UserRoles.assign and the Administrators' Assign Role and Remove Role hold one lock from the last-admin check through the write. A lock was rejected on 2026-06-12, when only people changed roles. Plugins change roles at every sign-in, and a restart doesn't repair a race there: rbac restores the admin role at startup only to a user 1 left with no role. The direct repository calls OIDC Authentication 1.0.3 makes keep working and are deprecated. The release notes will name the release that ends support for them. Tests: unit tests for each code assign returns, a race test that fails without the lock, a contract test pinning the class name, its public methods and the codes, and an e2e check that calls UserRoles from a channel deploy script by reflection on all six databases. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OIDC Authentication sets each user's role from identity provider groups, and the LDAP plugin, not released yet, does the same from directory groups. Both call rbac's repository by reflection. Those calls bypass rbac's last-admin check, cache refresh and audit event, so each plugin repeats the check and the refresh itself, and two plugins can race each other.
This adds
com.diridium.rbac.UserRoles, a supported way to do it. Plugins still call it by reflection, with no build or install dependency on rbac.isReady(),roleNames(),adminRoleName(),currentRoleName(userId)andassign(userId, roleName, callerPlugin).assignreturnsASSIGNED,ALREADY_ASSIGNED,NO_SUCH_ROLE,LAST_ADMINorNOT_READY, and throws on an unexpected failure such as the database being down.Role changes on one engine now run one at a time.
UserRoles.assignand Assign Role and Remove Role in both Administrators hold one lock from the last-admin check through the write. Before, two demotions of the last two admins at the same moment could both go through and leave no admin; now the second is refused. A lock was rejected on 2026-06-12, when only people changed roles. Plugins change roles at every sign-in, and a restart doesn't repair a race there: rbac restores the admin role at startup only to a user 1 left with no role. The lock covers one engine. Engines sharing one database don't wait for each other (issue #62).The repository calls OIDC Authentication 1.0.3 makes are unchanged and still pinned by
ReflectionCallerContractTest. They are deprecated: the README says so, and the release notes will name the release that ends support for them (issue #72). The LDAP plugin is to useUserRolesfrom its first release.Docs: a README section for plugin authors, CLAUDE.md and a design notes entry. The wiki pages go out with the release.
Tests:
assignreturns, a name differing only in case where the database ignores case, the last admin kept, a database failure thrown with nothing recorded, the audit event and the one user's cache refresh.UserRoles, once with one throughUserRolesand one through the Administrator's Assign Role. With the lock removed, both demotions went through in both cases and no admin was left. With only the Administrator path's lock removed, the second case failed.UserRolesfrom a channel deploy script on OIE 4.7.0, by reflection and with no signed-in user, as a sign-in plugin does: every code, the case check, the last admin kept, the user's next request allowed at once, and one audit event naming the plugin. The whole e2e suite passed on OIE 4.7.0 with each database: Derby 353 checks, MySQL 366, Postgres 367, Oracle 359, SQL Server 366 with the jTDS driver and 366 with Microsoft's, no failures.Closes #56
Co-authored with Claude Code.