/** * Convenience method for reading a token storage file and loading its Tokens. * @param filename * @param conf * @throws IOException */ public static Credentials readTokenStorageFile(File filename, Configuration conf) throws IOException { DataInputStream in = null; Credentials credentials = new Credentials(); try { in = new DataInputStream(new BufferedInputStream( new FileInputStream(filename))); credentials.readTokenStorageStream(in); return credentials; } catch(IOException ioe) { throw new IOException("Exception reading " + filename, ioe); } finally { IOUtils.cleanupWithLogger(LOG, in); } }
/** * Convenience method for reading a token storage file and loading its Tokens. * @param filename * @param conf * @throws IOException */ public static Credentials readTokenStorageFile(Path filename, Configuration conf) throws IOException { FSDataInputStream in = null; Credentials credentials = new Credentials(); try { in = filename.getFileSystem(conf).open(filename); credentials.readTokenStorageStream(in); in.close(); return credentials; } catch(IOException ioe) { throw IOUtils.wrapException(filename.toString(), "Credentials" + ".readTokenStorageFile", ioe); } finally { IOUtils.cleanupWithLogger(LOG, in); } }
/** * transform a byte of crendetials to a hadoop Credentials object. * @param binaryCredentials credentials in byte format as they would * usually be when received from protobuffers * @return a hadoop Credentials object */ public static Credentials credentialsFromByteArray(byte[] binaryCredentials) throws IOException { Credentials credentials = new Credentials(); DataInputBuffer dib = new DataInputBuffer(); dib.reset(binaryCredentials, binaryCredentials.length); credentials.readTokenStorageStream(dib); return credentials; } }
/** * Read the token aliases and {@link Credentials} from a Hadoop FileSystem. * @param file path of the file to be read * @param conf a Hadoop {@link} Configuration for the Hadoop FileSystem * @throws IOException if file cannot be read */ public void read(String file, Configuration conf) throws IOException { Path inFile = new Path(file); try (FSDataInputStream fis = inFile.getFileSystem(conf).open(inFile)) { tokenAliases.addAll(Arrays.asList(WritableUtils.readStringArray(fis))); credentials.readTokenStorageStream(fis); } }
private static Credentials readCredentials(Location location) throws IOException { Credentials credentials = new Credentials(); try (DataInputStream input = new DataInputStream(new BufferedInputStream(location.getInputStream()))) { credentials.readTokenStorageStream(input); } LOG.debug("Read credentials from {}", location); return credentials; } }
private static void loadSecureStore() throws IOException { if (!UserGroupInformation.isSecurityEnabled()) { return; } File file = new File(Constants.Files.CREDENTIALS); if (file.exists()) { Credentials credentials = new Credentials(); try (DataInputStream input = new DataInputStream(new FileInputStream(file))) { credentials.readTokenStorageStream(input); } UserGroupInformation.getCurrentUser().addCredentials(credentials); LOG.info("Secure store updated from {}", file); } }
private static void loadSecureStore() throws IOException { if (!UserGroupInformation.isSecurityEnabled()) { return; } File file = new File(Constants.Files.CREDENTIALS); if (file.exists()) { Credentials credentials = new Credentials(); try (DataInputStream input = new DataInputStream(new FileInputStream(file))) { credentials.readTokenStorageStream(input); } UserGroupInformation.getCurrentUser().addCredentials(credentials); LOG.info("Secure store updated from {}", file); } }
/** * Decodes {@link Credentials} from the given buffer. * If the buffer is null or empty, it returns an empty Credentials. */ public static Credentials decodeCredentials(ByteBuffer buffer) throws IOException { Credentials credentials = new Credentials(); if (buffer != null && buffer.hasRemaining()) { DataInputByteBuffer in = new DataInputByteBuffer(); in.reset(buffer); credentials.readTokenStorageStream(in); } return credentials; }
/** * Decodes {@link Credentials} from the given buffer. * If the buffer is null or empty, it returns an empty Credentials. */ public static Credentials decodeCredentials(ByteBuffer buffer) throws IOException { Credentials credentials = new Credentials(); if (buffer != null && buffer.hasRemaining()) { DataInputByteBuffer in = new DataInputByteBuffer(); in.reset(buffer); credentials.readTokenStorageStream(in); } return credentials; }
/** * Add serialized token to teh credentials. * @param tokens ByteBuffer containing token. */ @Override public void addTokens(final byte[] tokens) { try (final DataInputBuffer buf = new DataInputBuffer()) { buf.reset(tokens, tokens.length); final Credentials credentials = new Credentials(); credentials.readTokenStorageStream(buf); final UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); ugi.addCredentials(credentials); LOG.log(Level.FINEST, "Added {0} tokens for user {1}", new Object[] {credentials.numberOfTokens(), ugi}); } catch (final IOException ex) { LOG.log(Level.SEVERE, "Could not access tokens in user credentials.", ex); throw new RuntimeException(ex); } }
private static Credentials convertCredentialsFromByteBuffer( ByteBuffer appAttemptTokens) { DataInputByteBuffer dibb = new DataInputByteBuffer(); try { Credentials credentials = null; if (appAttemptTokens != null) { credentials = new Credentials(); appAttemptTokens.rewind(); dibb.reset(appAttemptTokens); credentials.readTokenStorageStream(dibb); } return credentials; } catch (IOException e) { LOG.error("Failed to convert Credentials from ByteBuffer."); assert false; return null; } finally { IOUtils.closeStream(dibb); } }
protected Credentials parseCredentials( ApplicationSubmissionContext application) throws IOException { Credentials credentials = new Credentials(); DataInputByteBuffer dibb = new DataInputByteBuffer(); ByteBuffer tokens = application.getAMContainerSpec().getTokens(); if (tokens != null) { dibb.reset(tokens); credentials.readTokenStorageStream(dibb); tokens.rewind(); } return credentials; }
protected Credentials parseCredentials( ApplicationSubmissionContext application) throws IOException { Credentials credentials = new Credentials(); DataInputByteBuffer dibb = new DataInputByteBuffer(); ByteBuffer tokens = application.getAMContainerSpec().getTokens(); if (tokens != null) { dibb.reset(tokens); credentials.readTokenStorageStream(dibb); tokens.rewind(); } return credentials; }
protected Credentials parseCredentials() throws IOException { Credentials credentials = new Credentials(); DataInputByteBuffer dibb = new DataInputByteBuffer(); ByteBuffer tokens = submissionContext.getAMContainerSpec().getTokens(); if (tokens != null) { dibb.reset(tokens); credentials.readTokenStorageStream(dibb); tokens.rewind(); } return credentials; } }
protected Credentials parseCredentials() throws IOException { Credentials credentials = new Credentials(); DataInputByteBuffer dibb = new DataInputByteBuffer(); ByteBuffer tokens = submissionContext.getAMContainerSpec().getTokens(); if (tokens != null) { dibb.reset(tokens); credentials.readTokenStorageStream(dibb); tokens.rewind(); } return credentials; } }
public static Credentials parseCredentialsBytes(byte[] credentialsBytes) throws IOException { Credentials credentials = new Credentials(); DataInputBuffer dib = new DataInputBuffer(); try { byte[] tokenBytes = credentialsBytes; dib.reset(tokenBytes, tokenBytes.length); credentials.readTokenStorageStream(dib); return credentials; } finally { dib.close(); } }
private Credentials parseCredentials(ContainerLaunchContext launchContext) throws IOException { Credentials credentials = new Credentials(); // //////////// Parse credentials ByteBuffer tokens = launchContext.getTokens(); if (tokens != null) { DataInputByteBuffer buf = new DataInputByteBuffer(); tokens.rewind(); buf.reset(tokens); credentials.readTokenStorageStream(buf); if (LOG.isDebugEnabled()) { for (Token<? extends TokenIdentifier> tk : credentials.getAllTokens()) { LOG.debug(tk.getService() + " = " + tk.toString()); } } } // //////////// End of parsing credentials return credentials; }
public static Credentials convertByteStringToCredentials(ByteString byteString) { if (byteString == null) { return null; } DataInputByteBuffer dib = new DataInputByteBuffer(); dib.reset(byteString.asReadOnlyByteBuffer()); Credentials credentials = new Credentials(); try { credentials.readTokenStorageStream(dib); return credentials; } catch (IOException e) { throw new TezUncheckedException("Failed to deserialize Credentials", e); } }
public Credentials getContainerCredentials() throws IOException { Credentials credentials = new Credentials(); DataInputByteBuffer buf = new DataInputByteBuffer(); containerTokens.rewind(); buf.reset(containerTokens); credentials.readTokenStorageStream(buf); return credentials; }
public Credentials getContainerCredentials() throws IOException { Credentials credentials = new Credentials(); DataInputByteBuffer buf = new DataInputByteBuffer(); containerTokens.rewind(); buf.reset(containerTokens); credentials.readTokenStorageStream(buf); return credentials; } }