Search in sources :

Example 6 with CredentialShell

use of org.apache.hadoop.security.alias.CredentialShell in project ranger by apache.

the class buildks method listCredential.

public int listCredential(String[] args) {
    int returnCode = -1;
    String command = null;
    String providerOption = null;
    String providerPath = null;
    String storeType = KeyStore.getDefaultType();
    try {
        if (args != null && args.length == 3) {
            command = args[0];
            providerOption = args[1];
            providerPath = args[2];
            if (!isValidListCommand(command, providerOption, providerPath, storeType)) {
                return returnCode;
            }
            // display command which need to be executed or entered
            displayCommand(args);
        } else {
            return returnCode;
        }
        CredentialShell cs = new CredentialShell();
        Configuration conf = new Configuration();
        // parse argument
        GenericOptionsParser parser = new GenericOptionsParser(conf, args);
        // set the configuration back, so that Tool can configure itself
        cs.setConf(conf);
        // get valid and remaining argument
        String[] toolArgs = parser.getRemainingArgs();
        // execute command in CredentialShell
        returnCode = cs.run(toolArgs);
    // if response code is zero then success else failure
    // System.out.println("Response Code:"+returnCode);
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return returnCode;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) CredentialShell(org.apache.hadoop.security.alias.CredentialShell) IOException(java.io.IOException) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

Example 7 with CredentialShell

use of org.apache.hadoop.security.alias.CredentialShell in project ranger by apache.

the class buildks method createKeyStore.

public int createKeyStore(String[] args) {
    int returnCode = -1;
    try {
        String command = null;
        String alias = null;
        String valueOption = null;
        String credential = null;
        String providerOption = null;
        String providerPath = null;
        String storeTypeOption = "storeType";
        String storeType = KeyStore.getDefaultType();
        if (args != null && (args.length == 6 || args.length == 8)) {
            command = args[0];
            alias = args[1];
            valueOption = args[2];
            credential = args[3];
            providerOption = args[4];
            providerPath = args[5];
            if (args.length == 8) {
                storeTypeOption = args[6];
                storeType = args[7];
            }
            if (!isValidCreateCommand(command, alias, valueOption, credential, providerOption, providerPath, storeTypeOption, storeType)) {
                return returnCode;
            }
            displayCommand(args);
        } else {
            return returnCode;
        }
        CredentialShell cs = new CredentialShell();
        Configuration conf = new Configuration();
        // parse argument
        GenericOptionsParser parser = new GenericOptionsParser(conf, args);
        // set the configuration back, so that Tool can configure itself
        cs.setConf(conf);
        // get valid and remaining argument
        String[] toolArgs = parser.getRemainingArgs();
        // execute command in CredentialShell
        // int i = 0;
        // for(String s : toolArgs) {
        // System.out.println("TooArgs [" + i + "] = [" + s + "]");
        // i++;
        // }
        String[] finalArgs = Arrays.copyOfRange(toolArgs, 0, 6);
        returnCode = cs.run(finalArgs);
    // if response code is zero then success else failure
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return returnCode;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) CredentialShell(org.apache.hadoop.security.alias.CredentialShell) IOException(java.io.IOException) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

Example 8 with CredentialShell

use of org.apache.hadoop.security.alias.CredentialShell in project ranger by apache.

the class RangerCredentialProviderTest method setup.

@Before
public void setup() throws Exception {
    int ret;
    // 
    try {
        if (ksFile != null) {
            if (ksFile.exists()) {
                System.out.println("Keystore File [" + ksFile.getAbsolutePath() + "] is available - and deleting");
                ksFile.delete();
                System.out.println("Keystore File [" + ksFile.getAbsolutePath() + "] is deleted.");
            } else {
                System.out.println("Keystore File [" + ksFile.getAbsolutePath() + "] is not available");
            }
        } else {
            System.out.println("Keystore File is NULL");
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
    Configuration conf = new Configuration();
    CredentialShell cs = new CredentialShell();
    cs.setConf(conf);
    try {
        ret = cs.run(argsCreate);
    } catch (Exception e) {
        throw e;
    }
    assertEquals(0, ret);
    System.out.println("(1) Number of active Threads : " + Thread.activeCount());
    listThreads();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CredentialShell(org.apache.hadoop.security.alias.CredentialShell) IOException(java.io.IOException) Before(org.junit.Before)

Aggregations

CredentialShell (org.apache.hadoop.security.alias.CredentialShell)8 IOException (java.io.IOException)6 Configuration (org.apache.hadoop.conf.Configuration)6 GenericOptionsParser (org.apache.hadoop.util.GenericOptionsParser)4 Field (java.lang.reflect.Field)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 After (org.junit.After)1 Before (org.junit.Before)1