@Test public void testTwoEncodedCredentialsToBase64Str() throws IOException { Credentials cred = new Credentials(); String tokenName1 = "testToken1"; String tokenName2 = "testToken2"; addTokenToCredential(cred, tokenName1); addTokenToCredential(cred, tokenName2); String encodedStr = TokenFetcherService.encodeCredentialsToBase64(cred); Credentials decodedCred = decodeStrToCredentials(encodedStr); Assert.assertEquals(cred.getToken(new Text(tokenName1)).getKind().toString(), decodedCred.getToken(new Text(tokenName1)).getKind().toString()); Assert.assertEquals(cred.getToken(new Text(tokenName1)).getIdentifier(), decodedCred.getToken(new Text(tokenName1)).getIdentifier()); Assert.assertEquals(cred.getToken(new Text(tokenName1)).getService().toString(), decodedCred.getToken(new Text(tokenName1)).getService().toString()); Assert.assertEquals(cred.getToken(new Text(tokenName2)).getKind().toString(), decodedCred.getToken(new Text(tokenName2)).getKind().toString()); Assert.assertEquals(cred.getToken(new Text(tokenName2)).getIdentifier(), decodedCred.getToken(new Text(tokenName2)).getIdentifier()); Assert.assertEquals(cred.getToken(new Text(tokenName2)).getService().toString(), decodedCred.getToken(new Text(tokenName2)).getService().toString()); Assert.assertEquals(cred.numberOfTokens(), decodedCred.numberOfTokens()); }
static String encodeCredentialsToBase64(Credentials cred) { ByteArrayOutputStream baos = null; DataOutputStream dos = null; try { baos = new ByteArrayOutputStream(); dos = new DataOutputStream(baos); cred.writeTokenStorageToStream(dos); cred.getAllTokens().forEach(x -> LOG.info(x.toString())); } catch (IOException ioe) { throw new TokenServiceException(ioe.toString(), ErrorCode.CREDENTIAL_ENCODING_EXCEPTION); } finally { if (dos != null) { try { dos.close(); } catch (final Throwable t) { LOG.error("encountered exception while closing DataOutputStream", t); } } if (baos != null) { try { baos.close(); } catch (final Throwable t) { LOG.error("encountered exception while closing ByteArrayOutputStream", t); } } } return Base64.getEncoder().encodeToString(baos.toByteArray()); }
TokenFetcherService { static String encodeCredentialsToBase64(Credentials cred) { ByteArrayOutputStream baos = null; DataOutputStream dos = null; try { baos = new ByteArrayOutputStream(); dos = new DataOutputStream(baos); cred.writeTokenStorageToStream(dos); cred.getAllTokens().forEach(x -> LOG.info(x.toString())); } catch (IOException ioe) { throw new TokenServiceException(ioe.toString(), ErrorCode.CREDENTIAL_ENCODING_EXCEPTION); } finally { if (dos != null) { try { dos.close(); } catch (final Throwable t) { LOG.error("encountered exception while closing DataOutputStream", t); } } if (baos != null) { try { baos.close(); } catch (final Throwable t) { LOG.error("encountered exception while closing ByteArrayOutputStream", t); } } } return Base64.getEncoder().encodeToString(baos.toByteArray()); } }
TokenFetcherService { static String encodeCredentialsToBase64(Credentials cred) { ByteArrayOutputStream baos = null; DataOutputStream dos = null; try { baos = new ByteArrayOutputStream(); dos = new DataOutputStream(baos); cred.writeTokenStorageToStream(dos); cred.getAllTokens().forEach(x -> LOG.info(x.toString())); } catch (IOException ioe) { throw new TokenServiceException(ioe.toString(), ErrorCode.CREDENTIAL_ENCODING_EXCEPTION); } finally { if (dos != null) { try { dos.close(); } catch (final Throwable t) { LOG.error("encountered exception while closing DataOutputStream", t); } } if (baos != null) { try { baos.close(); } catch (final Throwable t) { LOG.error("encountered exception while closing ByteArrayOutputStream", t); } } } return Base64.getEncoder().encodeToString(baos.toByteArray()); } private  TokenFetcherService(final Configuration conf); }
TokenFetcherService { static String encodeCredentialsToBase64(Credentials cred) { ByteArrayOutputStream baos = null; DataOutputStream dos = null; try { baos = new ByteArrayOutputStream(); dos = new DataOutputStream(baos); cred.writeTokenStorageToStream(dos); cred.getAllTokens().forEach(x -> LOG.info(x.toString())); } catch (IOException ioe) { throw new TokenServiceException(ioe.toString(), ErrorCode.CREDENTIAL_ENCODING_EXCEPTION); } finally { if (dos != null) { try { dos.close(); } catch (final Throwable t) { LOG.error("encountered exception while closing DataOutputStream", t); } } if (baos != null) { try { baos.close(); } catch (final Throwable t) { LOG.error("encountered exception while closing ByteArrayOutputStream", t); } } } return Base64.getEncoder().encodeToString(baos.toByteArray()); } private  TokenFetcherService(final Configuration conf); static TokenFetcherService getInstance(Configuration conf); String getDelegationTokens(Map<String, String[]> params); }
TokenFetcherService { static String encodeCredentialsToBase64(Credentials cred) { ByteArrayOutputStream baos = null; DataOutputStream dos = null; try { baos = new ByteArrayOutputStream(); dos = new DataOutputStream(baos); cred.writeTokenStorageToStream(dos); cred.getAllTokens().forEach(x -> LOG.info(x.toString())); } catch (IOException ioe) { throw new TokenServiceException(ioe.toString(), ErrorCode.CREDENTIAL_ENCODING_EXCEPTION); } finally { if (dos != null) { try { dos.close(); } catch (final Throwable t) { LOG.error("encountered exception while closing DataOutputStream", t); } } if (baos != null) { try { baos.close(); } catch (final Throwable t) { LOG.error("encountered exception while closing ByteArrayOutputStream", t); } } } return Base64.getEncoder().encodeToString(baos.toByteArray()); } private  TokenFetcherService(final Configuration conf); static TokenFetcherService getInstance(Configuration conf); String getDelegationTokens(Map<String, String[]> params); static final List<String> SUPPORTED_TOKEN_KINDS; }