本文整理了Java中org.apache.hadoop.security.token.Token.setService()
方法的一些代码示例,展示了Token.setService()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Token.setService()
方法的具体详情如下:
包路径:org.apache.hadoop.security.token.Token
类名称:Token
方法名:setService
[英]Set the service on which the token is supposed to be used
[中]设置应该使用令牌的服务
代码示例来源:origin: org.apache.hadoop/hadoop-common
@Override
public Token<?> call(KMSClientProvider provider) throws IOException {
Token<?> token = provider.getDelegationToken(renewer);
// override sub-providers service with our own so it can be used
// across all providers.
token.setService(dtService);
LOG.debug("New token service set. Token: ({})", token);
return token;
}
}, nextIdx(), false);
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Set the given token's service to the format expected by the RPC client
* @param token a delegation token
* @param addr the socket for the rpc connection
*/
public static void setTokenService(Token<?> token, InetSocketAddress addr) {
Text service = buildTokenService(addr);
if (token != null) {
token.setService(service);
if (LOG.isDebugEnabled()) {
LOG.debug("Acquired token "+token); // Token#toString() prints service
}
} else {
LOG.warn("Failed to get token for service "+service);
}
}
代码示例来源: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
/**
* 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/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 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: org.apache.hadoop/hadoop-common
token.setService(dtService);
LOG.info("New token created: ({})", token);
} else {
代码示例来源:origin: apache/hive
/**
* Create the delegation token.
*/
public Path open(String user, Configuration conf)
throws IOException, InterruptedException {
close();
if (isEnabled) {
this.user = user;
File t = File.createTempFile("templeton", null);
tokenPath = new Path(t.toURI());
Token[] fsToken = getFSDelegationToken(user, conf);
String hcatTokenStr;
try {
hcatTokenStr = buildHcatDelegationToken(user);
} catch (Exception e) {
throw new IOException(e);
}
if(hcatTokenStr == null) {
LOG.error("open(" + user + ") token=null");
}
Token<?> msToken = new Token();
msToken.decodeFromUrlString(hcatTokenStr);
msToken.setService(new Text(HCAT_SERVICE));
writeProxyDelegationTokens(fsToken, msToken, conf, user, tokenPath);
}
return tokenPath;
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
@SuppressWarnings("unchecked")
public Token<? extends AbstractDelegationTokenIdentifier> createToken(
UserGroupInformation ugi, String renewer, String service) {
LOG.debug("Creating token with ugi:{}, renewer:{}, service:{}.",
ugi, renewer, service !=null ? service : "");
renewer = (renewer == null) ? ugi.getShortUserName() : renewer;
String user = ugi.getUserName();
Text owner = new Text(user);
Text realUser = null;
if (ugi.getRealUser() != null) {
realUser = new Text(ugi.getRealUser().getUserName());
}
AbstractDelegationTokenIdentifier tokenIdentifier =
(AbstractDelegationTokenIdentifier) secretManager.createIdentifier();
tokenIdentifier.setOwner(owner);
tokenIdentifier.setRenewer(new Text(renewer));
tokenIdentifier.setRealUser(realUser);
Token token = new Token(tokenIdentifier, secretManager);
if (service != null) {
token.setService(new Text(service));
}
return token;
}
代码示例来源: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/incubator-gobblin
/**
* function to fetch hcat token as per the specified hive configuration and then store the token
* in to the credential store specified .
*
* @param userToProxy String value indicating the name of the user the token will be fetched for.
* @param hiveConf the configuration based off which the hive client will be initialized.
*/
private static Token<DelegationTokenIdentifier> fetchHcatToken(final String userToProxy, final HiveConf hiveConf,
final String tokenSignatureOverwrite, final IMetaStoreClient hiveClient)
throws IOException, TException, InterruptedException {
LOG.info(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL.varname + ": " + hiveConf.get(
HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL.varname));
LOG.info(HiveConf.ConfVars.METASTORE_KERBEROS_PRINCIPAL.varname + ": " + hiveConf.get(
HiveConf.ConfVars.METASTORE_KERBEROS_PRINCIPAL.varname));
final Token<DelegationTokenIdentifier> hcatToken = new Token<>();
hcatToken.decodeFromUrlString(
hiveClient.getDelegationToken(userToProxy, UserGroupInformation.getLoginUser().getShortUserName()));
// overwrite the value of the service property of the token if the signature
// override is specified.
// If the service field is set, do not overwrite that
if (hcatToken.getService().getLength() <= 0 && tokenSignatureOverwrite != null
&& tokenSignatureOverwrite.trim().length() > 0) {
hcatToken.setService(new Text(tokenSignatureOverwrite.trim().toLowerCase()));
LOG.info(HIVE_TOKEN_SIGNATURE_KEY + ":" + tokenSignatureOverwrite);
}
LOG.info("Created hive metastore token for user:" + userToProxy + " with kind[" + hcatToken.getKind() + "]"
+ " and service[" + hcatToken.getService() + "]");
return hcatToken;
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
aliasedToken.setService(alias);
creds.addToken(alias, aliasedToken);
LOG.info("Add token with service " + alias);
代码示例来源:origin: org.apache.hadoop/hadoop-common
/** Alias a token from a file and save back to file in the local filesystem.
* @param tokenFile a local File object to hold the input and output.
* @param fileFormat a string equal to FORMAT_PB or FORMAT_JAVA, for output
* @param alias overwrite service field of fetched token with this text.
* @param service only apply alias to tokens matching this service text.
* @param conf Configuration object passed along.
* @throws IOException
*/
public static void aliasTokenFile(File tokenFile, String fileFormat,
Text alias, Text service, Configuration conf) throws Exception {
Credentials newCreds = new Credentials();
Credentials creds = Credentials.readTokenStorageFile(tokenFile, conf);
for (Token<?> token : creds.getAllTokens()) {
newCreds.addToken(token.getService(), token);
if (token.getService().equals(service)) {
Token<?> aliasedToken = token.copyToken();
aliasedToken.setService(alias);
newCreds.addToken(alias, aliasedToken);
}
}
doFormattedWrite(tokenFile, fileFormat, newCreds, conf);
}
代码示例来源:origin: apache/incubator-gobblin
this.token.setService(new Text("test"));
Mockito.<Token<?>>when(this.localFs.getDelegationToken(UserGroupInformation.getLoginUser().getShortUserName()))
.thenReturn(this.token);
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
Token<DelegationTokenIdentifier> delegationToken() throws IOException {
String delegation = param(DelegationParam.NAME);
final Token<DelegationTokenIdentifier> token = new
Token<DelegationTokenIdentifier>();
token.decodeFromUrlString(delegation);
URI nnUri = URI.create(HDFS_URI_SCHEME + "://" + namenodeId());
boolean isLogical = HAUtilClient.isLogicalUri(conf, nnUri);
if (isLogical) {
token.setService(
HAUtilClient.buildTokenServiceForLogicalUri(nnUri, HDFS_URI_SCHEME));
} else {
token.setService(SecurityUtil.buildTokenService(nnUri));
}
return token;
}
代码示例来源:origin: org.apache.hadoop/hadoop-mapreduce-client-core
@Override
public Token<?> answer(InvocationOnMock invocation) throws Throwable {
Token<?> token = new Token<TokenIdentifier>();
token.setService(new Text(service));
// use unique value so when we restore from token storage, we can
// tell if it's really the same token
token.setKind(new Text("token" + unique++));
return token;
}
});
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
final String setKind = tokenKind.getValue();
if (setServiceName != null) {
token.setService(new Text(setServiceName));
内容来源于网络,如有侵权,请联系作者删除!