private String startFunction(String function, String extraLogInfo) { incrementCounter(function); logAndAudit((getThreadLocalIpAddress() == null ? "" : "source:" + getThreadLocalIpAddress() + " ") + function + extraLogInfo); com.codahale.metrics.Timer timer = Metrics.getOrCreateTimer(MetricsConstants.API_PREFIX + function); if (timer != null) { // Timer will be null we aren't using the metrics timerContexts.get().put(function, timer.time()); } Counter counter = Metrics.getOrCreateCounter(MetricsConstants.ACTIVE_CALLS + function); if (counter != null) { counter.inc(); } return function; }
private PrincipalPrivilegeSet get_user_privilege_set(final String userName, final List<String> groupNames) throws TException { incrementCounter("get_user_privilege_set"); PrincipalPrivilegeSet ret; try { ret = getMS().getUserPrivilegeSet(userName, groupNames); } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } return ret; }
private PrincipalPrivilegeSet get_db_privilege_set(String catName, final String dbName, final String userName, final List<String> groupNames) throws TException { incrementCounter("get_db_privilege_set"); PrincipalPrivilegeSet ret; try { ret = getMS().getDBPrivilegeSet(catName, dbName, userName, groupNames); } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } return ret; }
@Override public boolean drop_role(final String roleName) throws TException { incrementCounter("drop_role"); firePreEvent(new PreAuthorizationCallEvent(this)); if (ADMIN.equals(roleName) || PUBLIC.equals(roleName)) { throw new MetaException(PUBLIC + "," + ADMIN + " roles can't be dropped."); } Boolean ret; try { ret = getMS().removeRole(roleName); } catch (MetaException e) { throw e; } catch (NoSuchObjectException e) { ret = false; MetaStoreUtils.logAndThrowMetaException(e); } catch (Exception e) { throw new TException(e); } return ret; }
@Override public boolean create_role(final Role role) throws TException { incrementCounter("create_role"); firePreEvent(new PreAuthorizationCallEvent(this)); if (PUBLIC.equals(role.getRoleName())) { throw new MetaException(PUBLIC + " role implicitly exists. It can't be created."); } Boolean ret; try { ret = getMS().addRole(role.getRoleName(), role.getOwnerName()); } catch (MetaException e) { throw e; } catch (InvalidObjectException | NoSuchObjectException e) { ret = false; MetaStoreUtils.logAndThrowMetaException(e); } catch (Exception e) { throw new TException(e); } return ret; }
@Override public GetPrincipalsInRoleResponse get_principals_in_role(GetPrincipalsInRoleRequest request) throws TException { incrementCounter("get_principals_in_role"); firePreEvent(new PreAuthorizationCallEvent(this)); Exception ex = null; GetPrincipalsInRoleResponse response = null; try { response = new GetPrincipalsInRoleResponse(getMS().listRoleMembers(request.getRoleName())); } catch (MetaException e) { throw e; } catch (Exception e) { ex = e; rethrowException(e); } finally { endFunction("get_principals_in_role", ex == null, ex); } return response; }
private List<HiveObjectPrivilege> list_table_column_privileges( final String principalName, final PrincipalType principalType, String catName, final String dbName, final String tableName, final String columnName) throws TException { incrementCounter("list_table_column_privileges"); try { if (dbName == null) { return getMS().listPrincipalTableColumnGrantsAll(principalName, principalType); } if (principalName == null) { return getMS().listTableColumnGrantsAll(catName, dbName, tableName, columnName); } return getMS().listPrincipalTableColumnGrants(principalName, principalType, catName, dbName, tableName, columnName); } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
private boolean revoke_role(final String roleName, final String userName, final PrincipalType principalType, boolean grantOption) throws TException { incrementCounter("remove_role_member"); firePreEvent(new PreAuthorizationCallEvent(this)); if (PUBLIC.equals(roleName)) { throw new MetaException(PUBLIC + " role can't be revoked."); } Boolean ret; try { RawStore ms = getMS(); Role mRole = ms.getRole(roleName); ret = ms.revokeRole(mRole, userName, principalType, grantOption); } catch (MetaException e) { throw e; } catch (NoSuchObjectException e) { ret = false; MetaStoreUtils.logAndThrowMetaException(e); } catch (Exception e) { throw new TException(e); } return ret; }
@Override public GetRoleGrantsForPrincipalResponse get_role_grants_for_principal( GetRoleGrantsForPrincipalRequest request) throws TException { incrementCounter("get_role_grants_for_principal"); firePreEvent(new PreAuthorizationCallEvent(this)); Exception ex = null; List<RolePrincipalGrant> roleMaps = null; try { roleMaps = getMS().listRolesWithGrants(request.getPrincipal_name(), request.getPrincipal_type()); } catch (MetaException e) { throw e; } catch (Exception e) { ex = e; rethrowException(e); } finally { endFunction("get_role_grants_for_principal", ex == null, ex); } //List<RolePrincipalGrant> roleGrantsList = getRolePrincipalGrants(roleMaps); return new GetRoleGrantsForPrincipalResponse(roleMaps); }
private List<HiveObjectPrivilege> list_table_privileges( final String principalName, final PrincipalType principalType, String catName, final String dbName, final String tableName) throws TException { incrementCounter("list_security_table_grant"); try { if (dbName == null) { return getMS().listPrincipalTableGrantsAll(principalName, principalType); } if (principalName == null) { return getMS().listTableGrantsAll(catName, dbName, tableName); } return getMS().listAllTableGrants(principalName, principalType, catName, dbName, tableName); } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
private List<HiveObjectPrivilege> list_db_privileges(final String principalName, final PrincipalType principalType, String catName, final String dbName) throws TException { incrementCounter("list_security_db_grant"); try { if (dbName == null) { return getMS().listPrincipalDBGrantsAll(principalName, principalType); } if (principalName == null) { return getMS().listDBGrantsAll(catName, dbName); } else { return getMS().listPrincipalDBGrants(principalName, principalType, catName, dbName); } } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public GrantRevokePrivilegeResponse refresh_privileges(HiveObjectRef objToRefresh, String authorizer, GrantRevokePrivilegeRequest grantRequest) throws TException { incrementCounter("refresh_privileges"); firePreEvent(new PreAuthorizationCallEvent(this)); GrantRevokePrivilegeResponse response = new GrantRevokePrivilegeResponse(); try { boolean result = getMS().refreshPrivileges(objToRefresh, authorizer, grantRequest.getPrivileges()); response.setSuccess(result); } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } return response; }
@Override public boolean grant_privileges(final PrivilegeBag privileges) throws TException { incrementCounter("grant_privileges"); firePreEvent(new PreAuthorizationCallEvent(this)); Boolean ret; try { ret = getMS().grantPrivileges(privileges); } catch (MetaException e) { throw e; } catch (InvalidObjectException | NoSuchObjectException e) { ret = false; MetaStoreUtils.logAndThrowMetaException(e); } catch (Exception e) { throw new TException(e); } return ret; }
public boolean revoke_privileges(final PrivilegeBag privileges, boolean grantOption) throws TException { incrementCounter("revoke_privileges"); firePreEvent(new PreAuthorizationCallEvent(this)); Boolean ret; try { ret = getMS().revokePrivileges(privileges, grantOption); } catch (MetaException e) { throw e; } catch (InvalidObjectException | NoSuchObjectException e) { ret = false; MetaStoreUtils.logAndThrowMetaException(e); } catch (Exception e) { throw new TException(e); } return ret; }
private PrincipalPrivilegeSet get_table_privilege_set(String catName, final String dbName, final String tableName, final String userName, final List<String> groupNames) throws TException { incrementCounter("get_table_privilege_set"); PrincipalPrivilegeSet ret; try { ret = getMS().getTablePrivilegeSet(catName, dbName, tableName, userName, groupNames); } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } return ret; }
private PrincipalPrivilegeSet get_column_privilege_set(String catName, final String dbName, final String tableName, final String partName, final String columnName, final String userName, final List<String> groupNames) throws TException { incrementCounter("get_column_privilege_set"); PrincipalPrivilegeSet ret; try { ret = getMS().getColumnPrivilegeSet( catName, dbName, tableName, partName, columnName, userName, groupNames); } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } return ret; }
private PrincipalPrivilegeSet get_partition_privilege_set( String catName, final String dbName, final String tableName, final String partName, final String userName, final List<String> groupNames) throws TException { incrementCounter("get_partition_privilege_set"); PrincipalPrivilegeSet ret; try { ret = getMS().getPartitionPrivilegeSet(catName, dbName, tableName, partName, userName, groupNames); } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } return ret; }
@Override public List<String> get_role_names() throws TException { incrementCounter("get_role_names"); firePreEvent(new PreAuthorizationCallEvent(this)); List<String> ret; try { ret = getMS().listRoleNames(); return ret; } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
private List<HiveObjectPrivilege> list_global_privileges( final String principalName, final PrincipalType principalType) throws TException { incrementCounter("list_security_user_grant"); try { if (principalName == null) { return getMS().listGlobalGrantsAll(); } return getMS().listPrincipalGlobalGrants(principalName, principalType); } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public List<Role> list_roles(final String principalName, final PrincipalType principalType) throws TException { incrementCounter("list_roles"); firePreEvent(new PreAuthorizationCallEvent(this)); return getMS().listRoles(principalName, principalType); }