本文整理了Java中org.apache.accumulo.server.security.delegation.ZooAuthenticationKeyDistributor
类的一些代码示例,展示了ZooAuthenticationKeyDistributor
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooAuthenticationKeyDistributor
类的具体详情如下:
包路径:org.apache.accumulo.server.security.delegation.ZooAuthenticationKeyDistributor
类名称:ZooAuthenticationKeyDistributor
[英]Class that manages distribution of AuthenticationKeys, Accumulo's secret in the delegation token model, to other Accumulo nodes via ZooKeeper.
[中]类,该类管理AuthenticationKeys的分发,AuthenticationKeys是Accumulo在委派令牌模型中的秘密,通过ZooKeeper分发给其他Accumulo节点。
代码示例来源:origin: apache/accumulo
keyDistributor.advertise(newKey);
} catch (KeeperException | InterruptedException e) {
log.error("Failed to advertise AuthenticationKey in ZooKeeper. Exiting.", e);
代码示例来源:origin: apache/accumulo
@VisibleForTesting
void updateStateFromCurrentKeys() {
try {
List<AuthenticationKey> currentKeys = keyDistributor.getCurrentKeys();
if (!currentKeys.isEmpty()) {
for (AuthenticationKey key : currentKeys) {
// Ensure that we don't create new Keys with duplicate keyIds for keys that already exist
// It's not a big concern if we happen to duplicate keyIds for already expired keys.
if (key.getKeyId() > idSeq) {
idSeq = key.getKeyId();
}
secretManager.addKey(key);
}
log.info("Added {} existing AuthenticationKeys into the local cache from ZooKeeper",
currentKeys.size());
// Try to use the last key instead of creating a new one right away. This will present more
// expected
// functionality if the active master happens to die for some reason
AuthenticationKey currentKey = secretManager.getCurrentKey();
if (currentKey != null) {
log.info("Updating last key update to {} from current secret manager key",
currentKey.getCreationDate());
lastKeyUpdate = currentKey.getCreationDate();
}
}
} catch (KeeperException | InterruptedException e) {
log.warn("Failed to fetch existing AuthenticationKeys from ZooKeeper");
}
}
代码示例来源:origin: apache/accumulo
String qualifyPath(AuthenticationKey key) {
return qualifyPath(Integer.toString(key.getKeyId()));
}
}
代码示例来源:origin: apache/accumulo
/**
* Inspect each key cached in {@link #allKeys} and remove it if the expiration date has passed.
* For each removed local {@link AuthenticationKey}, the key is also removed from ZooKeeper using
* the provided {@code keyDistributor} instance.
*
* @param keyDistributor
* ZooKeeper key distribution class
*/
synchronized int removeExpiredKeys(ZooAuthenticationKeyDistributor keyDistributor) {
long now = System.currentTimeMillis();
int keysRemoved = 0;
Iterator<Entry<Integer,AuthenticationKey>> iter = allKeys.entrySet().iterator();
while (iter.hasNext()) {
Entry<Integer,AuthenticationKey> entry = iter.next();
AuthenticationKey key = entry.getValue();
if (key.getExpirationDate() < now) {
log.debug("Removing expired delegation token key {}", key.getKeyId());
iter.remove();
keysRemoved++;
try {
keyDistributor.remove(key);
} catch (KeeperException | InterruptedException e) {
log.error("Failed to remove AuthenticationKey from ZooKeeper. Exiting", e);
throw new RuntimeException(e);
}
}
}
return keysRemoved;
}
代码示例来源:origin: apache/accumulo
final long tokenUpdateInterval = aconf
.getTimeInMillis(Property.GENERAL_DELEGATION_TOKEN_UPDATE_INTERVAL);
keyDistributor = new ZooAuthenticationKeyDistributor(context.getZooReaderWriter(),
getZooKeeperRoot() + Constants.ZDELEGATION_TOKEN_KEYS);
authenticationTokenKeyManager = new AuthenticationTokenKeyManager(context.getSecretManager(),
代码示例来源:origin: apache/accumulo
keyDistributor.initialize();
authenticationTokenKeyManager.start();
boolean logged = false;
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
/**
* Inspect each key cached in {@link #allKeys} and remove it if the expiration date has passed.
* For each removed local {@link AuthenticationKey}, the key is also removed from ZooKeeper using
* the provided {@code keyDistributor} instance.
*
* @param keyDistributor
* ZooKeeper key distribution class
*/
synchronized int removeExpiredKeys(ZooAuthenticationKeyDistributor keyDistributor) {
long now = System.currentTimeMillis();
int keysRemoved = 0;
Iterator<Entry<Integer,AuthenticationKey>> iter = allKeys.entrySet().iterator();
while (iter.hasNext()) {
Entry<Integer,AuthenticationKey> entry = iter.next();
AuthenticationKey key = entry.getValue();
if (key.getExpirationDate() < now) {
log.debug("Removing expired delegation token key {}", key.getKeyId());
iter.remove();
keysRemoved++;
try {
keyDistributor.remove(key);
} catch (KeeperException | InterruptedException e) {
log.error("Failed to remove AuthenticationKey from ZooKeeper. Exiting", e);
throw new RuntimeException(e);
}
}
}
return keysRemoved;
}
代码示例来源:origin: org.apache.accumulo/accumulo-master
final long tokenUpdateInterval = aconf
.getTimeInMillis(Property.GENERAL_DELEGATION_TOKEN_UPDATE_INTERVAL);
keyDistributor = new ZooAuthenticationKeyDistributor(ZooReaderWriter.getInstance(),
ZooUtil.getRoot(getInstance()) + Constants.ZDELEGATION_TOKEN_KEYS);
authenticationTokenKeyManager = new AuthenticationTokenKeyManager(getSecretManager(),
代码示例来源:origin: org.apache.accumulo/accumulo-master
keyDistributor.initialize();
authenticationTokenKeyManager.start();
boolean logged = false;
代码示例来源:origin: apache/accumulo
/**
* Fetch all {@link AuthenticationKey}s currently stored in ZooKeeper beneath the configured
* {@code baseNode}.
*
* @return A list of {@link AuthenticationKey}s
*/
public List<AuthenticationKey> getCurrentKeys() throws KeeperException, InterruptedException {
checkState(initialized.get(), "Not initialized");
List<String> children = zk.getChildren(baseNode);
// Shortcircuit to avoid a list creation
if (children.isEmpty()) {
return Collections.emptyList();
}
// Deserialize each byte[] into an AuthenticationKey
List<AuthenticationKey> keys = new ArrayList<>(children.size());
for (String child : children) {
byte[] data = zk.getData(qualifyPath(child), null);
if (data != null) {
AuthenticationKey key = new AuthenticationKey();
try {
key.readFields(new DataInputStream(new ByteArrayInputStream(data)));
} catch (IOException e) {
throw new AssertionError("Error reading from in-memory buffer which should not happen",
e);
}
keys.add(key);
}
}
return keys;
}
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
@VisibleForTesting
void updateStateFromCurrentKeys() {
try {
List<AuthenticationKey> currentKeys = keyDistributor.getCurrentKeys();
if (!currentKeys.isEmpty()) {
for (AuthenticationKey key : currentKeys) {
// Ensure that we don't create new Keys with duplicate keyIds for keys that already exist
// It's not a big concern if we happen to duplicate keyIds for already expired keys.
if (key.getKeyId() > idSeq) {
idSeq = key.getKeyId();
}
secretManager.addKey(key);
}
log.info("Added {} existing AuthenticationKeys into the local cache from ZooKeeper",
currentKeys.size());
// Try to use the last key instead of creating a new one right away. This will present more
// expected
// functionality if the active master happens to die for some reasonn
AuthenticationKey currentKey = secretManager.getCurrentKey();
if (null != currentKey) {
log.info("Updating last key update to {} from current secret manager key",
currentKey.getCreationDate());
lastKeyUpdate = currentKey.getCreationDate();
}
}
} catch (KeeperException | InterruptedException e) {
log.warn("Failed to fetch existing AuthenticationKeys from ZooKeeper");
}
}
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
keyDistributor.advertise(newKey);
} catch (KeeperException | InterruptedException e) {
log.error("Failed to advertise AuthenticationKey in ZooKeeper. Exiting.", e);
代码示例来源:origin: apache/accumulo
/**
* Remove the given {@link AuthenticationKey} from ZooKeeper. If the node for the provided
* {@code key} doesn't exist in ZooKeeper, a warning is printed but an error is not thrown. Since
* there is only a single process managing ZooKeeper at one time, any inconsistencies should be
* client error.
*
* @param key
* The key to remove from ZooKeeper
*/
public synchronized void remove(AuthenticationKey key)
throws KeeperException, InterruptedException {
checkState(initialized.get(), "Not initialized");
requireNonNull(key);
String path = qualifyPath(key);
if (!zk.exists(path)) {
log.warn("AuthenticationKey with ID '{}' doesn't exist in ZooKeeper", key.getKeyId());
return;
}
log.debug("Removing AuthenticationKey with keyId {} from ZooKeeper at {}", key.getKeyId(),
path);
// Delete the node, any version
zk.delete(path, -1);
}
代码示例来源:origin: apache/accumulo
/**
* 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);
}
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
String qualifyPath(AuthenticationKey key) {
return qualifyPath(Integer.toString(key.getKeyId()));
}
}
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
/**
* Fetch all {@link AuthenticationKey}s currently stored in ZooKeeper beneath the configured
* {@code baseNode}.
*
* @return A list of {@link AuthenticationKey}s
*/
public List<AuthenticationKey> getCurrentKeys() throws KeeperException, InterruptedException {
checkState(initialized.get(), "Not initialized");
List<String> children = zk.getChildren(baseNode);
// Shortcircuit to avoid a list creation
if (children.isEmpty()) {
return Collections.<AuthenticationKey> emptyList();
}
// Deserialize each byte[] into an AuthenticationKey
List<AuthenticationKey> keys = new ArrayList<>(children.size());
for (String child : children) {
byte[] data = zk.getData(qualifyPath(child), null);
if (null != data) {
AuthenticationKey key = new AuthenticationKey();
try {
key.readFields(new DataInputStream(new ByteArrayInputStream(data)));
} catch (IOException e) {
throw new AssertionError("Error reading from in-memory buffer which should not happen",
e);
}
keys.add(key);
}
}
return keys;
}
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
/**
* Remove the given {@link AuthenticationKey} from ZooKeeper. If the node for the provided
* {@code key} doesn't exist in ZooKeeper, a warning is printed but an error is not thrown. Since
* there is only a single process managing ZooKeeper at one time, any inconsistencies should be
* client error.
*
* @param key
* The key to remove from ZooKeeper
*/
public synchronized void remove(AuthenticationKey key)
throws KeeperException, InterruptedException {
checkState(initialized.get(), "Not initialized");
requireNonNull(key);
String path = qualifyPath(key);
if (!zk.exists(path)) {
log.warn("AuthenticationKey with ID '{}' doesn't exist in ZooKeeper", key.getKeyId());
return;
}
log.debug("Removing AuthenticationKey with keyId {} from ZooKeeper at {}", key.getKeyId(),
path);
// Delete the node, any version
zk.delete(path, -1);
}
代码示例来源:origin: org.apache.accumulo/accumulo-server-base
/**
* 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);
}
内容来源于网络,如有侵权,请联系作者删除!