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

Examples of org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege


            throw new HiveException(
                "For user-level privileges, column sets should be null. columns="
                    + privileges.get(idx).getColumns().toString());
          }

          privBag.addToPrivileges(new HiveObjectPrivilege(new HiveObjectRef(
              HiveObjectType.GLOBAL, null, null, null, null), null, null,
              new PrivilegeGrantInfo(priv.getPriv(), 0, grantor, grantorType,
                  grantOption)));
        }
      } else {
        org.apache.hadoop.hive.metastore.api.Partition partObj = null;
        List<String> partValues = null;
        if (tableObj != null) {
          if ((!tableObj.isPartitioned())
              && privSubjectDesc.getPartSpec() != null) {
            throw new HiveException(
                "Table is not partitioned, but partition name is present: partSpec="
                    + privSubjectDesc.getPartSpec().toString());
          }

          if (privSubjectDesc.getPartSpec() != null) {
            partObj = db.getPartition(tableObj, privSubjectDesc.getPartSpec(),
                false).getTPartition();
            partValues = partObj.getValues();
          }
        }

        for (PrivilegeDesc privDesc : privileges) {
          List<String> columns = privDesc.getColumns();
          Privilege priv = privDesc.getPrivilege();
          if (columns != null && columns.size() > 0) {
            if (!priv.supportColumnLevel()) {
              throw new HiveException(priv.getPriv()
                  + " does not support column level.");
            }
            if (privSubjectDesc == null || tableName == 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, dbName, tableName,
                      partValues, columns.get(i)), null, null,  new PrivilegeGrantInfo(priv.getPriv(), 0, grantor, grantorType, grantOption)));
            }
          } else {
            if (privSubjectDesc.getTable()) {
              if (privSubjectDesc.getPartSpec() != null) {
                privBag.addToPrivileges(new HiveObjectPrivilege(
                    new HiveObjectRef(HiveObjectType.PARTITION, dbName,
                        tableName, partValues, null), null, null,  new PrivilegeGrantInfo(priv.getPriv(), 0, grantor, grantorType, grantOption)));
              } else {
                privBag
                    .addToPrivileges(new HiveObjectPrivilege(
                        new HiveObjectRef(HiveObjectType.TABLE, dbName,
                            tableName, null, null), null, null, new PrivilegeGrantInfo(priv.getPriv(), 0, grantor, grantorType, grantOption)));
              }
            } else {
              privBag.addToPrivileges(new HiveObjectPrivilege(
                  new HiveObjectRef(HiveObjectType.DATABASE, dbName, null,
                      null, null), null, null, new PrivilegeGrantInfo(priv.getPriv(), 0, grantor, grantorType, grantOption)));
            }
          }
        }
      }
     
      for (PrincipalDesc principal : principals) {
        for (int i = 0; i < privBag.getPrivileges().size(); i++) {
          HiveObjectPrivilege objPrivs = privBag.getPrivileges().get(i);
          objPrivs.setPrincipalName(principal.getName());
          objPrivs.setPrincipalType(principal.getType());
        }
        if (isGrant) {
          db.grantPrivileges(privBag);
        } else {
          db.revokePrivileges(privBag);
View Full Code Here


      if (privilegeList != null && privilegeList.size() > 0) {
        Iterator<HiveObjectPrivilege> privIter = privilegeList.iterator();
        Set<String> privSet = new HashSet<String>();
        while (privIter.hasNext()) {
          HiveObjectPrivilege privDef = privIter.next();
          HiveObjectRef hiveObject = privDef.getHiveObject();
          String privilegeStr = privDef.getGrantInfo().getPrivilege();
          String[] privs = privilegeStr.split(",");
          String userName = privDef.getPrincipalName();
          PrincipalType principalType = privDef.getPrincipalType();
          String grantor = privDef.getGrantInfo().getGrantor();
          String grantorType = privDef.getGrantInfo().getGrantorType().toString();
          boolean grantOption = privDef.getGrantInfo().isGrantOption();
          privSet.clear();

          if (hiveObject.getObjectType() == HiveObjectType.GLOBAL) {
            List<MGlobalPrivilege> globalPrivs = this
                .listPrincipalGlobalGrants(userName, principalType);
View Full Code Here

     
      if (privilegeList != null && privilegeList.size() > 0) {
        Iterator<HiveObjectPrivilege> privIter = privilegeList.iterator();
       
        while (privIter.hasNext()) {
          HiveObjectPrivilege privDef = privIter.next();
          HiveObjectRef hiveObject = privDef.getHiveObject();
          String privilegeStr = privDef.getGrantInfo().getPrivilege();
          if (privilegeStr == null || privilegeStr.trim().equals("")) {
            continue;
          }
          String[] privs = privilegeStr.split(",");
          String userName = privDef.getPrincipalName();
          PrincipalType principalType = privDef.getPrincipalType();

          if (hiveObject.getObjectType() == HiveObjectType.GLOBAL) {
            List<MGlobalPrivilege> mSecUser = this.listPrincipalGlobalGrants(
                userName, principalType);
            boolean found = false;
View Full Code Here

                  MPartitionColumnPrivilege sCol = mPartitionCols.get(i);
                  HiveObjectRef objectRef = new HiveObjectRef(
                      HiveObjectType.COLUMN, dbName, tableName,
                      part == null ? null : part.getValues(), sCol
                          .getColumnName());
                  HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef,
                      sCol.getPrincipalName(), principalType,
                      new PrivilegeGrantInfo(sCol.getPrivilege(), sCol
                          .getCreateTime(), sCol.getGrantor(), PrincipalType
                          .valueOf(sCol.getGrantorType()), sCol.getGrantOption()));
                  result.add(secObj);
                }
              }
            } else {
              List<MTableColumnPrivilege> mTableCols = ms
                  .listPrincipalTableColumnGrants(principalName, principalType,
                      dbName, tableName, columnName);
              if (mTableCols.size() > 0) {
                result = new ArrayList<HiveObjectPrivilege>();
                for (int i = 0; i < mTableCols.size(); i++) {
                  MTableColumnPrivilege sCol = mTableCols.get(i);
                  HiveObjectRef objectRef = new HiveObjectRef(
                      HiveObjectType.COLUMN, dbName, tableName, null, sCol
                          .getColumnName());
                  HiveObjectPrivilege secObj = new HiveObjectPrivilege(
                      objectRef, sCol.getPrincipalName(), principalType,
                      new PrivilegeGrantInfo(sCol.getPrivilege(), sCol
                          .getCreateTime(), sCol.getGrantor(), PrincipalType
                          .valueOf(sCol.getGrantorType()), sCol
                          .getGrantOption()));
View Full Code Here

              List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
              for (int i = 0; i < mDbs.size(); i++) {
                MDBPrivilege sDB = mDbs.get(i);
                HiveObjectRef objectRef = new HiveObjectRef(
                    HiveObjectType.DATABASE, dbName, null, null, null);
                HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef,
                    sDB.getPrincipalName(), principalType,
                    new PrivilegeGrantInfo(sDB.getPrivilege(), sDB
                        .getCreateTime(), sDB.getGrantor(), PrincipalType
                        .valueOf(sDB.getGrantorType()), sDB.getGrantOption()));
                result.add(secObj);
View Full Code Here

              for (int i = 0; i < mParts.size(); i++) {
                MPartitionPrivilege sPart = mParts.get(i);
                HiveObjectRef objectRef = new HiveObjectRef(
                    HiveObjectType.PARTITION, dbName, tableName, partValues,
                    null);
                HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef,
                    sPart.getPrincipalName(), principalType,
                    new PrivilegeGrantInfo(sPart.getPrivilege(), sPart
                        .getCreateTime(), sPart.getGrantor(), PrincipalType
                        .valueOf(sPart.getGrantorType()), sPart
                        .getGrantOption()));
View Full Code Here

              List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
              for (int i = 0; i < mTbls.size(); i++) {
                MTablePrivilege sTbl = mTbls.get(i);
                HiveObjectRef objectRef = new HiveObjectRef(
                    HiveObjectType.TABLE, dbName, tableName, null,null);
                HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef,
                    sTbl.getPrincipalName(), principalType,
                    new PrivilegeGrantInfo(sTbl.getPrivilege(), sTbl.getCreateTime(), sTbl
                        .getGrantor(), PrincipalType.valueOf(sTbl
                        .getGrantorType()), sTbl.getGrantOption()));
                result.add(secObj);
View Full Code Here

              List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
              for (int i = 0; i < mUsers.size(); i++) {
                MGlobalPrivilege sUsr = mUsers.get(i);
                HiveObjectRef objectRef = new HiveObjectRef(
                    HiveObjectType.GLOBAL, null, null, null, null);
                HiveObjectPrivilege secUser = new HiveObjectPrivilege(
                    objectRef, sUsr.getPrincipalName(), principalType,
                    new PrivilegeGrantInfo(sUsr.getPrivilege(), sUsr
                        .getCreateTime(), sUsr.getGrantor(), PrincipalType
                        .valueOf(sUsr.getGrantorType()), sUsr.getGrantOption()));
                result.add(secUser);
View Full Code Here

            throw new HiveException(
                "For user-level privileges, column sets should be null. columns="
                    + privileges.get(idx).getColumns().toString());
          }

          privBag.addToPrivileges(new HiveObjectPrivilege(new HiveObjectRef(
              HiveObjectType.GLOBAL, null, null, null, null), null, null,
              new PrivilegeGrantInfo(priv.toString(), 0, grantor, grantorType,
                  grantOption)));
        }
      } else {
        org.apache.hadoop.hive.metastore.api.Partition partObj = null;
        List<String> partValues = null;
        if (tableObj != null) {
          if ((!tableObj.isPartitioned())
              && privSubjectDesc.getPartSpec() != null) {
            throw new HiveException(
                "Table is not partitioned, but partition name is present: partSpec="
                    + privSubjectDesc.getPartSpec().toString());
          }

          if (privSubjectDesc.getPartSpec() != null) {
            partObj = db.getPartition(tableObj, privSubjectDesc.getPartSpec(),
                false).getTPartition();
            partValues = partObj.getValues();
          }
        }

        for (PrivilegeDesc privDesc : privileges) {
          List<String> columns = privDesc.getColumns();
          Privilege priv = privDesc.getPrivilege();
          if (columns != null && columns.size() > 0) {
            if (!priv.supportColumnLevel()) {
              throw new HiveException(priv.toString()
                  + " does not support column level.");
            }
            if (privSubjectDesc == null || tableName == 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, dbName, tableName,
                      partValues, columns.get(i)), null, null,  new PrivilegeGrantInfo(priv.toString(), 0, grantor, grantorType, grantOption)));
            }
          } else {
            if (privSubjectDesc.getTable()) {
              if (privSubjectDesc.getPartSpec() != null) {
                privBag.addToPrivileges(new HiveObjectPrivilege(
                    new HiveObjectRef(HiveObjectType.PARTITION, dbName,
                        tableName, partValues, null), null, null,  new PrivilegeGrantInfo(priv.toString(), 0, grantor, grantorType, grantOption)));
              } else {
                privBag
                    .addToPrivileges(new HiveObjectPrivilege(
                        new HiveObjectRef(HiveObjectType.TABLE, dbName,
                            tableName, null, null), null, null, new PrivilegeGrantInfo(priv.toString(), 0, grantor, grantorType, grantOption)));
              }
            } else {
              privBag.addToPrivileges(new HiveObjectPrivilege(
                  new HiveObjectRef(HiveObjectType.DATABASE, dbName, null,
                      null, null), null, null, new PrivilegeGrantInfo(priv.toString(), 0, grantor, grantorType, grantOption)));
            }
          }
        }
      }

      for (PrincipalDesc principal : principals) {
        for (int i = 0; i < privBag.getPrivileges().size(); i++) {
          HiveObjectPrivilege objPrivs = privBag.getPrivileges().get(i);
          objPrivs.setPrincipalName(principal.getName());
          objPrivs.setPrincipalType(principal.getType());
        }
        if (isGrant) {
          db.grantPrivileges(privBag);
        } else {
          db.revokePrivileges(privBag);
View Full Code Here

      if (privilegeList != null && privilegeList.size() > 0) {
        Iterator<HiveObjectPrivilege> privIter = privilegeList.iterator();
        Set<String> privSet = new HashSet<String>();
        while (privIter.hasNext()) {
          HiveObjectPrivilege privDef = privIter.next();
          HiveObjectRef hiveObject = privDef.getHiveObject();
          String privilegeStr = privDef.getGrantInfo().getPrivilege();
          String[] privs = privilegeStr.split(",");
          String userName = privDef.getPrincipalName();
          PrincipalType principalType = privDef.getPrincipalType();
          String grantor = privDef.getGrantInfo().getGrantor();
          String grantorType = privDef.getGrantInfo().getGrantorType().toString();
          boolean grantOption = privDef.getGrantInfo().isGrantOption();
          privSet.clear();

          if (hiveObject.getObjectType() == HiveObjectType.GLOBAL) {
            List<MGlobalPrivilege> globalPrivs = this
                .listPrincipalGlobalGrants(userName, principalType);
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege

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.