@Override public synchronized DelegationKey getCurrentKey() throws IOException { DelegationKey currentKey = getDelegationKey(getCurrentKeyId()); if (currentKey != null) return currentKey; // Try to roll the key if none is found. HiveDelegationTokenSupport.rollMasterKey(this); return getDelegationKey(getCurrentKeyId()); }
@Override public DelegationTokenInformation getToken(DelegationTokenIdentifier tokenIdentifier) throws TokenStoreException { try { String tokenStr = (String)invokeOnRawStore("getToken", new Object[] { TokenStoreDelegationTokenSecretManager.encodeWritable(tokenIdentifier)}, String.class); return (null == tokenStr) ? null : HiveDelegationTokenSupport.decodeDelegationTokenInformation(Base64.decodeBase64(tokenStr)); } catch (IOException e) { throw new TokenStoreException(e); } }
@Override public boolean addToken(DelegationTokenIdentifier tokenIdentifier, DelegationTokenInformation token) throws TokenStoreException { try { String identifier = TokenStoreDelegationTokenSecretManager.encodeWritable(tokenIdentifier); String tokenStr = Base64.encodeBase64URLSafeString( HiveDelegationTokenSupport.encodeDelegationTokenInformation(token)); boolean result = (Boolean)invokeOnRawStore("addToken", new Object[] {identifier, tokenStr}, String.class, String.class); if (LOG.isTraceEnabled()) { LOG.trace("addToken: tokenIdentifier = " + tokenIdentifier + ", added = " + result); } return result; } catch (IOException e) { throw new TokenStoreException(e); } }
@Override public DelegationTokenInformation getToken(DelegationTokenIdentifier tokenIdentifier) throws TokenStoreException { try { String tokenStr = (String)invokeOnRawStore("getToken", new Object[] { TokenStoreDelegationTokenSecretManager.encodeWritable(tokenIdentifier)}, String.class); return (null == tokenStr) ? null : HiveDelegationTokenSupport.decodeDelegationTokenInformation(Base64.decodeBase64(tokenStr)); } catch (IOException e) { throw new TokenStoreException(e); } }
@Override public boolean addToken(DelegationTokenIdentifier tokenIdentifier, DelegationTokenInformation token) throws TokenStoreException { try { String identifier = TokenStoreDelegationTokenSecretManager.encodeWritable(tokenIdentifier); String tokenStr = Base64.encodeBase64URLSafeString( HiveDelegationTokenSupport.encodeDelegationTokenInformation(token)); return (Boolean)invokeOnRawStore("addToken", new Object[] {identifier, tokenStr}, String.class, String.class); } catch (IOException e) { throw new TokenStoreException(e); } }
@Override public DelegationTokenInformation getToken(DelegationTokenIdentifier tokenIdentifier) throws TokenStoreException { try { String tokenStr = (String)invokeOnRawStore("getToken", new Object[] { TokenStoreDelegationTokenSecretManager.encodeWritable(tokenIdentifier)}, String.class); DelegationTokenInformation result = null; if (tokenStr != null) { result = HiveDelegationTokenSupport.decodeDelegationTokenInformation(Base64.decodeBase64(tokenStr)); } if (LOG.isTraceEnabled()) { LOG.trace("getToken: tokenIdentifier = " + tokenIdentifier + ", result = " + result); } return result; } catch (IOException e) { throw new TokenStoreException(e); } }
@Override public boolean addToken(DelegationTokenIdentifier tokenIdentifier, DelegationTokenInformation token) throws TokenStoreException { try { String identifier = TokenStoreDelegationTokenSecretManager.encodeWritable(tokenIdentifier); String tokenStr = Base64.encodeBase64URLSafeString( HiveDelegationTokenSupport.encodeDelegationTokenInformation(token)); return (Boolean)invokeOnRawStore("addToken", new Object[] {identifier, tokenStr}, String.class, String.class); } catch (IOException e) { throw new TokenStoreException(e); } }
/** * Extension of rollMasterKey to remove expired keys from store. * * @throws IOException */ protected void rollMasterKeyExt() throws IOException { Map<Integer, DelegationKey> keys = reloadKeys(); int currentKeyId = super.currentId; HiveDelegationTokenSupport.rollMasterKey(TokenStoreDelegationTokenSecretManager.this); List<DelegationKey> keysAfterRoll = Arrays.asList(getAllKeys()); for (DelegationKey key : keysAfterRoll) { keys.remove(key.getKeyId()); if (key.getKeyId() == currentKeyId) { tokenStore.updateMasterKey(currentKeyId, encodeWritable(key)); } } for (DelegationKey expiredKey : keys.values()) { LOGGER.info("Removing expired key id={}", expiredKey.getKeyId()); try { tokenStore.removeMasterKey(expiredKey.getKeyId()); } catch (Exception e) { LOGGER.error("Error removing expired key id={}", expiredKey.getKeyId(), e); } } }
@Override public DelegationTokenInformation getToken(DelegationTokenIdentifier tokenIdentifier) { byte[] tokenBytes = zkGetData(getTokenPath(tokenIdentifier)); try { return HiveDelegationTokenSupport.decodeDelegationTokenInformation(tokenBytes); } catch (Exception ex) { throw new TokenStoreException("Failed to decode token", ex); } }
@Override public boolean addToken(DelegationTokenIdentifier tokenIdentifier, DelegationTokenInformation token) { try { ZooKeeper zk = getSession(); byte[] tokenBytes = HiveDelegationTokenSupport.encodeDelegationTokenInformation(token); String newNode = zk.create(getTokenPath(tokenIdentifier), tokenBytes, newNodeAcl, CreateMode.PERSISTENT); LOGGER.info("Added token: {}", newNode); return true; } catch (KeeperException.NodeExistsException ex) { return false; } catch (KeeperException ex) { throw new TokenStoreException(ex); } catch (InterruptedException ex) { throw new TokenStoreException(ex); } }
/** * Extension of rollMasterKey to remove expired keys from store. * @throws IOException */ protected void rollMasterKeyExt() throws IOException { Map<Integer, DelegationKey> keys = reloadKeys(); int currentKeyId = super.currentId; HiveDelegationTokenSupport.rollMasterKey(TokenStoreDelegationTokenSecretManager.this); List<DelegationKey> keysAfterRoll = Arrays.asList(getAllKeys()); for (DelegationKey key : keysAfterRoll) { keys.remove(key.getKeyId()); if (key.getKeyId() == currentKeyId) { tokenStore.updateMasterKey(currentKeyId, encodeWritable(key)); } } for (DelegationKey expiredKey : keys.values()) { LOGGER.info("Removing expired key id={}", expiredKey.getKeyId()); tokenStore.removeMasterKey(expiredKey.getKeyId()); } }
@Override public DelegationTokenInformation getToken(DelegationTokenIdentifier tokenIdentifier) { byte[] tokenBytes = zkGetData(getTokenPath(tokenIdentifier)); try { return HiveDelegationTokenSupport.decodeDelegationTokenInformation(tokenBytes); } catch (Exception ex) { throw new TokenStoreException("Failed to decode token", ex); } }
@Override public boolean addToken(DelegationTokenIdentifier tokenIdentifier, DelegationTokenInformation token) { byte[] tokenBytes = HiveDelegationTokenSupport.encodeDelegationTokenInformation(token); String tokenPath = getTokenPath(tokenIdentifier); CuratorFramework zk = getSession(); String newNode; try { newNode = zk.create().withMode(CreateMode.PERSISTENT).withACL(newNodeAcl) .forPath(tokenPath, tokenBytes); } catch (Exception e) { throw new TokenStoreException("Error creating new node with path " + tokenPath, e); } LOGGER.info("Added token: {}", newNode); return true; }
/** * Extension of rollMasterKey to remove expired keys from store. * * @throws IOException */ protected void rollMasterKeyExt() throws IOException { Map<Integer, DelegationKey> keys = reloadKeys(); int currentKeyId = super.currentId; HiveDelegationTokenSupport.rollMasterKey(TokenStoreDelegationTokenSecretManager.this); List<DelegationKey> keysAfterRoll = Arrays.asList(getAllKeys()); for (DelegationKey key : keysAfterRoll) { keys.remove(key.getKeyId()); if (key.getKeyId() == currentKeyId) { tokenStore.updateMasterKey(currentKeyId, encodeWritable(key)); } } for (DelegationKey expiredKey : keys.values()) { LOGGER.info("Removing expired key id={}", expiredKey.getKeyId()); try { tokenStore.removeMasterKey(expiredKey.getKeyId()); } catch (Exception e) { LOGGER.error("Error removing expired key id={}", expiredKey.getKeyId(), e); } } }
@Override public DelegationTokenInformation getToken(DelegationTokenIdentifier tokenIdentifier) { byte[] tokenBytes = zkGetData(getTokenPath(tokenIdentifier)); try { return HiveDelegationTokenSupport.decodeDelegationTokenInformation(tokenBytes); } catch (Exception ex) { throw new TokenStoreException("Failed to decode token", ex); } }
@Override public boolean addToken(DelegationTokenIdentifier tokenIdentifier, DelegationTokenInformation token) { byte[] tokenBytes = HiveDelegationTokenSupport.encodeDelegationTokenInformation(token); String tokenPath = getTokenPath(tokenIdentifier); CuratorFramework zk = getSession(); String newNode; try { newNode = zk.create().withMode(CreateMode.PERSISTENT).withACL(newNodeAcl) .forPath(tokenPath, tokenBytes); } catch (Exception e) { throw new TokenStoreException("Error creating new node with path " + tokenPath, e); } LOGGER.info("Added token: {}", newNode); return true; }
/** * Extension of rollMasterKey to remove expired keys from store. * * @throws IOException */ protected void rollMasterKeyExt() throws IOException { Map<Integer, DelegationKey> keys = reloadKeys(); int currentKeyId = super.currentId; HiveDelegationTokenSupport.rollMasterKey(TokenStoreDelegationTokenSecretManager.this); List<DelegationKey> keysAfterRoll = Arrays.asList(getAllKeys()); for (DelegationKey key : keysAfterRoll) { keys.remove(key.getKeyId()); if (key.getKeyId() == currentKeyId) { tokenStore.updateMasterKey(currentKeyId, encodeWritable(key)); } } for (DelegationKey expiredKey : keys.values()) { LOGGER.info("Removing expired key id={}", expiredKey.getKeyId()); try { tokenStore.removeMasterKey(expiredKey.getKeyId()); } catch (Exception e) { LOGGER.error("Error removing expired key id={}", expiredKey.getKeyId(), e); } } }
@Override public DelegationTokenInformation getToken(DelegationTokenIdentifier tokenIdentifier) { try { ZooKeeper zk = getSession(); byte[] tokenBytes = zk.getData(getTokenPath(tokenIdentifier), false, null); try { return HiveDelegationTokenSupport.decodeDelegationTokenInformation(tokenBytes); } catch (Exception ex) { throw new TokenStoreException("Failed to decode token", ex); } } catch (KeeperException.NoNodeException ex) { return null; } catch (KeeperException ex) { throw new TokenStoreException(ex); } catch (InterruptedException ex) { throw new TokenStoreException(ex); } }
@Override public boolean addToken(DelegationTokenIdentifier tokenIdentifier, DelegationTokenInformation token) { byte[] tokenBytes = HiveDelegationTokenSupport.encodeDelegationTokenInformation(token); String tokenPath = getTokenPath(tokenIdentifier); CuratorFramework zk = getSession(); String newNode; try { newNode = zk.create().withMode(CreateMode.PERSISTENT).withACL(newNodeAcl) .forPath(tokenPath, tokenBytes); } catch (Exception e) { throw new TokenStoreException("Error creating new node with path " + tokenPath, e); } LOGGER.info("Added token: {}", newNode); return true; }
@Override public DelegationTokenInformation getToken(DelegationTokenIdentifier tokenIdentifier) throws TokenStoreException { try { String tokenStr = (String)invokeOnRawStore("getToken", new Object[] { TokenStoreDelegationTokenSecretManager.encodeWritable(tokenIdentifier)}, String.class); DelegationTokenInformation result = null; if (tokenStr != null) { result = HiveDelegationTokenSupport.decodeDelegationTokenInformation(Base64.decodeBase64(tokenStr)); } if (LOG.isTraceEnabled()) { LOG.trace("getToken: tokenIdentifier = " + tokenIdentifier + ", result = " + result); } return result; } catch (IOException e) { throw new TokenStoreException(e); } }