/** * Add the given {@link AuthenticationKey} to ZooKeeper. * * @param newKey * The key to add to ZooKeeper */ public synchronized void advertise(AuthenticationKey newKey) throws KeeperException, InterruptedException { checkState(initialized.get(), "Not initialized"); requireNonNull(newKey); // Make sure the node doesn't already exist String path = qualifyPath(newKey); if (zk.exists(path)) { log.warn("AuthenticationKey with ID '{}' already exists in ZooKeeper", newKey.getKeyId()); return; } // Serialize it ByteArrayOutputStream baos = new ByteArrayOutputStream(4096); try { newKey.write(new DataOutputStream(baos)); } catch (IOException e) { throw new AssertionError("Should not get exception writing to in-memory buffer", e); } byte[] serializedKey = baos.toByteArray(); log.debug("Advertising AuthenticationKey with keyId {} in ZooKeeper at {}", newKey.getKeyId(), path); // Put it into ZK with the private ACL zk.putPrivatePersistentData(path, serializedKey, NodeExistsPolicy.FAIL); }
if (!zk.putPrivatePersistentData(baseNode, new byte[0], NodeExistsPolicy.FAIL)) { throw new AssertionError("Got false from putPrivatePersistentData method");
@Override public void changePassword(String principal, AuthenticationToken token) throws AccumuloSecurityException { if (!(token instanceof PasswordToken)) throw new AccumuloSecurityException(principal, SecurityErrorCode.INVALID_TOKEN); PasswordToken pt = (PasswordToken) token; if (userExists(principal)) { try { synchronized (zooCache) { zooCache.clear(ZKUserPath + "/" + principal); context.getZooReaderWriter().putPrivatePersistentData(ZKUserPath + "/" + principal, ZKSecurityTool.createPass(pt.getPassword()), NodeExistsPolicy.OVERWRITE); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException(principal, SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (AccumuloException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException(principal, SecurityErrorCode.DEFAULT_SECURITY_ERROR, e); } } else // user doesn't exist throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST); }