Skip to content

Commit

Permalink
Add listRoleGrants to the SPI
Browse files Browse the repository at this point in the history
Extracted-From: prestodb/presto#10904
  • Loading branch information
cawallin authored and sopel39 committed Jan 29, 2019
1 parent 0c3406c commit 4b90148
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions presto-main/src/main/java/io/prestosql/metadata/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ public interface Metadata
*/
Set<String> listRoles(Session session, String catalog);

/**
* List roles grants in the specified catalog for a given principal, not recursively.
*/
Set<RoleGrant> listRoleGrants(Session session, String catalog, PrestoPrincipal principal);

/**
* Grants the specified roles to the specified grantees in the specified catalog
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,19 @@ public Set<String> listRoles(Session session, String catalog)
.collect(toImmutableSet());
}

@Override
public Set<RoleGrant> listRoleGrants(Session session, String catalog, PrestoPrincipal principal)
{
Optional<CatalogMetadata> catalogMetadata = getOptionalCatalogMetadata(session, catalog);
if (!catalogMetadata.isPresent()) {
return ImmutableSet.of();
}
ConnectorId connectorId = catalogMetadata.get().getConnectorId();
ConnectorSession connectorSession = session.toConnectorSession(connectorId);
ConnectorMetadata metadata = catalogMetadata.get().getMetadataFor(connectorId);
return metadata.listRoleGrants(connectorSession, principal);
}

@Override
public void grantRoles(Session session, Set<String> roles, Set<PrestoPrincipal> grantees, boolean withAdminOption, Optional<PrestoPrincipal> grantor, String catalog)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ public Set<String> listEnabledRoles(Session session, String catalog)
throw new UnsupportedOperationException();
}

@Override
public Set<RoleGrant> listRoleGrants(Session session, String catalog, PrestoPrincipal principal)
{
throw new UnsupportedOperationException();
}

@Override
public void grantTablePrivileges(Session session, QualifiedObjectName tableName, Set<Privilege> privileges, PrestoPrincipal grantee, boolean grantOption)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,14 @@ default Set<String> listRoles(ConnectorSession session)
throw new PrestoException(NOT_SUPPORTED, "This connector does not support roles");
}

/**
* List role grants for a given principal, not recursively.
*/
default Set<RoleGrant> listRoleGrants(ConnectorSession session, PrestoPrincipal principal)
{
throw new PrestoException(NOT_SUPPORTED, "This connector does not support roles");
}

/**
* Grants the specified roles to the specified grantees
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ public Set<String> listRoles(ConnectorSession session)
}
}

@Override
public Set<RoleGrant> listRoleGrants(ConnectorSession session, PrestoPrincipal principal)
{
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
return delegate.listRoleGrants(session, principal);
}
}

@Override
public void grantRoles(ConnectorSession connectorSession, Set<String> roles, Set<PrestoPrincipal> grantees, boolean withAdminOption, Optional<PrestoPrincipal> grantor)
{
Expand Down

0 comments on commit 4b90148

Please sign in to comment.