Search in sources :

Example 1 with CredentialShell

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

the class buildks method isCredentialShellInteractiveEnabled.

private static boolean isCredentialShellInteractiveEnabled() {
    boolean ret = false;
    String fieldName = "interactive";
    CredentialShell cs = new CredentialShell();
    try {
        Field interactiveField = cs.getClass().getDeclaredField(fieldName);
        if (interactiveField != null) {
            interactiveField.setAccessible(true);
            ret = interactiveField.getBoolean(cs);
            System.out.println("FOUND value of [" + fieldName + "] field in the Class [" + cs.getClass().getName() + "] = [" + ret + "]");
        }
    } catch (Throwable e) {
        System.out.println("Unable to find the value of [" + fieldName + "] field in the Class [" + cs.getClass().getName() + "]. Skiping -f option");
        e.printStackTrace();
        ret = false;
    }
    return ret;
}
Also used : Field(java.lang.reflect.Field) CredentialShell(org.apache.hadoop.security.alias.CredentialShell)

Example 2 with CredentialShell

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

the class RangerCredentialProviderTest method teardown.

@After
public void teardown() throws Exception {
    System.out.println("In teardown : Number of active Threads : " + Thread.activeCount());
    int ret;
    Configuration conf = new Configuration();
    CredentialShell cs = new CredentialShell();
    cs.setConf(conf);
    try {
        ret = cs.run(argsDelete);
    } catch (Exception e) {
        throw e;
    }
    assertEquals(0, ret);
    listThreads();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CredentialShell(org.apache.hadoop.security.alias.CredentialShell) IOException(java.io.IOException) After(org.junit.After)

Example 3 with CredentialShell

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

the class RangerCredentialProviderTest method isCredentialShellInteractiveEnabled.

private static boolean isCredentialShellInteractiveEnabled() {
    boolean ret = false;
    String fieldName = "interactive";
    CredentialShell cs = new CredentialShell();
    try {
        Field interactiveField = cs.getClass().getDeclaredField(fieldName);
        if (interactiveField != null) {
            interactiveField.setAccessible(true);
            ret = interactiveField.getBoolean(cs);
            System.out.println("FOUND value of [" + fieldName + "] field in the Class [" + cs.getClass().getName() + "] = [" + ret + "]");
        }
    } catch (Throwable e) {
        System.out.println("Unable to find the value of [" + fieldName + "] field in the Class [" + cs.getClass().getName() + "]. Skiping -f option");
        e.printStackTrace();
        ret = false;
    }
    return ret;
}
Also used : Field(java.lang.reflect.Field) CredentialShell(org.apache.hadoop.security.alias.CredentialShell)

Example 4 with CredentialShell

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

the class buildks method deleteCredential.

public int deleteCredential(String[] args, boolean isSilentMode) {
    int returnCode = -1;
    try {
        if (args != null && args.length == 4) {
            // for non-interactive, insert argument "-f" if needed
            if (isSilentMode && isCredentialShellInteractiveEnabled()) {
                String[] updatedArgs = new String[5];
                updatedArgs[0] = args[0];
                updatedArgs[1] = args[1];
                updatedArgs[2] = "-f";
                updatedArgs[3] = args[2];
                updatedArgs[4] = args[3];
                args = updatedArgs;
            }
            // 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
        // String[] finalArgs = Arrays.copyOfRange(toolArgs, 0, 6);
        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 5 with CredentialShell

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

the class buildks method createCredentialFromUserInput.

public int createCredentialFromUserInput() {
    int returnCode = -1;
    try {
        String[] args = null;
        String command = null;
        String alias = null;
        String valueOption = null;
        String credential = null;
        String providerOption = null;
        String providerPath = null;
        String storeTypeOption = null;
        String storeType = null;
        // below code can ask user to input if command line input fails
        System.out.println("Enter Alias Name:");
        BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
        alias = bufferRead.readLine();
        System.out.println("Enter password:");
        credential = bufferRead.readLine();
        System.out.println("Enter .jceks output file name with path:");
        providerPath = bufferRead.readLine();
        if (providerPath != null && !providerPath.trim().isEmpty() && (!providerPath.startsWith("localjceks://file") && !providerPath.startsWith("jceks://file") && !providerPath.startsWith("localbcfks://file") && !providerPath.startsWith("bcfks://file"))) {
            if (providerPath.startsWith("/")) {
                providerPath = "jceks://file" + providerPath;
            } else {
                providerPath = "jceks://file/" + providerPath;
            }
        }
        command = "create";
        valueOption = "-value";
        providerOption = "-provider";
        if (!isValidCreateCommand(command, alias, valueOption, credential, providerOption, providerPath, storeTypeOption, storeType)) {
            return returnCode;
        }
        args = new String[6];
        args[0] = command;
        args[1] = alias;
        args[2] = valueOption;
        args[3] = credential;
        args[4] = providerOption;
        args[5] = providerPath;
        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 : InputStreamReader(java.io.InputStreamReader) Configuration(org.apache.hadoop.conf.Configuration) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) CredentialShell(org.apache.hadoop.security.alias.CredentialShell) IOException(java.io.IOException) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

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