Package org.apache.hadoop.hive.metastore.api

Examples of org.apache.hadoop.hive.metastore.api.PrivilegeBag$PrivilegeBagStandardScheme


    // authorize the grant
    GrantPrivAuthUtils.authorize(hivePrincipals, hivePrivileges, hivePrivObject, grantOption,
        metastoreClient, authenticator.getUserName(), getCurrentRoleNames(), isUserAdmin());

    // grant
    PrivilegeBag privBag = SQLAuthorizationUtils.getThriftPrivilegesBag(hivePrincipals, hivePrivileges, hivePrivObject,
        grantorPrincipal, grantOption);
    try {
      metastoreClient.grant_privileges(privBag);
    } catch (Exception e) {
      throw new HiveAuthzPluginException("Error granting privileges: " + e.getMessage(), e);
View Full Code Here


      // principal, privilege object type it does not filter on the grator
      // username.
      // So this will revoke privileges that are granted by other users.This is
      // not SQL compliant behavior. Need to change/add a metastore api
      // that has desired behavior.
      metastoreClient.revoke_privileges(new PrivilegeBag(revokePrivs));
    } catch (Exception e) {
      throw new HiveAuthzPluginException("Error revoking privileges", e);
    }
  }
View Full Code Here

   */
  static PrivilegeBag getThriftPrivilegesBag(List<HivePrincipal> hivePrincipals,
      List<HivePrivilege> hivePrivileges, HivePrivilegeObject hivePrivObject,
      HivePrincipal grantorPrincipal, boolean grantOption) throws HiveAuthzPluginException {
    HiveObjectRef privObj = getThriftHiveObjectRef(hivePrivObject);
    PrivilegeBag privBag = new PrivilegeBag();
    for (HivePrivilege privilege : hivePrivileges) {
      if (privilege.getColumns() != null && privilege.getColumns().size() > 0) {
        throw new HiveAuthzPluginException("Privileges on columns not supported currently"
            + " in sql standard authorization mode");
      }
      if (!SUPPORTED_PRIVS_SET.contains(privilege.getName().toUpperCase(Locale.US))) {
        throw new HiveAuthzPluginException("Privilege: " + privilege.getName()
            + " is not supported in sql standard authorization mode");
      }
      PrivilegeGrantInfo grantInfo = getThriftPrivilegeGrantInfo(privilege, grantorPrincipal,
          grantOption, 0 /*real grant time added by metastore*/);
      for (HivePrincipal principal : hivePrincipals) {
        HiveObjectPrivilege objPriv = new HiveObjectPrivilege(privObj, principal.getName(),
            AuthorizationUtils.getThriftPrincipalType(principal.getType()), grantInfo);
        privBag.addToPrivileges(objPriv);
      }
    }
    return privBag;
  }
