private void processKeyAddOrUpdate(byte[] data) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); DelegationKey key = new DelegationKey(); key.readFields(din); synchronized (this) { allKeys.put(key.getKeyId(), key); } }
private DelegationKey getKeyFromZK(int keyId) throws IOException { String nodePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + keyId); try { byte[] data = zkClient.getData().forPath(nodePath); if ((data == null) || (data.length == 0)) { return null; } ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); DelegationKey key = new DelegationKey(); key.readFields(din); return key; } catch (KeeperException.NoNodeException e) { LOG.error("No node in path [" + nodePath + "]"); } catch (Exception ex) { throw new IOException(ex); } return null; }
protected Map<Integer, DelegationKey> reloadKeys() { // read keys from token store String[] allKeys = tokenStore.getMasterKeys(); Map<Integer, DelegationKey> keys = new HashMap<>(allKeys.length); for (String keyStr : allKeys) { DelegationKey key = new DelegationKey(); try { decodeWritable(key, keyStr); keys.put(key.getKeyId(), key); } catch (IOException ex) { LOGGER.error("Failed to load master key.", ex); } } synchronized (this) { super.allKeys.clear(); super.allKeys.putAll(keys); } return keys; }
/** * Update the current master key * This is called once by startThreads before tokenRemoverThread is created, * and only by tokenRemoverThread afterwards. */ private void updateCurrentKey() throws IOException { LOG.info("Updating the current master key for generating delegation tokens"); /* Create a new currentKey with an estimated expiry date. */ int newCurrentId; synchronized (this) { newCurrentId = incrementCurrentKeyId(); } DelegationKey newKey = new DelegationKey(newCurrentId, System .currentTimeMillis() + keyUpdateInterval + tokenMaxLifetime, generateSecret()); //Log must be invoked outside the lock on 'this' logUpdateMasterKey(newKey); synchronized (this) { currentKey = newKey; storeDelegationKey(currentKey); } }
/** * Synchronize master key updates / sequence generation for multiple nodes. * NOTE: {@link AbstractDelegationTokenSecretManager} keeps currentKey private, so we need * to utilize this "hook" to manipulate the key through the object reference. * This .20S workaround should cease to exist when Hadoop supports token store. */ @Override protected void logUpdateMasterKey(DelegationKey key) throws IOException { int keySeq = this.tokenStore.addMasterKey(encodeWritable(key)); // update key with assigned identifier DelegationKey keyWithSeq = new DelegationKey(keySeq, key.getExpiryDate(), key.getKey()); String keyStr = encodeWritable(keyWithSeq); this.tokenStore.updateMasterKey(keySeq, keyStr); decodeWritable(key, keyStr); LOGGER.info("New master key with key id={}", key.getKeyId()); super.logUpdateMasterKey(key); }
@Override void readFields(DataInputStream in, int logVersion) throws IOException { this.key = new DelegationKey(); this.key.readFields(in); }
public static DelegationKey delegationKeyFromXml(Stanza st) throws InvalidXmlException { int keyId = Integer.parseInt(st.getValue("KEY_ID")); long expiryDate = Long.parseLong(st.getValue("EXPIRY_DATE")); byte key[] = null; try { key = Hex.decodeHex(st.getValue("KEY").toCharArray()); } catch (DecoderException e) { throw new InvalidXmlException(e.toString()); } catch (InvalidXmlException e) { } return new DelegationKey(keyId, expiryDate, key); }
public synchronized void loadSecretManagerState(SecretManagerState state) throws IOException { Preconditions.checkState(!running, "Can't load state from image in a running SecretManager."); currentId = state.section.getCurrentId(); delegationTokenSequenceNumber = state.section.getTokenSequenceNumber(); for (SecretManagerSection.DelegationKey k : state.keys) { addKey(new DelegationKey(k.getId(), k.getExpiryDate(), k.hasKey() ? k .getKey().toByteArray() : null)); } for (SecretManagerSection.PersistToken t : state.tokens) { DelegationTokenIdentifier id = new DelegationTokenIdentifier(new Text( t.getOwner()), new Text(t.getRenewer()), new Text(t.getRealUser())); id.setIssueDate(t.getIssueDate()); id.setMaxDate(t.getMaxDate()); id.setSequenceNumber(t.getSequenceNumber()); id.setMasterKeyId(t.getMasterKeyId()); addPersistedDelegationToken(id, t.getExpiryDate()); } }
/** * Private helper method to load delegation keys from fsimage. * @throws IOException on error */ private synchronized void loadAllKeys(DataInput in) throws IOException { StartupProgress prog = NameNode.getStartupProgress(); Step step = new Step(StepType.DELEGATION_KEYS); prog.beginStep(Phase.LOADING_FSIMAGE, step); int numberOfKeys = in.readInt(); prog.setTotal(Phase.LOADING_FSIMAGE, step, numberOfKeys); Counter counter = prog.getCounter(Phase.LOADING_FSIMAGE, step); for (int i = 0; i < numberOfKeys; i++) { DelegationKey value = new DelegationKey(); value.readFields(in); addKey(value); counter.increment(); } prog.endStep(Phase.LOADING_FSIMAGE, step); } }
ImageElement.NUM_DELEGATION_KEYS, numDKeys); for(int i =0; i < numDKeys; i++) { DelegationKey key = new DelegationKey(); key.readFields(in); v.visit(ImageElement.DELEGATION_KEY, key.toString());
@Override void readFields(DataInputStream in, int logVersion) throws IOException { this.key = new DelegationKey(); this.key.readFields(in); }
@Override void readFields(DataInputStream in, int logVersion) throws IOException { this.key = new DelegationKey(); this.key.readFields(in); }
private void processKeyAddOrUpdate(byte[] data) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); DelegationKey key = new DelegationKey(); key.readFields(din); synchronized (this) { allKeys.put(key.getKeyId(), key); } }
private static void loadTokenMasterKeyData(TimelineServiceState state, byte[] keyData) throws IOException { DelegationKey key = new DelegationKey(); DataInputStream in = new DataInputStream(new ByteArrayInputStream(keyData)); try { key.readFields(in); } finally { IOUtils.cleanup(LOG, in); } state.tokenMasterKeyState.add(key); }
private DelegationKey loadDelegationKey(byte[] data) throws IOException { DelegationKey key = new DelegationKey(); DataInputStream in = new DataInputStream(new ByteArrayInputStream(data)); try { key.readFields(in); } finally { IOUtils.cleanup(LOG, in); } return key; }
private void processKeyAddOrUpdate(byte[] data) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); DelegationKey key = new DelegationKey(); key.readFields(din); synchronized (this) { allKeys.put(key.getKeyId(), key); } }
private void loadTokenMasterKey(HistoryServerState state, byte[] data) throws IOException { DelegationKey key = new DelegationKey(); DataInputStream in = new DataInputStream(new ByteArrayInputStream(data)); try { key.readFields(in); } finally { IOUtils.cleanup(LOG, in); } state.tokenMasterKeyState.add(key); }
private void processKeyAddOrUpdate(byte[] data) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); DelegationKey key = new DelegationKey(); key.readFields(din); synchronized (this) { allKeys.put(key.getKeyId(), key); } }
private DelegationKey loadDelegationKey(byte[] data) throws IOException { DelegationKey key = new DelegationKey(); DataInputStream in = new DataInputStream(new ByteArrayInputStream(data)); try { key.readFields(in); } finally { IOUtils.cleanup(LOG, in); } return key; }
@Test public void testDelegationKeyEqualAndHash() { DelegationKey key1 = new DelegationKey(1111, 2222, "keyBytes".getBytes()); DelegationKey key2 = new DelegationKey(1111, 2222, "keyBytes".getBytes()); DelegationKey key3 = new DelegationKey(3333, 2222, "keyBytes".getBytes()); Assert.assertEquals(key1, key2); Assert.assertFalse(key2.equals(key3)); } }