Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,15 @@ private void addTablePrivilegesRecords(QualifiedTablePrefix prefix)

private void addRolesRecords()
{
Optional<String> catalogName = metadata.isCatalogManagedSecurity(session, this.catalogName) ? Optional.of(this.catalogName) : Optional.empty();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be cleaner to use Optional.filter

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that and it was less awesome

try {
accessControl.checkCanShowRoles(session.toSecurityContext(), Optional.of(catalogName));
accessControl.checkCanShowRoles(session.toSecurityContext(), catalogName);
}
catch (AccessDeniedException exception) {
return;
}

for (String role : metadata.listRoles(session, Optional.of(catalogName))) {
for (String role : metadata.listRoles(session, catalogName)) {
addRecord(role);
if (isLimitExhausted()) {
return;
Expand All @@ -361,14 +362,15 @@ private void addRolesRecords()

private void addRoleAuthorizationDescriptorRecords()
{
Optional<String> catalogName = metadata.isCatalogManagedSecurity(session, this.catalogName) ? Optional.of(this.catalogName) : Optional.empty();
try {
accessControl.checkCanShowRoleAuthorizationDescriptors(session.toSecurityContext(), Optional.of(catalogName));
accessControl.checkCanShowRoleAuthorizationDescriptors(session.toSecurityContext(), catalogName);
}
catch (AccessDeniedException exception) {
return;
}

for (RoleGrant grant : metadata.listAllRoleGrants(session, Optional.of(catalogName), roles, grantees, limit)) {
for (RoleGrant grant : metadata.listAllRoleGrants(session, catalogName, roles, grantees, limit)) {
addRecord(
grant.getRoleName(),
null, // grantor
Expand All @@ -384,7 +386,8 @@ private void addRoleAuthorizationDescriptorRecords()

private void addApplicableRolesRecords()
{
for (RoleGrant grant : metadata.listApplicableRoles(session, new TrinoPrincipal(USER, session.getUser()), Optional.of(catalogName))) {
Optional<String> catalogName = metadata.isCatalogManagedSecurity(session, this.catalogName) ? Optional.of(this.catalogName) : Optional.empty();
for (RoleGrant grant : metadata.listApplicableRoles(session, new TrinoPrincipal(USER, session.getUser()), catalogName)) {
addRecord(
grant.getGrantee().getName(),
grant.getGrantee().getType().toString(),
Expand Down