View Full Code Here

        // This should never be thrown.
        LOG.warn("Unexpected exception while adding "+PUBLIC +" roles" , e);
      }
      LOG.info("Added "+PUBLIC+ " role in metastore");
      // now grant all privs to admin
      PrivilegeBag privs = new PrivilegeBag();
      privs.addToPrivileges(new HiveObjectPrivilege( new HiveObjectRef(HiveObjectType.GLOBAL, null,
        null, null, null), ADMIN, PrincipalType.ROLE, new PrivilegeGrantInfo("All", 0, ADMIN,
        PrincipalType.ROLE, true)));
      try {
        ms.grantPrivileges(privs);
      } catch (InvalidObjectException e) {
View Full Code Here

  @Test
  public void testGrantPriv() throws Exception {
    FunctionInvoker invoker = new FunctionInvoker() {
      @Override
      public void invoke() throws Exception {
        msc.grant_privileges(new PrivilegeBag(new ArrayList<HiveObjectPrivilege>()));
      }
    };
    testFunction(invoker);
  }
View Full Code Here

  @Test
  public void testRevokePriv() throws Exception {
    FunctionInvoker invoker = new FunctionInvoker() {
      @Override
      public void invoke() throws Exception {
        msc.revoke_privileges(new PrivilegeBag(new ArrayList<HiveObjectPrivilege>()), false);
      }
    };
    testFunction(invoker);
  }
View Full Code Here

   */
  static PrivilegeBag getThriftPrivilegesBag(List<HivePrincipal> hivePrincipals,
      List<HivePrivilege> hivePrivileges, HivePrivilegeObject hivePrivObject,
      HivePrincipal grantorPrincipal, boolean grantOption) throws HiveAuthzPluginException {
    HiveObjectRef privObj = getThriftHiveObjectRef(hivePrivObject);
    PrivilegeBag privBag = new PrivilegeBag();
    for (HivePrivilege privilege : hivePrivileges) {
      if (privilege.getColumns() != null && privilege.getColumns().size() > 0) {
        throw new HiveAuthzPluginException("Privileges on columns not supported currently"
            + " in sql standard authorization mode");
      }
      if (!SUPPORTED_PRIVS_SET.contains(privilege.getName().toUpperCase(Locale.US))) {
        throw new HiveAuthzPluginException("Privilege: " + privilege.getName()
            + " is not supported in sql standard authorization mode");
      }
      PrivilegeGrantInfo grantInfo = getThriftPrivilegeGrantInfo(privilege, grantorPrincipal,
          grantOption, 0 /*real grant time added by metastore*/);
      for (HivePrincipal principal : hivePrincipals) {
        HiveObjectPrivilege objPriv = new HiveObjectPrivilege(privObj, principal.getName(),
            AuthorizationUtils.getThriftPrincipalType(principal.getType()), grantInfo);
        privBag.addToPrivileges(objPriv);
      }
    }
    return privBag;
  }
View Full Code Here

  public void grantPrivileges(
      List<HivePrincipal> principals, List<HivePrivilege> privileges, HivePrivilegeObject privObject,
      HivePrincipal grantor, boolean grantOption)
      throws HiveAuthzPluginException, HiveAccessControlException {
    try {
      PrivilegeBag privBag = toPrivilegeBag(privileges, privObject, grantor, grantOption);
      grantOrRevokePrivs(principals, privBag, true, grantOption);
    } catch (Exception e) {
      throw new HiveAuthzPluginException(e);
    }
  }
View Full Code Here

  public void revokePrivileges(
      List<HivePrincipal> principals, List<HivePrivilege> privileges, HivePrivilegeObject privObject,
      HivePrincipal grantor, boolean grantOption)
      throws HiveAuthzPluginException, HiveAccessControlException {
    try {
      PrivilegeBag privBag = toPrivilegeBag(privileges, privObject, grantor, grantOption);
      grantOrRevokePrivs(principals, privBag, false, grantOption);
    } catch (Exception e) {
      throw new HiveAuthzPluginException(e);
    }
  }
View Full Code Here

  private PrivilegeBag toPrivilegeBag(List<HivePrivilege> privileges,
      HivePrivilegeObject privObject, HivePrincipal grantor, boolean grantOption)
      throws HiveException {

    PrivilegeBag privBag = new PrivilegeBag();
    if (privileges.isEmpty()) {
      return privBag;
    }
    String grantorName = grantor.getName();
    PrincipalType grantorType = AuthorizationUtils.getThriftPrincipalType(grantor.getType());
    if (privObject.getType() == null ||
        privObject.getType() == HivePrivilegeObject.HivePrivilegeObjectType.GLOBAL) {
      for (HivePrivilege priv : privileges) {
        List<String> columns = priv.getColumns();
        if (columns != null && !columns.isEmpty()) {
          throw new HiveException(
              "For user-level privileges, column sets should be null. columns=" +
                  columns.toString());
        }
        privBag.addToPrivileges(new HiveObjectPrivilege(new HiveObjectRef(
            HiveObjectType.GLOBAL, null, null, null, null), null, null,
            new PrivilegeGrantInfo(priv.getName(), 0, grantor.getName(), grantorType,
                grantOption)));
      }
      return privBag;
    }

    if (privObject.getPartKeys() != null && grantOption) {
      throw new HiveException("Grant does not support partition level.");
    }
    Database dbObj = hive.getDatabase(privObject.getDbname());
    if (dbObj == null) {
      throw new HiveException("Database " + privObject.getDbname() + " does not exists");
    }
    Table tableObj = null;
    if (privObject.getObjectName() != null) {
      tableObj = hive.getTable(dbObj.getName(), privObject.getObjectName());
    }

    List<String> partValues = null;
    if (tableObj != null) {
      if ((!tableObj.isPartitioned())
          && privObject.getPartKeys() != null) {
        throw new HiveException(
            "Table is not partitioned, but partition name is present: partSpec="
                + privObject.getPartKeys());
      }

      if (privObject.getPartKeys() != null) {
        Map<String, String> partSpec =
            Warehouse.makeSpecFromValues(tableObj.getPartitionKeys(), privObject.getPartKeys());
        Partition partObj = hive.getPartition(tableObj, partSpec, false).getTPartition();
        partValues = partObj.getValues();
      }
    }

    for (HivePrivilege priv : privileges) {
      List<String> columns = priv.getColumns();
      if (columns != null && !columns.isEmpty()) {
        if (!priv.supportsScope(PrivilegeScope.COLUMN_LEVEL_SCOPE)) {
          throw new HiveException(priv.getName() + " does not support column level privilege.");
        }
        if (tableObj == null) {
          throw new HiveException(
              "For user-level/database-level privileges, column sets should be null. columns="
                  + columns);
        }
        for (int i = 0; i < columns.size(); i++) {
          privBag.addToPrivileges(new HiveObjectPrivilege(
              new HiveObjectRef(HiveObjectType.COLUMN, dbObj.getName(), tableObj.getTableName(),
                  partValues, columns.get(i)), null, null,
              new PrivilegeGrantInfo(priv.getName(), 0, grantorName, grantorType, grantOption)));
        }
      } else if (tableObj == null) {
        privBag.addToPrivileges(new HiveObjectPrivilege(
            new HiveObjectRef(HiveObjectType.DATABASE, dbObj.getName(), null,
                null, null), null, null,
            new PrivilegeGrantInfo(priv.getName(), 0, grantorName, grantorType, grantOption)));
      } else if (partValues == null) {
        privBag.addToPrivileges(new HiveObjectPrivilege(
            new HiveObjectRef(HiveObjectType.TABLE, dbObj.getName(), tableObj.getTableName(),
                null, null), null, null,
            new PrivilegeGrantInfo(priv.getName(), 0, grantorName, grantorType, grantOption)));
      } else {
        privBag.addToPrivileges(new HiveObjectPrivilege(
            new HiveObjectRef(HiveObjectType.PARTITION, dbObj.getName(), tableObj.getTableName(),
                partValues, null), null, null,
            new PrivilegeGrantInfo(priv.getName(), 0, grantorName, grantorType, grantOption)));
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.metastore.api.PrivilegeBag$PrivilegeBagStandardScheme

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.