org.apache.hadoop.security.token.Token.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中org.apache.hadoop.security.token.Token.<init>()方法的一些代码示例,展示了Token.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Token.<init>()方法的具体详情如下:
包路径:org.apache.hadoop.security.token.Token
类名称:Token
方法名:<init>

Token.<init>介绍

[英]Default constructor
[中]默认构造函数

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

public Token<T> copyToken() {
 return new Token<T>(this);
}

代码示例来源:origin: apache/hive

public synchronized void cancelDelegationToken(String tokenStrForm) throws IOException {
 Token<DelegationTokenIdentifier> t= new Token<>();
 t.decodeFromUrlString(tokenStrForm);
 String user = UserGroupInformation.getCurrentUser().getUserName();
 cancelToken(t, user);
}

代码示例来源:origin: apache/hive

public synchronized String getDelegationToken(final String ownerStr, final String renewer) throws IOException {
 if (ownerStr == null) {
  throw new RuntimeException("Delegation token owner is null");
 }
 Text owner = new Text(ownerStr);
 Text realUser = null;
 UserGroupInformation currentUgi = UserGroupInformation.getCurrentUser();
 if (currentUgi.getUserName() != null) {
  realUser = new Text(currentUgi.getUserName());
 }
 DelegationTokenIdentifier ident =
  new DelegationTokenIdentifier(owner, new Text(renewer), realUser);
 Token<DelegationTokenIdentifier> t = new Token<>(
   ident, this);
 return t.encodeToUrlString();
}

代码示例来源:origin: apache/hive

public synchronized long renewDelegationToken(String tokenStrForm) throws IOException {
 Token<DelegationTokenIdentifier> t= new Token<>();
 t.decodeFromUrlString(tokenStrForm);
 //when a token is created the renewer of the token is stored
 //as shortName in AbstractDelegationTokenIdentifier.setRenewer()
 //this seems like an inconsistency because while cancelling the token
 //it uses the shortname to compare the renewer while it does not use
 //shortname during token renewal. Use getShortUserName() until its fixed
 //in HADOOP-15068
 String user = UserGroupInformation.getCurrentUser().getShortUserName();
 return renewToken(t, user);
}

代码示例来源:origin: apache/hive

public static Token<? extends AbstractDelegationTokenIdentifier> extractThriftToken(
 String tokenStrForm, String tokenSignature) throws MetaException,
 TException, IOException {
 // LOG.info("extractThriftToken("+tokenStrForm+","+tokenSignature+")");
 Token<? extends AbstractDelegationTokenIdentifier> t = new Token<DelegationTokenIdentifier>();
 t.decodeFromUrlString(tokenStrForm);
 t.setService(new Text(tokenSignature));
 // LOG.info("returning "+t);
 return t;
}

代码示例来源:origin: apache/hive

/**
 * Create a new token using the given string and service
 * @param tokenStr
 * @param tokenService
 * @return
 * @throws IOException
 */
private static Token<DelegationTokenIdentifier> createToken(String tokenStr, String tokenService)
  throws IOException {
 Token<DelegationTokenIdentifier> delegationToken = new Token<>();
 delegationToken.decodeFromUrlString(tokenStr);
 delegationToken.setService(new Text(tokenService));
 return delegationToken;
}

代码示例来源:origin: apache/hive

/**
 * Create a new token using the given string and service
 * 
 * @param tokenStr
 * @param tokenService
 * @return
 * @throws IOException
 */
private static Token<DelegationTokenIdentifier> createToken(String tokenStr, String tokenService)
  throws IOException {
 Token<DelegationTokenIdentifier> delegationToken = new Token<DelegationTokenIdentifier>();
 delegationToken.decodeFromUrlString(tokenStr);
 delegationToken.setService(new Text(tokenService));
 return delegationToken;
}

代码示例来源:origin: apache/hive

public Token<JobTokenIdentifier> getPluginToken() {
 if (this.token != null) return token;
 String tokenString = getProperties().get(TezAmRegistryImpl.AM_PLUGIN_TOKEN);
 if (tokenString == null || tokenString.isEmpty()) return null;
 byte[] tokenBytes = Base64.decodeBase64(tokenString);
 Token<JobTokenIdentifier> token = new Token<>();
 try {
  token.readFields(ByteStreams.newDataInput(tokenBytes));
 } catch (IOException e) {
  LOG.error("Couldn't read the plugin token from [" + tokenString + "]", e);
  return null;
 }
 this.token = token;
 return token;
}

代码示例来源:origin: apache/hive

/** Verifies the token available as serialized bytes. */
 public void verifyToken(byte[] tokenBytes) throws IOException {
  if (!UserGroupInformation.isSecurityEnabled()) return;
  if (tokenBytes == null) throw new SecurityException("Token required for authentication");
  Token<LlapTokenIdentifier> token = new Token<>();
  token.readFields(new DataInputStream(new ByteArrayInputStream(tokenBytes)));
  verifyToken(token.decodeIdentifier(), token.getPassword());
 }
}

代码示例来源:origin: apache/hive

public String getUserFromToken(String tokenStr) throws IOException {
  Token<DelegationTokenIdentifier> delegationToken = new Token<>();
  delegationToken.decodeFromUrlString(tokenStr);

  ByteArrayInputStream buf = new ByteArrayInputStream(delegationToken.getIdentifier());
  DataInputStream in = new DataInputStream(buf);
  DelegationTokenIdentifier id = createIdentifier();
  id.readFields(in);
  return id.getUser().getShortUserName();
 }
}

代码示例来源:origin: apache/hbase

