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

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

Introduction

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

Prototype

public abstract void flush() throws IOException;

Source Link

Document

Ensures that any changes to the credentials are written to persistent store.

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 ww. j  av  a  2  s .  c o  m*/
    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();
        }
    }
}

From source file:org.apache.atlas.web.security.BaseSSLAndKerberosTest.java

License:Apache License

protected void setupCredentials() throws Exception {
    Configuration conf = new Configuration(false);

    File file = new File(jksPath.toUri().getPath());
    file.delete();/*from ww  w. ja  va  2s.c om*/
    conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);

    CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);

    // create new aliases
    try {

        char[] storepass = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry(SecurityProperties.KEYSTORE_PASSWORD_KEY, storepass);

        char[] trustpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry(SecurityProperties.TRUSTSTORE_PASSWORD_KEY, trustpass);

        char[] trustpass2 = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry("ssl.client.truststore.password", trustpass2);

        char[] certpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry(SecurityProperties.SERVER_CERT_PASSWORD_KEY, certpass);

        // write out so that it can be found in checks
        provider.flush();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:org.apache.atlas.web.security.SSLTest.java

License:Apache License

protected void setupCredentials() throws Exception {
    Configuration conf = new Configuration(false);

    File file = new File(jksPath.toUri().getPath());
    file.delete();//  w  ww.j av  a 2 s  . co  m
    conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);

    CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);

    // create new aliases
    try {

        char[] storepass = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry(KEYSTORE_PASSWORD_KEY, storepass);

        char[] trustpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry(TRUSTSTORE_PASSWORD_KEY, trustpass);

        char[] trustpass2 = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry("ssl.client.truststore.password", trustpass2);

        char[] certpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry(SERVER_CERT_PASSWORD_KEY, certpass);

        // write out so that it can be found in checks
        provider.flush();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:org.apache.atlas.web.service.SecureEmbeddedServerTestBase.java

License:Apache License

protected void setupCredentials() throws Exception {
    Configuration conf = new Configuration(false);

    File file = new File(jksPath.toUri().getPath());
    file.delete();/*from w ww .j a  va  2s  .  co  m*/
    conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);

    CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);

    // create new aliases
    try {

        char[] storepass = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry(KEYSTORE_PASSWORD_KEY, storepass);

        char[] trustpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry(TRUSTSTORE_PASSWORD_KEY, trustpass);

        char[] certpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
        provider.createCredentialEntry(SERVER_CERT_PASSWORD_KEY, certpass);

        // write out so that it can be found in checks
        provider.flush();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:org.apache.sentry.provider.db.service.persistent.TestHMSFollowerSentryStoreIntegration.java

License:Apache License

@BeforeClass
public static void setup() throws Exception {
    conf = new Configuration(true);
    final String ourUrl = UserProvider.SCHEME_NAME + ":///";
    conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl);

    // THis should be a UserGroupInformation provider
    CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);

    // The user credentials are stored as a static variable by UserGrouoInformation provider.
    // We need to only set the password the first time, an attempt to set it for the second
    // time fails with an exception.
    if (provider.getCredentialEntry(ServerConfig.SENTRY_STORE_JDBC_PASS) == null) {
        provider.createCredentialEntry(ServerConfig.SENTRY_STORE_JDBC_PASS, passwd);
        provider.flush();
    }/* ww  w.ja  va 2s  .c  om*/

    dataDir = new File(Files.createTempDir(), "sentry_policy_db");
    conf.set(ServerConfig.SENTRY_VERIFY_SCHEM_VERSION, "false");
    conf.set(ServerConfig.SENTRY_STORE_JDBC_URL,
            "jdbc:derby:;databaseName=" + dataDir.getPath() + ";create=true");
    conf.set(ServerConfig.SENTRY_STORE_JDBC_PASS, "dummy");
    conf.setStrings(ServerConfig.ADMIN_GROUPS, adminGroups);
    conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING, ServerConfig.SENTRY_STORE_LOCAL_GROUP_MAPPING);
    policyFilePath = new File(dataDir, "local_policy_file.ini");
    conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING_RESOURCE, policyFilePath.getPath());
    conf.setInt(ServerConfig.SENTRY_STORE_TRANSACTION_RETRY, 10);

}

