use of org.apache.accumulo.core.client.security.tokens.AuthenticationToken.TokenProperty in project accumulo by apache.
the class LoginProperties method execute.
@Override
public void execute(String[] args) throws Exception {
AccumuloConfiguration config = new ServerConfigurationFactory(HdfsZooInstance.getInstance()).getSystemConfiguration();
Authenticator authenticator = AccumuloVFSClassLoader.getClassLoader().loadClass(config.get(Property.INSTANCE_SECURITY_AUTHENTICATOR)).asSubclass(Authenticator.class).newInstance();
List<Set<TokenProperty>> tokenProps = new ArrayList<>();
for (Class<? extends AuthenticationToken> tokenType : authenticator.getSupportedTokenTypes()) {
tokenProps.add(tokenType.newInstance().getProperties());
}
System.out.println("Supported token types for " + authenticator.getClass().getName() + " are : ");
for (Class<? extends AuthenticationToken> tokenType : authenticator.getSupportedTokenTypes()) {
System.out.println("\t" + tokenType.getName() + ", which accepts the following properties : ");
for (TokenProperty tokenProperty : tokenType.newInstance().getProperties()) {
System.out.println("\t\t" + tokenProperty);
}
System.out.println();
}
}
use of org.apache.accumulo.core.client.security.tokens.AuthenticationToken.TokenProperty in project accumulo by apache.
the class CreateToken method execute.
@Override
public void execute(String[] args) {
Opts opts = new Opts();
opts.parseArgs("accumulo create-token", args);
Password pass = opts.password;
if (pass == null && opts.securePassword != null) {
pass = opts.securePassword;
}
try {
String principal = opts.principal;
if (principal == null) {
principal = getConsoleReader().readLine("Username (aka principal): ");
}
AuthenticationToken token = Class.forName(opts.tokenClassName).asSubclass(AuthenticationToken.class).newInstance();
Properties props = new Properties();
for (TokenProperty tp : token.getProperties()) {
String input;
if (pass != null && tp.getKey().equals("password")) {
input = pass.toString();
} else {
if (tp.getMask()) {
input = getConsoleReader().readLine(tp.getDescription() + ": ", '*');
} else {
input = getConsoleReader().readLine(tp.getDescription() + ": ");
}
}
props.put(tp.getKey(), input);
token.init(props);
}
String tokenBase64 = Base64.getEncoder().encodeToString(AuthenticationTokenSerializer.serialize(token));
String tokenFile = opts.tokenFile;
if (tokenFile == null) {
tokenFile = getConsoleReader().readLine("File to save auth token to: ");
}
File tf = new File(tokenFile);
if (!tf.exists()) {
if (!tf.createNewFile()) {
throw new IOException("Couldn't create " + tf.getCanonicalPath());
}
}
PrintStream out = new PrintStream(new FileOutputStream(tf, true), true, UTF_8.name());
String outString = principal + ":" + opts.tokenClassName + ":" + tokenBase64;
out.println(outString);
out.close();
System.out.println("Token written to " + tokenFile + ". Remember to upload it to hdfs.");
} catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
Aggregations