/** * Removes a RolePrivilege from the given role name. Returns the removed RolePrivilege with an * incremented catalog version or null if no matching privilege was found. Throws a * CatalogException if no role exists with this name. */ public RolePrivilege removeRolePrivilege(String roleName, TPrivilege thriftPriv) throws CatalogException { catalogLock_.writeLock().lock(); try { Role role = authPolicy_.getRole(roleName); if (role == null) throw new CatalogException("Role does not exist: " + roleName); RolePrivilege rolePrivilege = role.removePrivilege(thriftPriv.getPrivilege_name()); if (rolePrivilege == null) return null; rolePrivilege.setCatalogVersion(incrementAndGetCatalogVersion()); return rolePrivilege; } finally { catalogLock_.writeLock().unlock(); } }
/** * Adds a privilege to the given role name. Returns the new RolePrivilege and increments the * catalog version. If the parent role does not exist a CatalogException is thrown. */ public RolePrivilege addRolePrivilege(String roleName, TPrivilege thriftPriv) throws CatalogException { catalogLock_.writeLock().lock(); try { Role role = authPolicy_.getRole(roleName); if (role == null) throw new CatalogException("Role does not exist: " + roleName); RolePrivilege priv = RolePrivilege.fromThrift(thriftPriv); priv.setCatalogVersion(incrementAndGetCatalogVersion()); authPolicy_.addPrivilege(priv); return priv; } finally { catalogLock_.writeLock().unlock(); } }