Search in sources :

Example 1 with TokenProperty

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();
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) TokenProperty(org.apache.accumulo.core.client.security.tokens.AuthenticationToken.TokenProperty) Authenticator(org.apache.accumulo.server.security.handler.Authenticator) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 2 with TokenProperty

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);
    }
}
Also used : PrintStream(java.io.PrintStream) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) TokenProperty(org.apache.accumulo.core.client.security.tokens.AuthenticationToken.TokenProperty) IOException(java.io.IOException) Properties(org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Password(org.apache.accumulo.core.cli.ClientOpts.Password)

Aggregations

TokenProperty (org.apache.accumulo.core.client.security.tokens.AuthenticationToken.TokenProperty)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Password (org.apache.accumulo.core.cli.ClientOpts.Password)1 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)1 Properties (org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties)1 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)1 ServerConfigurationFactory (org.apache.accumulo.server.conf.ServerConfigurationFactory)1 Authenticator (org.apache.accumulo.server.security.handler.Authenticator)1