use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class SecurityOperation method revokeNamespacePermission.
public void revokeNamespacePermission(TCredentials c, String user, Namespace.ID namespace, NamespacePermission permission) throws ThriftSecurityException {
if (!canRevokeNamespace(c, user, namespace))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
targetUserExists(user);
try {
permHandle.revokeNamespacePermission(user, namespace, permission);
log.info("Revoked namespace permission {} for user {} on the namespace {} at the request of user {}", permission, user, namespace, c.getPrincipal());
} catch (AccumuloSecurityException e) {
throw e.asThriftException();
} catch (NamespaceNotFoundException e) {
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.NAMESPACE_DOESNT_EXIST);
}
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class SecurityOperation method grantNamespacePermission.
public void grantNamespacePermission(TCredentials c, String user, Namespace.ID namespace, NamespacePermission permission) throws ThriftSecurityException {
if (!canGrantNamespace(c, user, namespace))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
targetUserExists(user);
try {
permHandle.grantNamespacePermission(user, namespace, permission);
log.info("Granted namespace permission {} for user {} on the namespace {} at the request of user {}", permission, user, namespace, c.getPrincipal());
} catch (AccumuloSecurityException e) {
throw e.asThriftException();
} catch (NamespaceNotFoundException e) {
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.NAMESPACE_DOESNT_EXIST);
}
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class Shell method getClassLoader.
public ClassLoader getClassLoader(final CommandLine cl, final Shell shellState) throws AccumuloException, TableNotFoundException, AccumuloSecurityException, IOException, FileSystemException {
boolean tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !shellState.getTableName().isEmpty();
boolean namespaces = cl.hasOption(OptUtil.namespaceOpt().getOpt());
String classpath = null;
Iterable<Entry<String, String>> tableProps;
if (namespaces) {
try {
tableProps = shellState.getConnector().namespaceOperations().getProperties(OptUtil.getNamespaceOpt(cl, shellState));
} catch (NamespaceNotFoundException e) {
throw new IllegalArgumentException(e);
}
} else if (tables) {
tableProps = shellState.getConnector().tableOperations().getProperties(OptUtil.getTableOpt(cl, shellState));
} else {
throw new IllegalArgumentException("No table or namespace specified");
}
for (Entry<String, String> entry : tableProps) {
if (entry.getKey().equals(Property.TABLE_CLASSPATH.getKey())) {
classpath = entry.getValue();
}
}
ClassLoader classloader;
if (classpath != null && !classpath.equals("")) {
shellState.getConnector().instanceOperations().getSystemConfiguration().get(Property.VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + classpath);
try {
final Map<String, String> systemConfig = shellState.getConnector().instanceOperations().getSystemConfiguration();
AccumuloVFSClassLoader.getContextManager().setContextConfig(new ContextManager.DefaultContextsConfig() {
@Override
public Map<String, String> getVfsContextClasspathProperties() {
Map<String, String> filteredMap = new HashMap<>();
for (Entry<String, String> entry : systemConfig.entrySet()) {
if (entry.getKey().startsWith(Property.VFS_CONTEXT_CLASSPATH_PROPERTY.getKey())) {
filteredMap.put(entry.getKey(), entry.getValue());
}
}
return filteredMap;
}
});
} catch (IllegalStateException ise) {
}
classloader = AccumuloVFSClassLoader.getContextManager().getClassLoader(classpath);
} else {
classloader = AccumuloVFSClassLoader.getClassLoader();
}
return classloader;
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class MockTableOperations method getProperties.
@Override
public Iterable<Entry<String, String>> getProperties(String tableName) throws TableNotFoundException {
String namespace = Tables.qualify(tableName).getFirst();
if (!exists(tableName)) {
if (!namespaceExists(namespace))
throw new TableNotFoundException(tableName, new NamespaceNotFoundException(null, namespace, null));
throw new TableNotFoundException(null, tableName, null);
}
Set<Entry<String, String>> props = new HashSet<>(acu.namespaces.get(namespace).settings.entrySet());
Set<Entry<String, String>> tableProps = acu.tables.get(tableName).settings.entrySet();
for (Entry<String, String> e : tableProps) {
if (props.contains(e)) {
props.remove(e);
}
props.add(e);
}
return props;
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class ZKPermHandler method hasNamespacePermission.
@Override
public boolean hasNamespacePermission(String user, Namespace.ID namespace, NamespacePermission permission) throws NamespaceNotFoundException {
byte[] serializedPerms;
final ZooReaderWriter zrw = ZooReaderWriter.getInstance();
try {
String path = ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace;
zrw.sync(path);
serializedPerms = zrw.getData(path, null);
} catch (KeeperException e) {
if (e.code() == Code.NONODE) {
// maybe the namespace was just deleted?
try {
// check for existence:
zrw.getData(ZKNamespacePath + "/" + namespace, null);
// it's there, you don't have permission
return false;
} catch (InterruptedException ex) {
log.warn("Unhandled InterruptedException, failing closed for namespace permission check", e);
return false;
} catch (KeeperException ex) {
// not there, throw an informative exception
if (e.code() == Code.NONODE) {
throw new NamespaceNotFoundException(namespace.canonicalID(), null, "while checking permissions");
}
log.warn("Unhandled InterruptedException, failing closed for table permission check", e);
}
return false;
}
log.warn("Unhandled KeeperException, failing closed for table permission check", e);
return false;
} catch (InterruptedException e) {
log.warn("Unhandled InterruptedException, failing closed for table permission check", e);
return false;
}
if (serializedPerms != null) {
return ZKSecurityTool.convertNamespacePermissions(serializedPerms).contains(permission);
}
return false;
}
Aggregations