Java Code Examples for org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject#getDbname()
The following examples show how to use
org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject#getDbname() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RangerHiveAuthorizer.java From ranger with Apache License 2.0 | 5 votes |
static RangerHiveResource createHiveResource(HivePrivilegeObject privilegeObject) { RangerHiveResource resource = null; HivePrivilegeObjectType objectType = privilegeObject.getType(); String objectName = privilegeObject.getObjectName(); String dbName = privilegeObject.getDbname(); switch(objectType) { case DATABASE: resource = new RangerHiveResource(HiveObjectType.DATABASE, dbName); break; case TABLE_OR_VIEW: resource = new RangerHiveResource(HiveObjectType.TABLE, dbName, objectName); //resource.setOwnerUser(privilegeObject.getOwnerName()); break; case COLUMN: List<String> columns = privilegeObject.getColumns(); int numOfColumns = columns == null ? 0 : columns.size(); if (numOfColumns == 1) { resource = new RangerHiveResource(HiveObjectType.COLUMN, dbName, objectName, columns.get(0)); //resource.setOwnerUser(privilegeObject.getOwnerName()); } else { LOG.warn("RangerHiveAuthorizer.getHiveResource: unexpected number of columns requested:" + numOfColumns + ", objectType:" + objectType); } break; default: LOG.warn("RangerHiveAuthorizer.getHiveResource: unexpected objectType:" + objectType); } if (resource != null) { resource.setServiceDef(hivePlugin == null ? null : hivePlugin.getServiceDef()); } return resource; }
Example 2
Source File: RangerHiveAuthorizer.java From ranger with Apache License 2.0 | 4 votes |
@Override public List<HivePrivilegeObject> applyRowFilterAndColumnMasking(HiveAuthzContext queryContext, List<HivePrivilegeObject> hiveObjs) throws SemanticException { List<HivePrivilegeObject> ret = new ArrayList<HivePrivilegeObject>(); if(LOG.isDebugEnabled()) { LOG.debug("==> applyRowFilterAndColumnMasking(" + queryContext + ", objCount=" + hiveObjs.size() + ")"); } RangerPerfTracer perf = null; if(RangerPerfTracer.isPerfTraceEnabled(PERF_HIVEAUTH_REQUEST_LOG)) { perf = RangerPerfTracer.getPerfTracer(PERF_HIVEAUTH_REQUEST_LOG, "RangerHiveAuthorizer.applyRowFilterAndColumnMasking()"); } if(CollectionUtils.isNotEmpty(hiveObjs)) { for (HivePrivilegeObject hiveObj : hiveObjs) { HivePrivilegeObjectType hiveObjType = hiveObj.getType(); if(hiveObjType == null) { hiveObjType = HivePrivilegeObjectType.TABLE_OR_VIEW; } if(LOG.isDebugEnabled()) { LOG.debug("applyRowFilterAndColumnMasking(hiveObjType=" + hiveObjType + ")"); } boolean needToTransform = false; if (hiveObjType == HivePrivilegeObjectType.TABLE_OR_VIEW) { String database = hiveObj.getDbname(); String table = hiveObj.getObjectName(); String rowFilterExpr = getRowFilterExpression(queryContext, database, table); if (StringUtils.isNotBlank(rowFilterExpr)) { if(LOG.isDebugEnabled()) { LOG.debug("rowFilter(database=" + database + ", table=" + table + "): " + rowFilterExpr); } hiveObj.setRowFilterExpression(rowFilterExpr); needToTransform = true; } if (CollectionUtils.isNotEmpty(hiveObj.getColumns())) { List<String> columnTransformers = new ArrayList<String>(); for (String column : hiveObj.getColumns()) { boolean isColumnTransformed = addCellValueTransformerAndCheckIfTransformed(queryContext, database, table, column, columnTransformers); if(LOG.isDebugEnabled()) { LOG.debug("addCellValueTransformerAndCheckIfTransformed(database=" + database + ", table=" + table + ", column=" + column + "): " + isColumnTransformed); } needToTransform = needToTransform || isColumnTransformed; } hiveObj.setCellValueTransformers(columnTransformers); } } if (needToTransform) { ret.add(hiveObj); } } } RangerPerfTracer.log(perf); if(LOG.isDebugEnabled()) { LOG.debug("<== applyRowFilterAndColumnMasking(" + queryContext + ", objCount=" + hiveObjs.size() + "): retCount=" + ret.size()); } return ret; }
Example 3
Source File: RangerHiveAuthorizer.java From ranger with Apache License 2.0 | 4 votes |
private RangerHiveResource getHiveResource(HiveOperationType hiveOpType, HivePrivilegeObject hiveObj, List<HivePrivilegeObject> inputs, List<HivePrivilegeObject> outputs) { RangerHiveResource ret = null; HiveObjectType objectType = getObjectType(hiveObj, hiveOpType); switch(objectType) { case DATABASE: ret = new RangerHiveResource(objectType, hiveObj.getDbname()); /* if (!isCreateOperation(hiveOpType)) { ret.setOwnerUser(hiveObj.getOwnerName()); } */ break; case TABLE: case VIEW: case FUNCTION: ret = new RangerHiveResource(objectType, hiveObj.getDbname(), hiveObj.getObjectName()); // To suppress PMD violations if (LOG.isDebugEnabled()) { LOG.debug("Size of inputs = [" + (CollectionUtils.isNotEmpty(inputs) ? inputs.size() : 0) + ", Size of outputs = [" + (CollectionUtils.isNotEmpty(outputs) ? outputs.size() : 0) + "]"); } /* String ownerName = hiveObj.getOwnerName(); if (isCreateOperation(hiveOpType)) { HivePrivilegeObject dbObject = getDatabaseObject(hiveObj.getDbname(), inputs, outputs); if (dbObject != null) { ownerName = dbObject.getOwnerName(); } } ret.setOwnerUser(ownerName); */ break; case PARTITION: case INDEX: ret = new RangerHiveResource(objectType, hiveObj.getDbname(), hiveObj.getObjectName()); break; case COLUMN: ret = new RangerHiveResource(objectType, hiveObj.getDbname(), hiveObj.getObjectName(), StringUtils.join(hiveObj.getColumns(), COLUMN_SEP)); //ret.setOwnerUser(hiveObj.getOwnerName()); break; case URI: case SERVICE_NAME: ret = new RangerHiveResource(objectType, hiveObj.getObjectName()); break; case GLOBAL: ret = new RangerHiveResource(objectType,hiveObj.getObjectName()); break; case NONE: break; } if (ret != null) { ret.setServiceDef(hivePlugin == null ? null : hivePlugin.getServiceDef()); } return ret; }
Example 4
Source File: DefaultSentryValidator.java From incubator-sentry with Apache License 2.0 | 4 votes |
private List<HivePrivilegeObject> filterShowTables(List<HivePrivilegeObject> listObjs, String userName, HiveAuthzBinding hiveAuthzBinding) { List<HivePrivilegeObject> filteredResult = new ArrayList<HivePrivilegeObject>(); Subject subject = new Subject(userName); HiveAuthzPrivileges tableMetaDataPrivilege = new HiveAuthzPrivileges.AuthzPrivilegeBuilder() .addInputObjectPriviledge(AuthorizableType.Column, EnumSet.of(DBModelAction.SELECT, DBModelAction.INSERT)) .setOperationScope(HiveOperationScope.TABLE) .setOperationType( org.apache.sentry.binding.hive.authz.HiveAuthzPrivileges.HiveOperationType.INFO) .build(); for (HivePrivilegeObject obj : listObjs) { // if user has privileges on table, add to filtered list, else discard Table table = new Table(obj.getObjectName()); Database database; database = new Database(obj.getDbname()); List<List<DBModelAuthorizable>> inputHierarchy = new ArrayList<List<DBModelAuthorizable>>(); List<List<DBModelAuthorizable>> outputHierarchy = new ArrayList<List<DBModelAuthorizable>>(); List<DBModelAuthorizable> externalAuthorizableHierarchy = new ArrayList<DBModelAuthorizable>(); externalAuthorizableHierarchy.add(hiveAuthzBinding.getAuthServer()); externalAuthorizableHierarchy.add(database); externalAuthorizableHierarchy.add(table); externalAuthorizableHierarchy.add(Column.ALL); inputHierarchy.add(externalAuthorizableHierarchy); try { hiveAuthzBinding.authorize(HiveOperation.SHOWTABLES, tableMetaDataPrivilege, subject, inputHierarchy, outputHierarchy); filteredResult.add(obj); } catch (AuthorizationException e) { // squash the exception, user doesn't have privileges, so the table is // not added to // filtered list. } } return filteredResult; }