protected Table.ID getTableId(ClientContext context, String tableName) throws ThriftTableOperationException { return ClientServiceHandler.checkTableId(context, tableName, null); }
@Override public void grantNamespacePermission(TInfo tinfo, TCredentials credentials, String user, String ns, byte permission) throws ThriftSecurityException, ThriftTableOperationException { Namespace.ID namespaceId = checkNamespaceId(context, ns, TableOperation.PERMISSION); security.grantNamespacePermission(credentials, user, namespaceId, NamespacePermission.getPermissionById(permission)); }
@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); }
Namespace.ID namespaceId = ClientServiceHandler.checkNamespaceId(master.getContext(), oldName, tableOp); if (!master.security.canRenameNamespace(c, namespaceId)) Namespace.ID namespaceId = ClientServiceHandler.checkNamespaceId(master.getContext(), namespace, tableOp); if (!master.security.canDeleteNamespace(c, namespaceId)) Table.ID tableId = ClientServiceHandler.checkTableId(master.getContext(), oldTableName, 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); 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,
@Override public Map<String,String> getConfiguration(TInfo tinfo, TCredentials credentials, ConfigurationType type) throws TException { ServerConfigurationFactory factory = context.getServerConfFactory(); switch (type) { case CURRENT: return conf(credentials, factory.getSystemConfiguration()); case SITE: return conf(credentials, factory.getSiteConfiguration()); case DEFAULT: return conf(credentials, factory.getDefaultConfiguration()); } throw new RuntimeException("Unexpected configuration type " + type); }
String namespaceId = ClientServiceHandler.checkNamespaceId(master.getInstance(), oldName, tableOp); if (!master.security.canRenameNamespace(c, namespaceId, oldName, newName)) String namespaceId = ClientServiceHandler.checkNamespaceId(master.getInstance(), namespace, tableOp); if (!master.security.canDeleteNamespace(c, namespaceId)) String tableId = ClientServiceHandler.checkTableId(master.getInstance(), oldTableName, tableOp); String namespaceId = getNamespaceIdFromTableId(tableOp, tableId); final String tableId = ClientServiceHandler.checkTableId(master.getInstance(), tableName, tableOp); String namespaceId = getNamespaceIdFromTableId(tableOp, tableId); final String tableId = ClientServiceHandler.checkTableId(master.getInstance(), tableName, tableOp); String namespaceId = getNamespaceIdFromTableId(tableOp, tableId); final String tableId = ClientServiceHandler.checkTableId(master.getInstance(), tableName, tableOp); String namespaceId = getNamespaceIdFromTableId(tableOp, tableId); final String tableId = ClientServiceHandler.checkTableId(master.getInstance(), tableName, tableOp); String namespaceId = getNamespaceIdFromTableId(tableOp, tableId); String tableId = ClientServiceHandler.checkTableId(master.getInstance(), tableName,
@Override public Map<String,String> getNamespaceConfiguration(TInfo tinfo, TCredentials credentials, String ns) throws ThriftTableOperationException, TException { Namespace.ID namespaceId; try { namespaceId = Namespaces.getNamespaceId(context, ns); } catch (NamespaceNotFoundException e) { String why = "Could not find namespace while getting configuration."; throw new ThriftTableOperationException(null, ns, null, TableOperationExceptionType.NAMESPACE_NOTFOUND, why); } AccumuloConfiguration config = context.getServerConfFactory() .getNamespaceConfiguration(namespaceId); return conf(credentials, config); }
@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 { String tableId = checkTableId(instance, tableName, null); AccumuloConfiguration config = context.getServerConfigurationFactory() .getTableConfiguration(tableId); return conf(credentials, config); }
@Override public void revokeNamespacePermission(TInfo tinfo, TCredentials credentials, String user, String ns, byte permission) throws ThriftSecurityException, ThriftTableOperationException { Namespace.ID namespaceId = checkNamespaceId(context, ns, TableOperation.PERMISSION); security.revokeNamespacePermission(credentials, user, namespaceId, NamespacePermission.getPermissionById(permission)); }
@Override public Map<String,String> getConfiguration(TInfo tinfo, TCredentials credentials, ConfigurationType type) throws TException { switch (type) { case CURRENT: return conf(credentials, new ServerConfiguration(instance).getConfiguration()); case SITE: return conf(credentials, ServerConfiguration.getSiteConfiguration()); case DEFAULT: return conf(credentials, AccumuloConfiguration.getDefaultConfiguration()); } throw new RuntimeException("Unexpected configuration type " + type); }
@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 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 hasNamespacePermission(TInfo tinfo, TCredentials credentials, String user, String ns, byte perm) throws ThriftSecurityException, ThriftTableOperationException { Namespace.ID namespaceId = checkNamespaceId(context, ns, TableOperation.PERMISSION); return security.hasNamespacePermission(credentials, user, namespaceId, NamespacePermission.getPermissionById(perm)); }
@Override public Map<String,String> getConfiguration(TInfo tinfo, TCredentials credentials, ConfigurationType type) throws TException { ServerConfigurationFactory factory = context.getServerConfigurationFactory(); switch (type) { case CURRENT: return conf(credentials, factory.getConfiguration()); case SITE: return conf(credentials, factory.getSiteConfiguration()); case DEFAULT: return conf(credentials, factory.getDefaultConfiguration()); } throw new RuntimeException("Unexpected configuration type " + type); }
@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 boolean checkNamespaceClass(TInfo tinfo, TCredentials credentials, String ns, String className, String interfaceMatch) throws TException, ThriftTableOperationException, ThriftSecurityException { security.authenticateUser(credentials, credentials); Namespace.ID namespaceId = checkNamespaceId(context, ns, null); ClassLoader loader = getClass().getClassLoader(); Class<?> shouldMatch; try { shouldMatch = loader.loadClass(interfaceMatch); AccumuloConfiguration conf = context.getServerConfFactory() .getNamespaceConfiguration(namespaceId); 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 Map<String,String> getNamespaceConfiguration(TInfo tinfo, TCredentials credentials, String ns) throws ThriftTableOperationException, TException { String namespaceId; try { namespaceId = Namespaces.getNamespaceId(instance, ns); } catch (NamespaceNotFoundException e) { String why = "Could not find namespace while getting configuration."; throw new ThriftTableOperationException(null, ns, null, TableOperationExceptionType.NAMESPACE_NOTFOUND, why); } AccumuloConfiguration config = context.getServerConfigurationFactory() .getNamespaceConfiguration(namespaceId); return conf(credentials, config); }
@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 alterNamespaceProperty(TCredentials c, String namespace, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException { Namespace.ID namespaceId = null; namespaceId = ClientServiceHandler.checkNamespaceId(master.getContext(), namespace, op); if (!master.security.canAlterNamespace(c, namespaceId)) throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); try { if (value == null) { NamespacePropUtil.removeNamespaceProperty(master.getContext(), namespaceId, property); } else { NamespacePropUtil.setNamespaceProperty(master.getContext(), namespaceId, property, value); } } catch (KeeperException.NoNodeException e) { // race condition... namespace no longer exists? This call will throw an exception if the // namespace was deleted: ClientServiceHandler.checkNamespaceId(master.getContext(), namespace, op); log.info("Error altering namespace property", e); throw new ThriftTableOperationException(namespaceId.canonicalID(), namespace, op, TableOperationExceptionType.OTHER, "Problem altering namespaceproperty"); } catch (Exception e) { log.error("Problem altering namespace property", e); throw new ThriftTableOperationException(namespaceId.canonicalID(), namespace, op, TableOperationExceptionType.OTHER, "Problem altering namespace property"); } }