Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.io.IOException;
import java.security.MessageDigest;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.crypto.SecretKey;

Expand Down Expand Up @@ -58,10 +58,9 @@

@InterfaceAudience.Public
@InterfaceStability.Evolving
public abstract
class AbstractDelegationTokenSecretManager<TokenIdent
extends AbstractDelegationTokenIdentifier>
extends SecretManager<TokenIdent> {
public abstract class AbstractDelegationTokenSecretManager<TokenIdent
extends AbstractDelegationTokenIdentifier>
extends SecretManager<TokenIdent> {
private static final Logger LOG = LoggerFactory
.getLogger(AbstractDelegationTokenSecretManager.class);

Expand All @@ -80,7 +79,7 @@ private String formatTokenId(TokenIdent id) {
* to DelegationTokenInformation. Protected by this object lock.
*/
protected final Map<TokenIdent, DelegationTokenInformation> currentTokens
= new HashMap<TokenIdent, DelegationTokenInformation>();
= new ConcurrentHashMap<>();

/**
* Sequence number to create DelegationTokenIdentifier.
Expand All @@ -89,17 +88,17 @@ private String formatTokenId(TokenIdent id) {
protected int delegationTokenSequenceNumber = 0;

/**
* Access to allKeys is protected by this object lock
* Access to allKeys is protected by this object lock.
*/
protected final Map<Integer, DelegationKey> allKeys
= new HashMap<Integer, DelegationKey>();
= new ConcurrentHashMap<>();

/**
* Access to currentId is protected by this object lock.
*/
protected int currentId = 0;
/**
* Access to currentKey is protected by this object lock
* Access to currentKey is protected by this object lock.
*/
private DelegationKey currentKey;

Expand All @@ -122,7 +121,7 @@ private String formatTokenId(TokenIdent id) {
protected Object noInterruptsLock = new Object();

/**
* Create a secret manager
* Create a secret manager.
* @param delegationKeyUpdateInterval the number of milliseconds for rolling
* new secret keys.
* @param delegationTokenMaxLifetime the maximum lifetime of the delegation
Expand Down Expand Up @@ -183,8 +182,9 @@ public long getCurrentTokensSize() {
* @throws IOException raised on errors performing I/O.
*/
public synchronized void addKey(DelegationKey key) throws IOException {
if (running) // a safety check
if (running) { // a safety check
throw new IOException("Can't add delegation key to a running SecretManager.");
}
if (key.getKeyId() > getCurrentKeyId()) {
setCurrentKeyId(key.getKeyId());
}
Expand Down Expand Up @@ -453,8 +453,9 @@ private synchronized void removeExpiredKeys() {
it.remove();
// ensure the tokens generated by this current key can be recovered
// with this current key after this current key is rolled
if(!e.getValue().equals(currentKey))
if(!e.getValue().equals(currentKey)) {
removeStoredMasterKey(e.getValue());
}
}
}
}
Expand Down Expand Up @@ -729,8 +730,9 @@ protected void logExpireTokens(
}

public void stopThreads() {
if (LOG.isDebugEnabled())
if (LOG.isDebugEnabled()) {
LOG.debug("Stopping expired delegation token remover thread");
}
running = false;

if (tokenRemoverThread != null) {
Expand Down
Loading