Search in sources :

Example 11 with NamespaceNotFoundException

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);
    }
}
Also used : AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 12 with NamespaceNotFoundException

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);
    }
}
Also used : AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 13 with NamespaceNotFoundException

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;
}
Also used : NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) Entry(java.util.Map.Entry) ContextManager(org.apache.accumulo.start.classloader.vfs.ContextManager) AccumuloVFSClassLoader(org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 14 with NamespaceNotFoundException

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;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) HashSet(java.util.HashSet)

Example 15 with NamespaceNotFoundException

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;
}
Also used : ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) KeeperException(org.apache.zookeeper.KeeperException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Aggregations

NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)23 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)12 AccumuloException (org.apache.accumulo.core.client.AccumuloException)10 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)9 ThriftTableOperationException (org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)8 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)7 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)7 TableExistsException (org.apache.accumulo.core.client.TableExistsException)6 IOException (java.io.IOException)5 TreeMap (java.util.TreeMap)4 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)4 IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)4 TTransportException (org.apache.thrift.transport.TTransportException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)3 NamespaceNotEmptyException (org.apache.accumulo.core.client.NamespaceNotEmptyException)3 ThriftNotActiveServiceException (org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException)3 MasterClientService (org.apache.accumulo.core.master.thrift.MasterClientService)3 FileNotFoundException (java.io.FileNotFoundException)2