/**
  * Converts a protobuf Token message back into a Token instance.
  *
  * @param proto the protobuf Token message
  * @return the Token instance
  */
 public static Token<AuthenticationTokenIdentifier> toToken(AuthenticationProtos.Token proto) {
  return new Token<>(
    proto.hasIdentifier() ? proto.getIdentifier().toByteArray() : null,
    proto.hasPassword() ? proto.getPassword().toByteArray() : null,
    AuthenticationTokenIdentifier.AUTH_TOKEN_TYPE,
    proto.hasService() ? new Text(proto.getService().toStringUtf8()) : null);
 }
}

代码示例来源:origin: apache/hive

static Token<JobTokenIdentifier> deserializeServiceData(ByteBuffer secret) throws IOException {
 DataInputByteBuffer in = new DataInputByteBuffer();
 in.reset(secret);
 Token<JobTokenIdentifier> jt = new Token<JobTokenIdentifier>();
 jt.readFields(in);
 return jt;
}

代码示例来源:origin: apache/hbase

public Token<AuthenticationTokenIdentifier> generateToken(String username) {
 AuthenticationTokenIdentifier ident =
   new AuthenticationTokenIdentifier(username);
 Token<AuthenticationTokenIdentifier> token = new Token<>(ident, this);
 if (clusterId.hasId()) {
  token.setService(new Text(clusterId.getId()));
 }
 return token;
}

代码示例来源:origin: apache/hive

private String addHMSToken(Job job, String user) throws IOException, InterruptedException,
    TException {
 if(!secureMetastoreAccess) {
  return null;
 }
 Token<org.apache.hadoop.hive.metastore.security.DelegationTokenIdentifier> hiveToken =
     new Token<org.apache.hadoop.hive.metastore.security.DelegationTokenIdentifier>();
 String metastoreTokenStrForm = buildHcatDelegationToken(user);
 hiveToken.decodeFromUrlString(metastoreTokenStrForm);
 job.getCredentials().addToken(new
     Text(SecureProxySupport.HCAT_SERVICE), hiveToken);
 return metastoreTokenStrForm;
}
private String buildHcatDelegationToken(String user) throws IOException, InterruptedException,

代码示例来源:origin: apache/storm

private Token<DelegationTokenIdentifier> getDelegationToken(HiveConf hcatConf,
                              String metaStoreServicePrincipal,
                              String topologySubmitterUser) throws IOException {
  LOG.info("Creating delegation tokens for principal={}", metaStoreServicePrincipal);
  HCatClient hcatClient = null;
  try {
    hcatClient = HCatClient.create(hcatConf);
    String delegationToken = hcatClient.getDelegationToken(topologySubmitterUser, metaStoreServicePrincipal);
    Token<DelegationTokenIdentifier> delegationTokenId = new Token<DelegationTokenIdentifier>();
    delegationTokenId.decodeFromUrlString(delegationToken);
    DelegationTokenIdentifier d = new DelegationTokenIdentifier();
    d.readFields(new DataInputStream(new ByteArrayInputStream(
        delegationTokenId.getIdentifier())));
    LOG.info("Created Delegation Token for : " + d.getUser());
    return delegationTokenId;
  } finally {
    if (hcatClient != null)
      hcatClient.close();
  }
}

代码示例来源:origin: apache/hive

private static Token<JobTokenIdentifier> createJobToken(ApplicationId applicationId) {
  String tokenIdentifier = applicationId.toString();
  JobTokenIdentifier identifier = new JobTokenIdentifier(new Text(
    tokenIdentifier));
  Token<JobTokenIdentifier> sessionToken = new Token<JobTokenIdentifier>(identifier,
    new JobTokenSecretManager());
  sessionToken.setService(identifier.getJobId());
  return sessionToken;
 }
}

代码示例来源:origin: apache/hive

private static Token<JobTokenIdentifier> createAmsToken(ApplicationId id) {
 if (!UserGroupInformation.isSecurityEnabled()) return null;
 JobTokenIdentifier identifier = new JobTokenIdentifier(new Text(id.toString()));
 JobTokenSecretManager jobTokenManager = new JobTokenSecretManager();
 Token<JobTokenIdentifier> sessionToken = new Token<>(identifier, jobTokenManager);
 sessionToken.setService(identifier.getJobId());
 return sessionToken;
}

代码示例来源:origin: apache/hive

/**
 * Verify token string
 * @param tokenStrForm
 * @return user name
 * @throws IOException
 */
public synchronized String verifyDelegationToken(String tokenStrForm) throws IOException {
 Token<DelegationTokenIdentifier> t = new Token<>();
 t.decodeFromUrlString(tokenStrForm);
 DelegationTokenIdentifier id = getTokenIdentifier(t);
 verifyToken(id, t.getPassword());
 return id.getUser().getShortUserName();
}

代码示例来源:origin: apache/incubator-gobblin

@BeforeClass
public void setUp() throws IOException {
 this.configuration = new Configuration();
 this.fileSystem = FileSystem.getLocal(this.configuration);
 this.tokenFilePath = new Path(HelixUtilsTest.class.getSimpleName(), "token");
 this.token = new Token<>();
 this.token.setKind(new Text("test"));
 this.token.setService(new Text("test"));
}

代码示例来源:origin: apache/hive

private Token<LlapTokenIdentifier> extractToken(ByteString tokenBytes) throws IOException {
 Token<LlapTokenIdentifier> token = new Token<>();
 DataInputByteBuffer in = new DataInputByteBuffer();
 in.reset(tokenBytes.asReadOnlyByteBuffer());
 token.readFields(in);
 return token;
}

相关文章