From source file:org.apache.sentry.provider.db.service.persistent.TestSentryStore.java

License:Apache License

@BeforeClass
public static void setup() throws Exception {
    conf = new Configuration(true);
    final String ourUrl = UserProvider.SCHEME_NAME + ":///";
    conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl);

    // enable HDFS sync, so perm and path changes will be saved into DB
    conf.set(ServiceConstants.ServerConfig.PROCESSOR_FACTORIES,
            "org.apache.sentry.hdfs.SentryHDFSServiceProcessorFactory");
    conf.set(ServiceConstants.ServerConfig.SENTRY_POLICY_STORE_PLUGINS, "org.apache.sentry.hdfs.SentryPlugin");

    // THis should be a UserGroupInformation provider
    CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);

    // The user credentials are stored as a static variable by UserGrouoInformation provider.
    // We need to only set the password the first time, an attempt to set it for the second
    // time fails with an exception.
    if (provider.getCredentialEntry(ServerConfig.SENTRY_STORE_JDBC_PASS) == null) {
        provider.createCredentialEntry(ServerConfig.SENTRY_STORE_JDBC_PASS, passwd);
        provider.flush();
    }/*  w ww. jav a  2s .c o m*/

    dataDir = new File(Files.createTempDir(), "sentry_policy_db");
    conf.set(ServerConfig.SENTRY_VERIFY_SCHEM_VERSION, "false");
    conf.set(ServerConfig.SENTRY_STORE_JDBC_URL,
            "jdbc:derby:;databaseName=" + dataDir.getPath() + ";create=true");
    conf.set(ServerConfig.SENTRY_STORE_JDBC_PASS, "dummy");
    conf.setStrings(ServerConfig.ADMIN_GROUPS, adminGroups);
    conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING, ServerConfig.SENTRY_STORE_LOCAL_GROUP_MAPPING);
    policyFilePath = new File(dataDir, "local_policy_file.ini");
    conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING_RESOURCE, policyFilePath.getPath());

    // These tests do not need to retry transactions, so setting to 1 to reduce testing time
    conf.setInt(ServerConfig.SENTRY_STORE_TRANSACTION_RETRY, 1);

    // SentryStore should be initialized only once. The tables created by the test cases will
    // be cleaned up during the @After method.
    sentryStore = new SentryStore(conf);

    boolean hdfsSyncEnabled = SentryServiceUtil.isHDFSSyncEnabled(conf);
    sentryStore.setPersistUpdateDeltas(hdfsSyncEnabled);
}

From source file:org.apache.slider.server.services.security.TestCertificateManager.java

License:Apache License

private void setupCredentials(AggregateConf instanceDefinition, String keyAlias, String trustAlias)
        throws Exception {
    Configuration conf = new Configuration();
    final Path jksPath = new Path(SecurityUtils.getSecurityDir(), "test.jks");
    final String ourUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri();

    File file = new File(SecurityUtils.getSecurityDir(), "test.jks");
    file.delete();//from   w w  w .j av a  2 s . co m
    conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl);

    instanceDefinition.getAppConf().credentials.put(ourUrl, new ArrayList<String>());

    CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);

    // create new aliases
    try {

        if (keyAlias != null) {
            char[] storepass = { 'k', 'e', 'y', 'p', 'a', 's', 's' };
            provider.createCredentialEntry(keyAlias, storepass);
        }

        if (trustAlias != null) {
            char[] trustpass = { 't', 'r', 'u', 's', 't', 'p', 'a', 's', 's' };
            provider.createCredentialEntry(trustAlias, trustpass);
        }

        // write out so that it can be found in checks
        provider.flush();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}