Example usage for org.apache.hadoop.security.alias CredentialShell CredentialShell

List of usage examples for org.apache.hadoop.security.alias CredentialShell CredentialShell

Introduction

In this page you can find the example usage for org.apache.hadoop.security.alias CredentialShell CredentialShell.

Prototype

CredentialShell

Source Link

Usage

From source file:org.apache.ranger.authorization.hadoop.utils.RangerCredentialProviderTest.java

License:Apache License

@Before
public void setup() throws Exception {
    int ret;//  w  w  w .  j  a  va  2  s . c  om
    //
    // adding a delete before creating a keystore
    //
    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();
}

From source file:org.apache.ranger.authorization.hadoop.utils.RangerCredentialProviderTest.java

License:Apache License

@After
public void teardown() throws Exception {
    System.out.println("In teardown : Number of active Threads : " + Thread.activeCount());
    int ret;//  www.jav  a  2 s .c o m
    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();
}

From source file:org.apache.ranger.authorization.hadoop.utils.RangerCredentialProviderTest.java

License:Apache License

private static boolean isCredentialShellInteractiveEnabled() {
    boolean ret = false;

    String fieldName = "interactive";

    CredentialShell cs = new CredentialShell();

    try {/*from  www.  j  a va 2  s  . c  om*/
        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;

}

From source file:org.apache.ranger.credentialapi.buildks.java

License:Apache License

public int createKeyStore(String args[]) {
    int returnCode = -1;
    try {//from  w w w .  ja  v  a 2  s .  c o  m
        String command = null;
        String alias = null;
        String valueOption = null;
        String credential = null;
        String providerOption = null;
        String providerPath = null;
        if (args != null && args.length == 6) {
            command = args[0];
            alias = args[1];
            valueOption = args[2];
            credential = args[3];
            providerOption = args[4];
            providerPath = args[5];
            if (!isValidCreateCommand(command, alias, valueOption, credential, providerOption, providerPath)) {
                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++ ;
        // }
        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;
}

From source file:org.apache.ranger.credentialapi.buildks.java

License:Apache License

public int createCredentialFromUserInput() {
    int returnCode = -1;
    try {/*from  w  w  w .  j  a  v a2  s .  c o  m*/
        String[] args = null;
        String command = null;
        String alias = null;
        String valueOption = null;
        String credential = null;
        String providerOption = null;
        String providerPath = 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")) {
            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)) {
            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;
}

From source file:org.apache.ranger.credentialapi.buildks.java

License:Apache License

public int listCredential(String args[]) {
    int returnCode = -1;
    String command = null;//from   w  w w.j  a  v  a2 s . com
    String providerOption = null;
    String providerPath = null;
    try {
        if (args != null && args.length == 3) {
            command = args[0];
            providerOption = args[1];
            providerPath = args[2];
            if (!isValidListCommand(command, providerOption, providerPath)) {
                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;
}

From source file:org.apache.ranger.credentialapi.buildks.java

License:Apache License

public int deleteCredential(String args[], boolean isSilentMode) {
    int returnCode = -1;
    try {/*from   w  ww  .j av a  2  s. co m*/
        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
        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;
}