protected Table.ID getTableId(ClientContext context, String tableName) throws ThriftTableOperationException { return ClientServiceHandler.checkTableId(context, tableName, null); }
@Override public boolean hasTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte tblPerm) throws ThriftSecurityException, ThriftTableOperationException { Table.ID tableId = checkTableId(context, tableName, TableOperation.PERMISSION); return security.hasTablePermission(credentials, user, tableId, TablePermission.getPermissionById(tblPerm)); }
@Override public Map<String,String> getTableConfiguration(TInfo tinfo, TCredentials credentials, String tableName) throws TException, ThriftTableOperationException { Table.ID tableId = checkTableId(context, tableName, null); AccumuloConfiguration config = context.getServerConfFactory().getTableConfiguration(tableId); return conf(credentials, config); }
@Override public List<TDiskUsage> getDiskUsage(Set<String> tables, TCredentials credentials) throws ThriftTableOperationException, ThriftSecurityException, TException { try { HashSet<Table.ID> tableIds = new HashSet<>(); for (String table : tables) { // ensure that table table exists Table.ID tableId = checkTableId(context, table, null); tableIds.add(tableId); Namespace.ID namespaceId = Tables.getNamespaceId(context, tableId); if (!security.canScan(credentials, tableId, namespaceId)) throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); } // use the same set of tableIds that were validated above to avoid race conditions Map<TreeSet<String>,Long> diskUsage = TableDiskUsage.getDiskUsage(tableIds, fs, context); List<TDiskUsage> retUsages = new ArrayList<>(); for (Map.Entry<TreeSet<String>,Long> usageItem : diskUsage.entrySet()) { retUsages.add(new TDiskUsage(new ArrayList<>(usageItem.getKey()), usageItem.getValue())); } return retUsages; } catch (TableNotFoundException | IOException e) { throw new TException(e); } }
@Override public boolean checkTableClass(TInfo tinfo, TCredentials credentials, String tableName, String className, String interfaceMatch) throws TException, ThriftTableOperationException, ThriftSecurityException { security.authenticateUser(credentials, credentials); Table.ID tableId = checkTableId(context, tableName, null); ClassLoader loader = getClass().getClassLoader(); Class<?> shouldMatch; try { shouldMatch = loader.loadClass(interfaceMatch); AccumuloConfiguration conf = context.getServerConfFactory().getTableConfiguration(tableId); String context = conf.get(Property.TABLE_CLASSPATH); ClassLoader currentLoader; if (context != null && !context.equals("")) { currentLoader = AccumuloVFSClassLoader.getContextManager().getClassLoader(context); } else { currentLoader = AccumuloVFSClassLoader.getClassLoader(); } Class<?> test = currentLoader.loadClass(className).asSubclass(shouldMatch); test.newInstance(); return true; } catch (Exception e) { log.warn("Error checking object types", e); return false; } }
@Override public void grantTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte permission) throws TException { Table.ID tableId = checkTableId(context, tableName, TableOperation.PERMISSION); Namespace.ID namespaceId; try { namespaceId = Tables.getNamespaceId(context, tableId); } catch (TableNotFoundException e) { throw new TException(e); } security.grantTablePermission(credentials, user, tableId, TablePermission.getPermissionById(permission), namespaceId); }
@Override public void revokeTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte permission) throws TException { Table.ID tableId = checkTableId(context, tableName, TableOperation.PERMISSION); Namespace.ID namespaceId; try { namespaceId = Tables.getNamespaceId(context, tableId); } catch (TableNotFoundException e) { throw new TException(e); } security.revokeTablePermission(credentials, user, tableId, TablePermission.getPermissionById(permission), namespaceId); }
private void alterTableProperty(TCredentials c, String tableName, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException { final Table.ID tableId = ClientServiceHandler.checkTableId(master.getContext(), tableName, op); Namespace.ID namespaceId = getNamespaceIdFromTableId(op, tableId); if (!master.security.canAlterTable(c, tableId, namespaceId)) throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); try { if (value == null || value.isEmpty()) { TablePropUtil.removeTableProperty(master.getContext(), tableId, property); } else if (!TablePropUtil.setTableProperty(master.getContext(), tableId, property, value)) { throw new Exception("Invalid table property."); } } catch (KeeperException.NoNodeException e) { // race condition... table no longer exists? This call will throw an exception if the table // was deleted: ClientServiceHandler.checkTableId(master.getContext(), tableName, op); log.info("Error altering table property", e); throw new ThriftTableOperationException(tableId.canonicalID(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property"); } catch (Exception e) { log.error("Problem altering table property", e); throw new ThriftTableOperationException(tableId.canonicalID(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property"); } }
protected String getTableId(Instance instance, String tableName) throws ThriftTableOperationException { return ClientServiceHandler.checkTableId(instance, tableName, null); }
Table.ID tableId = ClientServiceHandler.checkTableId(master.getContext(), oldTableName, tableOp); Namespace.ID namespaceId = getNamespaceIdFromTableId(tableOp, tableId); String tableName = validateTableNameArgument(arguments.get(0), tableOp, NOT_SYSTEM); final Table.ID tableId = ClientServiceHandler.checkTableId(master.getContext(), tableName, tableOp); Namespace.ID namespaceId = getNamespaceIdFromTableId(tableOp, tableId); Text endRow = ByteBufferUtil.toText(arguments.get(2)); final Table.ID tableId = ClientServiceHandler.checkTableId(master.getContext(), tableName, tableOp); Namespace.ID namespaceId = getNamespaceIdFromTableId(tableOp, tableId); final Table.ID tableId = ClientServiceHandler.checkTableId(master.getContext(), tableName, tableOp); Namespace.ID namespaceId = getNamespaceIdFromTableId(tableOp, tableId); final Table.ID tableId = ClientServiceHandler.checkTableId(master.getContext(), tableName, tableOp); Namespace.ID namespaceId = getNamespaceIdFromTableId(tableOp, tableId); Table.ID tableId = ClientServiceHandler.checkTableId(master.getContext(), tableName, tableOp); Namespace.ID namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
@Override public boolean hasTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte tblPerm) throws ThriftSecurityException, ThriftTableOperationException { String tableId = checkTableId(instance, tableName, TableOperation.PERMISSION); return security.hasTablePermission(credentials, user, tableId, TablePermission.getPermissionById(tblPerm)); }
@Override public void revokeTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte permission) throws ThriftSecurityException, ThriftTableOperationException { String tableId = checkTableId(tableName, TableOperation.PERMISSION); security.revokeTablePermission(credentials, user, tableId, TablePermission.getPermissionById(permission)); }
@Override public boolean hasTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte tblPerm) throws ThriftSecurityException, ThriftTableOperationException { String tableId = checkTableId(tableName, TableOperation.PERMISSION); return security.hasTablePermission(credentials, user, tableId, TablePermission.getPermissionById(tblPerm)); }
@Override public void grantTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte permission) throws ThriftSecurityException, ThriftTableOperationException { String tableId = checkTableId(tableName, TableOperation.PERMISSION); security.grantTablePermission(credentials, user, tableId, TablePermission.getPermissionById(permission)); }
@Override public Map<String,String> getTableConfiguration(TInfo tinfo, TCredentials credentials, String tableName) throws TException, ThriftTableOperationException { String tableId = checkTableId(instance, tableName, null); AccumuloConfiguration config = context.getServerConfigurationFactory() .getTableConfiguration(tableId); return conf(credentials, config); }
@Override public Map<String,String> getTableConfiguration(TInfo tinfo, TCredentials credentials, String tableName) throws TException, ThriftTableOperationException { String tableId = checkTableId(tableName, null); return conf(credentials, new ServerConfiguration(instance).getTableConfiguration(tableId)); }
@Override public boolean checkTableClass(TInfo tinfo, TCredentials credentials, String tableName, String className, String interfaceMatch) throws TException, ThriftTableOperationException, ThriftSecurityException { security.authenticateUser(credentials, credentials); String tableId = checkTableId(instance, tableName, null); ClassLoader loader = getClass().getClassLoader(); Class<?> shouldMatch; try { shouldMatch = loader.loadClass(interfaceMatch); AccumuloConfiguration conf = context.getServerConfigurationFactory() .getTableConfiguration(tableId); String context = conf.get(Property.TABLE_CLASSPATH); ClassLoader currentLoader; if (context != null && !context.equals("")) { currentLoader = AccumuloVFSClassLoader.getContextManager().getClassLoader(context); } else { currentLoader = AccumuloVFSClassLoader.getClassLoader(); } Class<?> test = currentLoader.loadClass(className).asSubclass(shouldMatch); test.newInstance(); return true; } catch (Exception e) { log.warn("Error checking object types", e); return false; } }
private void alterTableProperty(TCredentials c, String tableName, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException { final String tableId = ClientServiceHandler.checkTableId(master.getInstance(), tableName, op); String namespaceId = getNamespaceIdFromTableId(op, tableId); if (!master.security.canAlterTable(c, tableId, namespaceId)) throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); try { if (value == null || value.isEmpty()) { TablePropUtil.removeTableProperty(tableId, property); } else if (!TablePropUtil.setTableProperty(tableId, property, value)) { throw new Exception("Invalid table property."); } } catch (KeeperException.NoNodeException e) { // race condition... table no longer exists? This call will throw an exception if the table // was deleted: ClientServiceHandler.checkTableId(master.getInstance(), tableName, op); log.info("Error altering table property", e); throw new ThriftTableOperationException(tableId, tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property"); } catch (Exception e) { log.error("Problem altering table property", e); throw new ThriftTableOperationException(tableId, tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property"); } }
@Override public void grantTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte permission) throws TException { String tableId = checkTableId(instance, tableName, TableOperation.PERMISSION); String namespaceId; try { namespaceId = Tables.getNamespaceId(instance, tableId); } catch (TableNotFoundException e) { throw new TException(e); } security.grantTablePermission(credentials, user, tableId, TablePermission.getPermissionById(permission), namespaceId); }
@Override public void revokeTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte permission) throws TException { String tableId = checkTableId(instance, tableName, TableOperation.PERMISSION); String namespaceId; try { namespaceId = Tables.getNamespaceId(instance, tableId); } catch (TableNotFoundException e) { throw new TException(e); } security.revokeTablePermission(credentials, user, tableId, TablePermission.getPermissionById(permission), namespaceId); }