Example usage for org.apache.hadoop.security.alias CredentialProvider deleteCredentialEntry

List of usage examples for org.apache.hadoop.security.alias CredentialProvider deleteCredentialEntry

Introduction

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

Prototype

public abstract void deleteCredentialEntry(String name) throws IOException;

Source Link

Document

Delete the given credential.

Usage

From source file:org.apache.atlas.util.CredentialProviderUtility.java

License:Apache License

public static void main(String[] args) throws IOException {
    // prompt for the provider name
    CredentialProvider provider = getCredentialProvider(textDevice);

    char[] cred;//from   w w w. j  a v a 2 s .  com
    for (String key : KEYS) {
        cred = getPassword(textDevice, key);
        // create a credential entry and store it
        boolean overwrite = true;
        if (provider.getCredentialEntry(key) != null) {
            String choice = textDevice.readLine("Entry for %s already exists.  Overwrite? (y/n) [y]:", key);
            overwrite = StringUtils.isEmpty(choice) || choice.equalsIgnoreCase("y");
            if (overwrite) {
                provider.deleteCredentialEntry(key);
                provider.flush();
                provider.createCredentialEntry(key, cred);
                provider.flush();
                textDevice.printf("Entry for %s was overwritten with the new value.\n", key);
            } else {
                textDevice.printf("Entry for %s was not overwritten.\n", key);
            }
        } else {
            provider.createCredentialEntry(key, cred);
            provider.flush();
        }
    }
}