List of usage examples for org.apache.hadoop.security Credentials addSecretKey
public void addSecretKey(Text alias, byte[] key)
From source file:org.apache.pig.backend.hadoop.executionengine.tez.util.SecurityHelper.java
License:Apache License
@SuppressWarnings("unchecked") private static void readTokensFromFiles(Configuration conf, Credentials credentials) throws IOException { // add tokens and secrets coming from a token storage file String binaryTokenFilename = conf.get(MRConfiguration.JOB_CREDENTIALS_BINARY); if (binaryTokenFilename != null) { Credentials binary = Credentials.readTokenStorageFile(new Path("file:///" + binaryTokenFilename), conf); credentials.addAll(binary);/*from w w w . j a v a 2 s.c o m*/ } // add secret keys coming from a json file String tokensFileName = conf.get(MRConfiguration.JOB_CREDENTIALS_JSON); if (tokensFileName != null) { LOG.info("loading user's secret keys from " + tokensFileName); String localFileName = new Path(tokensFileName).toUri().getPath(); boolean json_error = false; try { // read JSON ObjectMapper mapper = new ObjectMapper(); Map<String, String> nm = mapper.readValue(new File(localFileName), Map.class); for (Map.Entry<String, String> ent : nm.entrySet()) { credentials.addSecretKey(new Text(ent.getKey()), ent.getValue().getBytes(Charsets.UTF_8)); } } catch (JsonMappingException e) { json_error = true; } catch (JsonParseException e) { json_error = true; } if (json_error) LOG.warn("couldn't parse Token Cache JSON file with user secret keys"); } }
From source file:org.apache.tez.engine.common.security.TokenCache.java
License:Apache License
@InterfaceAudience.Private public static void setShuffleSecretKey(byte[] key, Credentials credentials) { credentials.addSecretKey(SHUFFLE_TOKEN, key); }
From source file:org.springframework.yarn.examples.XdAppmaster.java
License:Apache License
@Override public ContainerLaunchContext preLaunch(ContainerLaunchContext context) { if (log.isDebugEnabled()) { log.debug("preLaunch: " + context); }/*from ww w.j a v a 2 s .c o m*/ AppmasterService service = getAppmasterService(); if (service != null) { int port = service.getPort(); String address = service.getHost(); Map<String, String> env = new HashMap<String, String>(context.getEnvironment()); env.put(YarnSystemConstants.AMSERVICE_PORT, Integer.toString(port)); env.put(YarnSystemConstants.AMSERVICE_HOST, address); env.put(YarnSystemConstants.SYARN_CONTAINER_ID, ConverterUtils.toString(context.getContainerId())); // String xdGroup = getManagedGroups().findGroupNameByMember(ConverterUtils.toString(context.getContainerId())); String xdGroup = getManagedGroups().getGroupByMember(ConverterUtils.toString(context.getContainerId())) .getId(); env.put("syarn.cg.group", xdGroup != null ? xdGroup : ""); context.setEnvironment(env); // testing try { Credentials credentials = new Credentials(); credentials.addSecretKey(new Text(YarnSystemConstants.SYARN_SEC_SESSIONID), sessionId.getBytes()); DataOutputBuffer dob = new DataOutputBuffer(); credentials.writeTokenStorageToStream(dob); ByteBuffer containerToken = ByteBuffer.wrap(dob.getData(), 0, dob.getLength()); context.setContainerTokens(containerToken); } catch (IOException e) { log.error("XXX error setContainerTokens", e); } return context; } else { return context; } }