Package org.apache.hadoop.security

Examples of org.apache.hadoop.security.TokenStorage


    String nnAddress =
      InetAddress.getByName(dfs.getUri().getHost()).getHostAddress()
      + ":" + dfs.getUri().getPort();
    token.setService(new Text(nnAddress));
   
    TokenStorage ts = new TokenStorage();
    ts.addToken(new Text(shortName), token);
    ts.write(out);
  }
View Full Code Here


          nnAddr + DelegationTokenServlet.PATH_SPEC + ugiPostfix);
      URL remoteURL = new URL(nnAddr + DelegationTokenServlet.PATH_SPEC + ugiPostfix);
      URLConnection connection = remoteURL.openConnection();
     
      InputStream in = connection.getInputStream();
      TokenStorage ts = new TokenStorage();
      dis = new DataInputStream(in);
      ts.readFields(dis);
      file = new DataOutputStream(new FileOutputStream(filename));
      ts.write(file);
      file.flush();
      System.out.println("Successfully wrote token of " + file.size()
          + " bytes  to " + filename);
    } catch (Exception e) {
      throw new IOException("Unable to obtain remote token", e);
View Full Code Here

    getLocalizer().initializeJobDirs(userName, jobId);
    // save local copy of JobToken file
    String localJobTokenFile = localizeJobTokenFile(t.getUser(), jobId);
    rjob.ugi = UserGroupInformation.createRemoteUser(t.getUser());

    TokenStorage ts = TokenCache.loadTokens(localJobTokenFile, fConf);
    Token<JobTokenIdentifier> jt = TokenCache.getJobToken(ts);
    if (jt != null) { //could be null in the case of some unit tests
      getJobTokenSecretManager().addTokenForJob(jobId.toString(), jt);
    }
    for (Token<? extends TokenIdentifier> token : ts.getAllTokens()) {
      rjob.ugi.addToken(token);
    }
    // Download the job.xml for this job from the system FS
    Path localJobFile =
        localizeJobConfFile(new Path(t.getJobFile()), userName, jobId);
View Full Code Here

        firstTaskid.getTaskType() == TaskType.MAP,jvmIdInt);
   
    //load token cache storage
    String jobTokenFile =
      System.getenv().get(UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION);
    TokenStorage ts =
      TokenCache.loadTaskTokenStorage(jobTokenFile, defaultConf);
    LOG.debug("loading token. # keys =" +ts.numberOfSecretKeys() +
        "; from file=" + jobTokenFile);
    Token<JobTokenIdentifier> jt = TokenCache.getJobToken(ts);
    jt.setService(new Text(address.getAddress().getHostAddress() + ":"
        + address.getPort()));
    UserGroupInformation current = UserGroupInformation.getCurrentUser();
View Full Code Here

          Token<DelegationTokenIdentifier> token =
            nn.getDelegationToken(new Text(req.getUserPrincipal().getName()));
          String s = nn.rpcAddress.getAddress().getHostAddress()
                     + ":" + nn.rpcAddress.getPort();
          token.setService(new Text(s));
          TokenStorage ts = new TokenStorage();
          ts.addToken(new Text(ugi.getShortUserName()), token);
          ts.write(dosFinal);
          dosFinal.close();
          return null;
        }
      });
View Full Code Here

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    out = new DataOutputStream(baos);
    new DelegationTokenFetcher(dfs, out, ugi).go();
   
    // now read the data back in and verify correct values
    TokenStorage ts = new TokenStorage();
    DataInputStream dis =
      new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
    ts.readFields(dis);
    Token<? extends TokenIdentifier> newToken = ts.getToken(new Text(SHORT_NAME));
   
    assertEquals("Should only be one token in storage", ts.numberOfTokens(), 1);
    assertEquals("Service value should have survived",
        "127.0.0.1:2005", newToken.getService().toString());
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public <T extends TokenIdentifier> void testReadWriteStorage()
  throws IOException, NoSuchAlgorithmException{
    // create tokenStorage Object
    TokenStorage ts = new TokenStorage();
   
    Token<T> token1 = new Token();
    Token<T> token2 = new Token();
    Text service1 = new Text("service1");
    Text service2 = new Text("service2");
    Collection<Text> services = new ArrayList<Text>();
   
    services.add(service1);
    services.add(service2);
   
    token1.setService(service1);
    token2.setService(service2);
    ts.addToken(new Text("sometoken1"), token1);
    ts.addToken(new Text("sometoken2"), token2);
   
    // create keys and put it in
    final KeyGenerator kg = KeyGenerator.getInstance(DEFAULT_HMAC_ALGORITHM);
    String alias = "alias";
    Map<Text, byte[]> m = new HashMap<Text, byte[]>(10);
    for(int i=0; i<10; i++) {
      Key key = kg.generateKey();
      m.put(new Text(alias+i), key.getEncoded());
      ts.addSecretKey(new Text(alias+i), key.getEncoded());
    }
  
    // create file to store
    File tmpFileName = new File(tmpDir, "tokenStorageTest");
    DataOutputStream dos =
      new DataOutputStream(new FileOutputStream(tmpFileName));
    ts.write(dos);
    dos.close();
   
    // open and read it back
    DataInputStream dis =
      new DataInputStream(new FileInputStream(tmpFileName));   
    ts = new TokenStorage();
    ts.readFields(dis);
    dis.close();
   
    // get the tokens and compare the services
    Collection<Token<? extends TokenIdentifier>> list = ts.getAllTokens();
    assertEquals("getAllTokens should return collection of size 2",
        list.size(), 2);
    boolean foundFirst = false;
    boolean foundSecond = false;
    for (Token<? extends TokenIdentifier> token : list) {
      if (token.getService().equals(service1)) {
        foundFirst = true;
      }
      if (token.getService().equals(service2)) {
        foundSecond = true;
      }
    }
    assertTrue("Tokens for services service1 and service2 must be present",
        foundFirst && foundSecond);
    // compare secret keys
    int mapLen = m.size();
    assertEquals("wrong number of keys in the Storage",
        mapLen, ts.numberOfSecretKeys());
    for(Text a : m.keySet()) {
      byte [] kTS = ts.getSecretKey(a);
      byte [] kLocal = m.get(a);
      assertTrue("keys don't match for " + a,
          WritableComparator.compareBytes(kTS, 0, kTS.length, kLocal,
              0, kLocal.length)==0);
    }
View Full Code Here

        jobtracker.getJobTokenSecretManager());
    token.setService(identifier.getJobId());
   
    // add this token to the tokenStorage
    if(tokenStorage == null)
      tokenStorage = new TokenStorage();
   
    TokenCache.setJobToken(token, tokenStorage);
   
    // write TokenStorage out
    tokenStorage.write(os);
View Full Code Here

   * @return TokenStore object
   */
  @InterfaceAudience.Private
  public static TokenStorage getTokenStorage() {
    if(tokenStorage==null)
      tokenStorage = new TokenStorage();
   
    return tokenStorage;
  }
View Full Code Here

  throws IOException {
    Path localJobTokenFile = new Path (jobTokenFile);
    FileSystem localFS = FileSystem.getLocal(conf);
    FSDataInputStream in = localFS.open(localJobTokenFile);
   
    TokenStorage ts = new TokenStorage();
    ts.readFields(in);

    if(LOG.isDebugEnabled()) {
      LOG.debug("Task: Loaded jobTokenFile from: "+localJobTokenFile.toUri().getPath()
        +"; num of sec keys  = " + ts.numberOfSecretKeys());
    }
    in.close();
    return ts;
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.security.TokenStorage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.