Skip to content

privilege, jdbc: users hold privileges as roles do; a database read as a whole or as its user sees it - #104

Merged
stbischof merged 1 commit into
eclipse-daanse:mainfrom
stbischof:feat/user-privileges
Dec 2, 2026
Merged

stbischof merged 1 commit into
eclipse-daanse:mainfrom
stbischof:feat/user-privileges

Conversation

@stbischof

Copy link
Copy Markdown
Contributor

A database user holds privileges as a role does, and a database is read into a catalog from one of two points of view. Builds on eclipse-daanse/org.eclipse.daanse.sql#112.

try (Connection connection = DriverManager.getConnection(url, user, password)) {
    Catalog all = CwmJdbcImport.load(connection, JdbcToCwmConfig.defaults()
            .withCatalogName("shop").withScope(MetadataScope.DATABASE).withStrictScope(true));
    Catalog mine = CwmJdbcImport.load(connection, JdbcToCwmConfig.defaults()
            .withCatalogName("shop").withScope(MetadataScope.USER));
}

Privilege model

  • A user and a role hold privileges alike: each owns its own, and a member of a role holds the role's besides. The stereotypes databaseUser and databaseRole tell them apart; PUBLIC carries neither.
  • The rules stand in the metamodel as OCL invariants, P1 to P7, each with its sentence and level; PrivilegeModelValidator gives their findings.
  • The selection rule party:<glob> takes the parties of that name with the privileges they own, and nothing else of that name.
  • The DDL writes a membership that names a user only where the dialect grants a user like a role; elsewhere it is left out and logged or, strict, the generation fails.

Scope

  • JdbcToCwmConfig.withScope: DATABASE, the default, every schema, object, role, membership and grant, or USER, what the connected user may see.
  • A connection that may not read the whole database is read as its user sees it, as a whole, never a mix. withStrictScope(true) fails instead, before anything is read, with the MetadataScopeException naming the right the connection lacks.
  • The catalog says what it holds: the tagged value daanse.jdbc.scope is the scope it was read in, daanse.jdbc.scope.requested the scope asked for where the two differ.
  • The goal cwm-jdbc:import takes scope and strictScope.

Example

examples/jdbc.load reads a database with one call: schemas with all they hold, roles and users with their privileges, chosen by rules, in either scope. The same shop is created in Oracle and PostgreSQL and read by the same code, as a whole and as its clerk sees it; the tests compare both catalogs with what is expected and with each other, show the fallback and the strict failure, and read both back from XMI.

@stbischof
stbischof force-pushed the feat/user-privileges branch from 8a7b8f7 to 50c97fc Compare December 2, 2026 16:11
…s a whole or as its user sees it

A database user and a database role hold privileges alike: each owns
its own, and a party that is a member of a role holds the role's
privileges besides. The stereotypes databaseUser and databaseRole tell
them apart; PUBLIC carries neither.

The rules of the privilege model stand in the metamodel as OCL
invariants of their classes, each named by its code with its sentence
and level beside it: P1 the grantee is a party, P2 the table and its
columns, P3 the role of a membership is not its member, P4 the
procedure, P5 no cycle of memberships, P6 the grantee is a user or a
role, not both, and the warning P7 a membership names a role, not a
user. The classic Eclipse OCL evaluates them; PrivilegeModelValidator
gives their findings and installs, for the check alone, the inverse
index through which the invariants read a party's stereotype. The
documentation of the model is English only, under the keys
documentation and caption.

The rule party:<glob> takes the parties of that name with the
privileges they own, whether the database tells them as role, as user
or not at all, as MySQL does not. It takes nothing else of that name:
in Oracle a user is a schema too, which name:<glob> would take as well.

The DDL writes a membership that names a user only where the dialect
grants a user like a role (supportsUserAsRole: PostgreSQL, MySQL);
elsewhere it is a case the dialect cannot write, left out and logged,
or, strict, the generation fails naming it. A user's own grant comes
after the user is created, its revoke before it is dropped. The
privilege loader gives a party whose kind the database does not tell
the responsibility "database principal" instead of "database role",
and reads a user with the privileges it holds itself beside its
memberships.

JdbcToCwmConfig names the scope a database is read in: DATABASE, the
default, every schema, object, role, membership and grant, or USER,
what the connected user may see. CwmJdbcImport.load takes the metadata
provider of that scope. A connection that may not read the whole
database is read as its user sees it, the whole snapshot, never a mix;
withStrictScope(true) fails instead, before anything is read, with the
MetadataScopeException that names the right the connection lacks. The
catalog says what it holds: the tagged value daanse.jdbc.scope is the
scope it was read in, daanse.jdbc.scope.requested the scope it was
asked for where the two differ. Both are provenance, written by no DDL
and compared by no diff. A database whose metadata provider reads its
catalog one way only, as that of H2 does, is read so in either scope,
and the catalog names the scope it was read in.

The example jdbc.load reads a database with one call of
CwmJdbcImport.load: its schemas with all they hold, its roles and users
with their privileges, chosen by rules as cwm-jdbc:import takes them, in
either scope; Inventory lists what a catalog holds, kind by kind, and
the scope it was read in. The same shop, two schemas, three roles and
two users, is created in Oracle and PostgreSQL and read by the same
code: as a whole, on Oracle by a catalog reader holding just
SELECT_CATALOG_ROLE, on PostgreSQL by the user of the container, and by
the clerk of the shop, who sees its part. The tests compare both
catalogs with what is expected and with each other, show the clerk
asking for the whole database falling back to its part or, strictly,
failing with the right it lacks before anything is read, and read both
back from XMI. Where a database shows the clerk more or less than the
shop leads one to expect, the test of that database says so and why:
Oracle names every user to every user, without the memberships of
others; PostgreSQL shows every user the whole database. The README
names the right each database wants for the whole.

The goal cwm-jdbc:import takes the parameter scope (cwm-jdbc.scope),
database, the default, or user; another value fails the goal before it
connects. strictScope (cwm-jdbc.strictScope) fails the goal, before
anything is read, where the connection may not read in that scope,
naming the right it lacks. The log names the scope the catalog was
read in, and the one asked for where they differ.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
@stbischof
stbischof force-pushed the feat/user-privileges branch from 50c97fc to 72e243e Compare December 2, 2026 16:15
@stbischof
stbischof merged commit 835a9cd into eclipse-daanse:main Dec 2, 2026
58 of 59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant