Search in sources :

Example 21 with PrestoPrincipal

use of com.facebook.presto.spi.security.PrestoPrincipal in project presto by prestodb.

the class HiveMetadata method grantRoles.

@Override
public void grantRoles(ConnectorSession session, Set<String> roles, Set<PrestoPrincipal> grantees, boolean withAdminOption, Optional<PrestoPrincipal> grantor) {
    MetastoreContext metastoreContext = getMetastoreContext(session);
    metastore.grantRoles(metastoreContext, roles, grantees, withAdminOption, grantor.orElse(new PrestoPrincipal(USER, session.getUser())));
}
Also used : MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) PrestoPrincipal(com.facebook.presto.spi.security.PrestoPrincipal)

Example 22 with PrestoPrincipal

use of com.facebook.presto.spi.security.PrestoPrincipal in project presto by prestodb.

the class TestFileBasedSystemAccessControl method testViewOperations.

@Test
public void testViewOperations() {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControlManager = newAccessControlManager(transactionManager, "catalog.json");
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanCreateView(transactionId, alice, context, aliceView);
        accessControlManager.checkCanDropView(transactionId, alice, context, aliceView);
        accessControlManager.checkCanSelectFromColumns(transactionId, alice, context, aliceView, ImmutableSet.of());
        accessControlManager.checkCanCreateViewWithSelectFromColumns(transactionId, alice, context, aliceTable, ImmutableSet.of());
        accessControlManager.checkCanCreateViewWithSelectFromColumns(transactionId, alice, context, aliceView, ImmutableSet.of());
        accessControlManager.checkCanSetCatalogSessionProperty(transactionId, alice, context, "alice-catalog", "property");
        accessControlManager.checkCanGrantTablePrivilege(transactionId, alice, context, SELECT, aliceTable, new PrestoPrincipal(USER, "grantee"), true);
        accessControlManager.checkCanRevokeTablePrivilege(transactionId, alice, context, SELECT, aliceTable, new PrestoPrincipal(USER, "revokee"), true);
    });
    assertThrows(AccessDeniedException.class, () -> transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanCreateView(transactionId, bob, context, aliceView);
    }));
}
Also used : SystemAccessControl(com.facebook.presto.spi.security.SystemAccessControl) InterfaceTestUtils.assertAllMethodsOverridden(com.facebook.presto.spi.testing.InterfaceTestUtils.assertAllMethodsOverridden) PrestoPrincipal(com.facebook.presto.spi.security.PrestoPrincipal) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) SECURITY_CONFIG_FILE(com.facebook.presto.plugin.base.security.FileBasedAccessControlConfig.SECURITY_CONFIG_FILE) AccessDeniedException(com.facebook.presto.spi.security.AccessDeniedException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assert.assertThrows(org.testng.Assert.assertThrows) Identity(com.facebook.presto.spi.security.Identity) TransactionBuilder.transaction(com.facebook.presto.transaction.TransactionBuilder.transaction) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) Thread.sleep(java.lang.Thread.sleep) TransactionManager(com.facebook.presto.transaction.TransactionManager) Files.newTemporaryFile(org.assertj.core.util.Files.newTemporaryFile) SECURITY_REFRESH_PERIOD(com.facebook.presto.plugin.base.security.FileBasedAccessControlConfig.SECURITY_REFRESH_PERIOD) USER(com.facebook.presto.spi.security.PrincipalType.USER) SELECT(com.facebook.presto.spi.security.Privilege.SELECT) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) AccessControlContext(com.facebook.presto.spi.security.AccessControlContext) Set(java.util.Set) File(java.io.File) QueryId(com.facebook.presto.spi.QueryId) Files.copy(com.google.common.io.Files.copy) Optional(java.util.Optional) CatalogSchemaName(com.facebook.presto.common.CatalogSchemaName) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) PrestoPrincipal(com.facebook.presto.spi.security.PrestoPrincipal) Test(org.testng.annotations.Test)

Example 23 with PrestoPrincipal

use of com.facebook.presto.spi.security.PrestoPrincipal in project presto by prestodb.

the class InformationSchemaPageSourceProvider method buildApplicableRoles.

private InternalTable buildApplicableRoles(Session session, String catalog) {
    InternalTable.Builder table = InternalTable.builder(informationSchemaTableColumns(TABLE_APPLICABLE_ROLES));
    for (RoleGrant grant : metadata.listApplicableRoles(session, new PrestoPrincipal(USER, session.getUser()), catalog)) {
        PrestoPrincipal grantee = grant.getGrantee();
        table.add(grantee.getName(), grantee.getType().toString(), grant.getRoleName(), grant.isGrantable() ? "YES" : "NO");
    }
    return table.build();
}
Also used : RoleGrant(com.facebook.presto.spi.security.RoleGrant) InternalTable(com.facebook.presto.metadata.InternalTable) PrestoPrincipal(com.facebook.presto.spi.security.PrestoPrincipal)

Aggregations

PrestoPrincipal (com.facebook.presto.spi.security.PrestoPrincipal)23 RoleGrant (com.facebook.presto.spi.security.RoleGrant)11 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)10 PrestoException (com.facebook.presto.spi.PrestoException)9 ImmutableSet (com.google.common.collect.ImmutableSet)9 USER (com.facebook.presto.spi.security.PrincipalType.USER)8 Optional (java.util.Optional)8 HivePrivilegeInfo (com.facebook.presto.hive.metastore.HivePrivilegeInfo)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 Collection (java.util.Collection)7 Set (java.util.Set)7 Column (com.facebook.presto.hive.metastore.Column)6 SchemaTableName (com.facebook.presto.spi.SchemaTableName)6 Database (com.facebook.presto.hive.metastore.Database)5 HiveColumnStatistics (com.facebook.presto.hive.metastore.HiveColumnStatistics)5 SemiTransactionalHiveMetastore (com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 HashSet (java.util.HashSet)5 Table (com.facebook.presto.hive.metastore.Table)4 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)4