From: Jonas Sundman <jonas.sundman@thl.fi>
To: pgsql-jdbc@postgresql.org
Subject: getTablePrivileges empty if table owned by group role
Date: Thu, 18 Aug 2011 12:15:26 +0300
Message-ID: <4E4CD82E.3040102@thl.fi> (raw)
Hi,
I came across a situation which revealed that getTablePrivileges is not
returning any grants if a table is owned by a group role, i.e. a role wihout
login attribute. The connection is opened with superuser priviliges.
This code runs with the latest 8.4 driver (702) agains a 8.4.8 database.
public static void listprivs() throws SQLException{
ResultSet rs = con.getMetaData().getTablePrivileges(null, "public", "test");
int i = 0;
while (rs.next())
{
System.out.print("grantee: " + rs.getString("GRANTEE"));
System.out.println(", privilege: " + rs.getString("PRIVILEGE"));
i++;
}
System.out.println("Total: " + i);
}
public static void main(String[] args) throws ClassNotFoundException,
SQLException {
Class.forName("org.postgresql.Driver");
con = DriverManager.getConnection("jdbc:postgresql://localhost/test",
"user", "****");
con.setAutoCommit(true);
Statement stmt = con.createStatement();
stmt.executeUpdate("create table test (a int)");
stmt.executeUpdate("create role test_group");
stmt.executeUpdate("alter table test owner to test_group");
System.out.println("Initial case");
listprivs();
stmt.executeUpdate("alter role test_group login");
System.out.println("login attribute set");
listprivs();
stmt.executeUpdate("drop table test");
stmt.executeUpdate("drop role test_group");
}
}
Output:
Initial case
Total: 0
Group with login
grantee: test_group, privilege: DELETE
grantee: test_group, privilege: INSERT
grantee: test_group, privilege: REFERENCES
grantee: test_group, privilege: RULE
grantee: test_group, privilege: SELECT
grantee: test_group, privilege: TRIGGER
grantee: test_group, privilege: UPDATE
Total: 7
To my understanding, the result should be the same in both cases. The result is
the same even if there are explicit grants on the table to some other role.
Regards,
Jonas Sundman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: jonas.sundman@thl.fi
Subject: Re: getTablePrivileges empty if table owned by group role
In-Reply-To: <4E4CD82E.3040102@thl.fi>
References: <4E4CD82E.3040102@thl.fi>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox