本文整理了Java中org.apache.hadoop.security.token.Token.decodeFromUrlString()
方法的一些代码示例,展示了Token.decodeFromUrlString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Token.decodeFromUrlString()
方法的具体详情如下:
包路径:org.apache.hadoop.security.token.Token
类名称:Token
方法名:decodeFromUrlString
[英]Decode the given url safe string into this token.
[中]将给定的url安全字符串解码到此令牌中。
代码示例来源: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 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 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/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: org.apache.hadoop/hadoop-common
/**
* Requests a delegation token using the configured <code>Authenticator</code>
* for authentication.
*
* @param url the URL to get the delegation token from. Only HTTP/S URLs are
* supported.
* @param token the authentication token being used for the user where the
* Delegation token will be stored.
* @param renewer the renewer user.
* @param doAsUser the user to do as, which will be the token owner.
* @throws IOException if an IO error occurred.
* @throws AuthenticationException if an authentication exception occurred.
*/
public Token<AbstractDelegationTokenIdentifier> getDelegationToken(URL url,
AuthenticatedURL.Token token, String renewer, String doAsUser)
throws IOException, AuthenticationException {
Map json = doDelegationTokenOperation(url, token,
DelegationTokenOperation.GETDELEGATIONTOKEN, renewer, null, true,
doAsUser);
json = (Map) json.get(DELEGATION_TOKEN_JSON);
String tokenStr = (String) json.get(DELEGATION_TOKEN_URL_STRING_JSON);
Token<AbstractDelegationTokenIdentifier> dToken =
new Token<AbstractDelegationTokenIdentifier>();
dToken.decodeFromUrlString(tokenStr);
InetSocketAddress service = new InetSocketAddress(url.getHost(),
url.getPort());
SecurityUtil.setTokenService(dToken, service);
return dToken;
}
代码示例来源: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
/**
* 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: 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
/**
* 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
try {
Token<AbstractDelegationTokenIdentifier> dt = new Token();
dt.decodeFromUrlString(delegationParam);
UserGroupInformation ugi = tokenManager.verifyToken(dt);
final String shortName = ugi.getShortUserName();
代码示例来源:origin: apache/hive
case DIGEST:
Token<DelegationTokenIdentifier> t= new Token<>();
t.decodeFromUrlString(tokenStrForm);
saslTransport = new TSaslClientTransport(
method.getMechanismName(),
代码示例来源:origin: org.apache.hadoop/hadoop-common
Token<AbstractDelegationTokenIdentifier> dt = new Token();
try {
dt.decodeFromUrlString(tokenToRenew);
long expirationTime = tokenManager.renewToken(dt,
requestUgi.getShortUserName());
Token<AbstractDelegationTokenIdentifier> dt = new Token();
try {
dt.decodeFromUrlString(tokenToCancel);
tokenManager.cancelToken(dt, (requestUgi != null)
? requestUgi.getShortUserName() : null);
代码示例来源:origin: larsgeorge/hbase-book
public static void main(String[] args) throws IOException, InterruptedException {
Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf);
// vv TokenExample
Token<AuthenticationTokenIdentifier> token =
TokenUtil.obtainToken(connection);
String urlString = token.encodeToUrlString();
File temp = new File(FileUtils.getTempDirectory(), "token");
FileUtils.writeStringToFile(temp, urlString);
System.out.println("Encoded Token: " + urlString);
String strToken = FileUtils.readFileToString(new File("token"));
Token token2 = new Token();
token2.decodeFromUrlString(strToken);
UserGroupInformation.getCurrentUser().addToken(token2);
// ^^ TokenExample
connection.close();
}
}
代码示例来源: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-hdfs
private static UserGroupInformation getTokenUGI(ServletContext context,
HttpServletRequest request,
String tokenString,
Configuration conf)
throws IOException {
final Token<DelegationTokenIdentifier> token =
new Token<DelegationTokenIdentifier>();
token.decodeFromUrlString(tokenString);
InetSocketAddress serviceAddress = getNNServiceAddress(context, request);
if (serviceAddress != null) {
SecurityUtil.setTokenService(token, serviceAddress);
token.setKind(DelegationTokenIdentifier.HDFS_DELEGATION_KIND);
}
ByteArrayInputStream buf =
new ByteArrayInputStream(token.getIdentifier());
DataInputStream in = new DataInputStream(buf);
DelegationTokenIdentifier id = new DelegationTokenIdentifier();
id.readFields(in);
if (context != null) {
final NameNode nn = NameNodeHttpServer.getNameNodeFromContext(context);
if (nn != null) {
// Verify the token.
nn.getNamesystem().verifyToken(id, token.getPassword());
}
}
UserGroupInformation ugi = id.getUser();
ugi.addToken(token);
return ugi;
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
token.decodeFromUrlString(delegationTokenArgument.getValue());
final long expiryTime = cp.renewDelegationToken(token);
final String js = JsonUtil.toJsonString("long", expiryTime);
token.decodeFromUrlString(delegationTokenArgument.getValue());
cp.cancelDelegationToken(token);
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
内容来源于网络,如有侵权,请联系作者删除!