本文整理汇总了Java中org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier类的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationTokenIdentifier类的具体用法?Java AuthenticationTokenIdentifier怎么用?Java AuthenticationTokenIdentifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationTokenIdentifier类属于org.apache.hadoop.hbase.security.token包,在下文中一共展示了AuthenticationTokenIdentifier类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initCredentials
import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier; //导入依赖的package包/类
public static void initCredentials(JobConf job) throws IOException {
UserProvider userProvider = UserProvider.instantiate(job);
if (userProvider.isHadoopSecurityEnabled()) {
// propagate delegation related props from launcher job to MR job
if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) {
job.set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION"));
}
}
if (userProvider.isHBaseSecurityEnabled()) {
try {
// login the server principal (if using secure Hadoop)
User user = userProvider.getCurrent();
Token<AuthenticationTokenIdentifier> authToken = getAuthToken(job, user);
if (authToken == null) {
user.obtainAuthTokenForJob(job);
} else {
job.getCredentials().addToken(authToken.getService(), authToken);
}
} catch (InterruptedException ie) {
ie.printStackTrace();
Thread.currentThread().interrupt();
}
}
}
示例2: main
import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier; //导入依赖的package包/类
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();
}
示例3: initCredentials
import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier; //导入依赖的package包/类
public static void initCredentials(JobConf job) throws IOException {
UserProvider userProvider = UserProvider.instantiate(job);
if (userProvider.isHadoopSecurityEnabled()) {
// propagate delegation related props from launcher job to MR job
if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) {
job.set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION"));
}
}
if (userProvider.isHBaseSecurityEnabled()) {
try {
// login the server principal (if using secure Hadoop)
User user = userProvider.getCurrent();
Token<AuthenticationTokenIdentifier> authToken = getAuthToken(job, user);
if (authToken == null) {
user.obtainAuthTokenForJob(job);
} else {
job.getCredentials().addToken(authToken.getService(), authToken);
}
} catch (InterruptedException ie) {
ie.printStackTrace();
Thread.interrupted();
}
}
}
示例4: toToken
import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier; //导入依赖的package包/类
/**
* Converts a Token instance (with embedded identifier) to the protobuf representation.
*
* @param token the Token instance to copy
* @return the protobuf Token message
*/
public static AuthenticationProtos.Token toToken(Token<AuthenticationTokenIdentifier> token) {
AuthenticationProtos.Token.Builder builder = AuthenticationProtos.Token.newBuilder();
builder.setIdentifier(ByteStringer.wrap(token.getIdentifier()));
builder.setPassword(ByteStringer.wrap(token.getPassword()));
if (token.getService() != null) {
builder.setService(ByteString.copyFromUtf8(token.getService().toString()));
}
return builder.build();
}
示例5: getAuthToken
import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier; //导入依赖的package包/类
/**
* Get the authentication token of the user for the cluster specified in the configuration
* @return null if the user does not have the token, otherwise the auth token for the cluster.
*/
private static Token<AuthenticationTokenIdentifier> getAuthToken(Configuration conf, User user)
throws IOException, InterruptedException {
ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "mr-init-credentials", null);
try {
String clusterId = ZKClusterId.readClusterIdZNode(zkw);
return new AuthenticationTokenSelector().selectToken(new Text(clusterId), user.getUGI().getTokens());
} catch (KeeperException e) {
throw new IOException(e);
} finally {
zkw.close();
}
}
示例6: obtainAuthTokenForJob
import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier; //导入依赖的package包/类
private static void obtainAuthTokenForJob(Job job, Configuration conf, User user)
throws IOException, InterruptedException {
Token<AuthenticationTokenIdentifier> authToken = getAuthToken(conf, user);
if (authToken == null) {
user.obtainAuthTokenForJob(conf, job);
} else {
job.getCredentials().addToken(authToken.getService(), authToken);
}
}
示例7: toToken
import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier; //导入依赖的package包/类
/**
* Converts a Token instance (with embedded identifier) to the protobuf representation.
*
* @param token the Token instance to copy
* @return the protobuf Token message
*/
public static AuthenticationProtos.Token toToken(Token<AuthenticationTokenIdentifier> token) {
AuthenticationProtos.Token.Builder builder = AuthenticationProtos.Token.newBuilder();
builder.setIdentifier(HBaseZeroCopyByteString.wrap(token.getIdentifier()));
builder.setPassword(HBaseZeroCopyByteString.wrap(token.getPassword()));
if (token.getService() != null) {
builder.setService(ByteString.copyFromUtf8(token.getService().toString()));
}
return builder.build();
}
示例8: toToken
import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier; //导入依赖的package包/类
/**
* Converts a Token instance (with embedded identifier) to the protobuf representation.
*
* @param token the Token instance to copy
* @return the protobuf Token message
*/
public static AuthenticationProtos.Token toToken(Token<AuthenticationTokenIdentifier> token) {
AuthenticationProtos.Token.Builder builder = AuthenticationProtos.Token.newBuilder();
builder.setIdentifier(ZeroCopyLiteralByteString.wrap(token.getIdentifier()));
builder.setPassword(ZeroCopyLiteralByteString.wrap(token.getPassword()));
if (token.getService() != null) {
builder.setService(ByteString.copyFromUtf8(token.getService().toString()));
}
return builder.build();
}
示例9: toToken
import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier; //导入依赖的package包/类
/**
* Converts a Token instance (with embedded identifier) to the protobuf representation.
*
* @param token the Token instance to copy
* @return the protobuf Token message
*/
public static AuthenticationProtos.Token toToken(Token<AuthenticationTokenIdentifier> token) {
AuthenticationProtos.Token.Builder builder = AuthenticationProtos.Token.newBuilder();
builder.setIdentifier(ByteString.copyFrom(token.getIdentifier()));
builder.setPassword(ByteString.copyFrom(token.getPassword()));
if (token.getService() != null) {
builder.setService(ByteString.copyFromUtf8(token.getService().toString()));
}
return builder.build();
}