Search in sources :

Example 16 with RoleGrant

use of com.facebook.presto.spi.security.RoleGrant in project urban-eureka by errir503.

the class FileHiveMetastore method grantRoles.

@Override
public synchronized void grantRoles(MetastoreContext metastoreContext, Set<String> roles, Set<PrestoPrincipal> grantees, boolean withAdminOption, PrestoPrincipal grantor) {
    Set<String> existingRoles = listRoles(metastoreContext);
    Set<RoleGrant> existingGrants = listRoleGrantsSanitized(metastoreContext);
    Set<RoleGrant> modifiedGrants = new HashSet<>(existingGrants);
    for (PrestoPrincipal grantee : grantees) {
        for (String role : roles) {
            checkArgument(existingRoles.contains(role), "Role does not exist: %s", role);
            if (grantee.getType() == ROLE) {
                checkArgument(existingRoles.contains(grantee.getName()), "Role does not exist: %s", grantee.getName());
            }
            RoleGrant grantWithAdminOption = new RoleGrant(grantee, role, true);
            RoleGrant grantWithoutAdminOption = new RoleGrant(grantee, role, false);
            if (withAdminOption) {
                modifiedGrants.remove(grantWithoutAdminOption);
                modifiedGrants.add(grantWithAdminOption);
            } else {
                modifiedGrants.remove(grantWithAdminOption);
                modifiedGrants.add(grantWithoutAdminOption);
            }
        }
    }
    modifiedGrants = removeDuplicatedEntries(modifiedGrants);
    if (!existingGrants.equals(modifiedGrants)) {
        writeRoleGrantsFile(modifiedGrants);
    }
}
Also used : RoleGrant(com.facebook.presto.spi.security.RoleGrant) PrestoPrincipal(com.facebook.presto.spi.security.PrestoPrincipal) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

RoleGrant (com.facebook.presto.spi.security.RoleGrant)16 PrestoPrincipal (com.facebook.presto.spi.security.PrestoPrincipal)12 ImmutableSet (com.google.common.collect.ImmutableSet)4 HashSet (java.util.HashSet)4 LinkedHashSet (java.util.LinkedHashSet)4 SemiTransactionalHiveMetastore (com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore)2 InternalTable (com.facebook.presto.metadata.InternalTable)2 SelectedRole (com.facebook.presto.spi.security.SelectedRole)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2