@Override protected void finalize() { if (zooCache != null) zooCache.clear(); } }
@Override public void invalidateCache() { if (propCache != null) propCache.clear(); }
/** * Clears the internal {@link ZooCache}. */ void invalidateCache() { propCache.clear(); }
@Override public void invalidateCache(String tserver) { zc.clear(root + "/" + tserver); }
@Override public void invalidateCache(ClientContext context, String server) { ZooCache zooCache = context.getZooCache(); String root = context.getZooKeeperRoot() + Constants.ZTSERVERS; zooCache.clear(root + "/" + server); }
/** * Sets up a new table configuration for the provided user/table. No checking for existence is * done here, it should be done before calling. */ private void createTablePerm(String user, Table.ID table, Set<TablePermission> perms) throws KeeperException, InterruptedException { synchronized (zooCache) { zooCache.clear(); zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, ZKSecurityTool.convertTablePermissions(perms), NodeExistsPolicy.FAIL); } }
private void createUserNodeInZk(String principal) throws KeeperException, InterruptedException { synchronized (zooCache) { zooCache.clear(); IZooReaderWriter zoo = context.getZooReaderWriter(); zoo.putPrivatePersistentData(zkUserPath + "/" + principal, new byte[0], NodeExistsPolicy.FAIL); } }
/** * Sets up a new namespace configuration for the provided user/table. No checking for existence is * done here, it should be done before calling. */ private void createNamespacePerm(String user, Namespace.ID namespace, Set<NamespacePermission> perms) throws KeeperException, InterruptedException { synchronized (zooCache) { zooCache.clear(); zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace, ZKSecurityTool.convertNamespacePermissions(perms), NodeExistsPolicy.FAIL); } }
/** * Sets up the user in ZK for the provided user. No checking for existence is done here, it should * be done before calling. */ private void constructUser(String user, byte[] pass) throws KeeperException, InterruptedException { synchronized (zooCache) { zooCache.clear(); IZooReaderWriter zoo = context.getZooReaderWriter(); zoo.putPrivatePersistentData(ZKUserPath + "/" + user, pass, NodeExistsPolicy.FAIL); } }
/** * Clears the zoo cache from instance/root/{PATH} * * @param context * The Accumulo client context * @param zooPath * A zookeeper path */ public static void clearCacheByPath(ClientContext context, final String zooPath) { String thePath = zooPath.startsWith("/") ? zooPath : "/" + zooPath; getZooCache(context).clear(context.getZooKeeperRoot() + thePath); instanceToMapCache.invalidate(context.getInstanceID()); }
@Override public void cleanNamespacePermissions(String namespace) throws AccumuloSecurityException { try { synchronized (zooCache) { zooCache.clear(); for (String user : zooCache.getChildren(ZKUserPath)) zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace, NodeMissingPolicy.SKIP); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException("unknownUser", SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
@Override public void put(String path, byte[] bs) throws DistributedStoreException { try { path = relative(path); context.getZooReaderWriter().putPersistentData(path, bs, NodeExistsPolicy.OVERWRITE); cache.clear(); log.debug("Wrote {} to {}", new String(bs, UTF_8), path); } catch (Exception ex) { throw new DistributedStoreException(ex); } }
@Override public void cleanTablePermissions(String table) throws AccumuloSecurityException { try { synchronized (zooCache) { zooCache.clear(); for (String user : zooCache.getChildren(ZKUserPath)) zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, NodeMissingPolicy.SKIP); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException("unknownUser", SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
@Override public void changeAuthorizations(String user, Authorizations authorizations) throws AccumuloSecurityException { try { synchronized (zooCache) { zooCache.clear(); context.getZooReaderWriter().putPersistentData(ZKUserPath + "/" + user + ZKUserAuths, ZKSecurityTool.convertAuthorizations(authorizations), NodeExistsPolicy.OVERWRITE); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
@Override public void dropUser(String user) throws AccumuloSecurityException { try { synchronized (zooCache) { IZooReaderWriter zoo = context.getZooReaderWriter(); zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserAuths, NodeMissingPolicy.SKIP); zooCache.clear(ZKUserPath + "/" + user); } } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (KeeperException e) { log.error("{}", e.getMessage(), e); if (e.code().equals(KeeperException.Code.NONODE)) throw new AccumuloSecurityException(user, SecurityErrorCode.USER_DOESNT_EXIST, e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } }
@Override public void dropUser(String user) throws AccumuloSecurityException { try { synchronized (zooCache) { zooCache.clear(); context.getZooReaderWriter().recursiveDelete(ZKUserPath + "/" + user, NodeMissingPolicy.FAIL); } } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (KeeperException e) { if (e.code().equals(KeeperException.Code.NONODE)) { throw new AccumuloSecurityException(user, SecurityErrorCode.USER_DOESNT_EXIST, e); } log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } }
@Override public void remove(String path) throws DistributedStoreException { try { log.debug("Removing {}", path); path = relative(path); IZooReaderWriter zoo = context.getZooReaderWriter(); if (zoo.exists(path)) zoo.recursiveDelete(path, NodeMissingPolicy.SKIP); cache.clear(); } catch (Exception ex) { throw new DistributedStoreException(ex); } } }
@Override public void cleanUser(String user) throws AccumuloSecurityException { try { synchronized (zooCache) { zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserSysPerms, NodeMissingPolicy.SKIP); zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserTablePerms, NodeMissingPolicy.SKIP); zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserNamespacePerms, NodeMissingPolicy.SKIP); zooCache.clear(ZKUserPath + "/" + user); } } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (KeeperException e) { log.error("{}", e.getMessage(), e); if (e.code().equals(KeeperException.Code.NONODE)) throw new AccumuloSecurityException(user, SecurityErrorCode.USER_DOESNT_EXIST, e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } }
@Override public boolean authenticateUser(String principal, AuthenticationToken token) throws AccumuloSecurityException { if (!(token instanceof PasswordToken)) throw new AccumuloSecurityException(principal, SecurityErrorCode.INVALID_TOKEN); PasswordToken pt = (PasswordToken) token; byte[] pass; String zpath = ZKUserPath + "/" + principal; pass = zooCache.get(zpath); boolean result = ZKSecurityTool.checkPass(pt.getPassword(), pass); if (!result) { zooCache.clear(zpath); pass = zooCache.get(zpath); result = ZKSecurityTool.checkPass(pt.getPassword(), pass); } return result; }