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);
}
}
Aggregations