Search in sources :

Example 1 with EnvCredentialsProvider

use of org.apache.drill.exec.store.security.EnvCredentialsProvider in project drill by apache.

the class CredentialsProviderImplementationsTest method testEnvCredentialsProvider.

@Test
public void testEnvCredentialsProvider() {
    String variableName = "USER";
    String expectedValue = System.getenv(variableName);
    CredentialsProvider envCredentialsProvider = new EnvCredentialsProvider(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, variableName));
    Map<String, String> actualCredentials = envCredentialsProvider.getCredentials();
    assertEquals(Collections.singletonMap(UsernamePasswordCredentials.USERNAME, expectedValue), actualCredentials);
}
Also used : EnvCredentialsProvider(org.apache.drill.exec.store.security.EnvCredentialsProvider) EnvCredentialsProvider(org.apache.drill.exec.store.security.EnvCredentialsProvider) CredentialsProvider(org.apache.drill.common.logical.security.CredentialsProvider) HadoopCredentialsProvider(org.apache.drill.exec.store.security.HadoopCredentialsProvider) VaultCredentialsProvider(org.apache.drill.exec.store.security.vault.VaultCredentialsProvider) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 2 with EnvCredentialsProvider

use of org.apache.drill.exec.store.security.EnvCredentialsProvider in project drill by apache.

the class CredentialsProviderImplementationsTest method testHadoopCredentialsProvider.

@Test
public void testHadoopCredentialsProvider() {
    Configuration configuration = new Configuration();
    String expectedUsernameValue = "user1";
    String expectedPassValue = "pass123!@#";
    String usernamePropertyName = "username_key";
    String passwordPropertyName = "password_key";
    configuration.set(usernamePropertyName, expectedUsernameValue);
    configuration.set(passwordPropertyName, expectedPassValue);
    CredentialsProvider envCredentialsProvider = new HadoopCredentialsProvider(configuration, ImmutableMap.of(UsernamePasswordCredentials.USERNAME, usernamePropertyName, UsernamePasswordCredentials.PASSWORD, passwordPropertyName));
    Map<String, String> actualCredentials = envCredentialsProvider.getCredentials();
    assertEquals(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, expectedUsernameValue, UsernamePasswordCredentials.PASSWORD, expectedPassValue), actualCredentials);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HadoopCredentialsProvider(org.apache.drill.exec.store.security.HadoopCredentialsProvider) EnvCredentialsProvider(org.apache.drill.exec.store.security.EnvCredentialsProvider) CredentialsProvider(org.apache.drill.common.logical.security.CredentialsProvider) HadoopCredentialsProvider(org.apache.drill.exec.store.security.HadoopCredentialsProvider) VaultCredentialsProvider(org.apache.drill.exec.store.security.vault.VaultCredentialsProvider) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 3 with EnvCredentialsProvider

use of org.apache.drill.exec.store.security.EnvCredentialsProvider in project drill by apache.

the class CredentialsProviderImplementationsTest method testVaultCredentialsProvider.

@Test
public void testVaultCredentialsProvider() throws VaultException {
    DrillConfig config = cluster.drillbit().getContext().getConfig();
    CredentialsProvider envCredentialsProvider = new VaultCredentialsProvider(SECRET_PATH, ImmutableMap.of(UsernamePasswordCredentials.USERNAME, "top_secret", UsernamePasswordCredentials.PASSWORD, "db_password"), config);
    Map<String, String> actualCredentials = envCredentialsProvider.getCredentials();
    assertEquals(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, "password1", UsernamePasswordCredentials.PASSWORD, "dbpassword1"), actualCredentials);
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) VaultCredentialsProvider(org.apache.drill.exec.store.security.vault.VaultCredentialsProvider) EnvCredentialsProvider(org.apache.drill.exec.store.security.EnvCredentialsProvider) CredentialsProvider(org.apache.drill.common.logical.security.CredentialsProvider) HadoopCredentialsProvider(org.apache.drill.exec.store.security.HadoopCredentialsProvider) VaultCredentialsProvider(org.apache.drill.exec.store.security.vault.VaultCredentialsProvider) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 4 with EnvCredentialsProvider

use of org.apache.drill.exec.store.security.EnvCredentialsProvider in project drill by apache.

the class CredentialsProviderSerDeTest method testEnvCredentialsProviderSerDe.

@Test
public void testEnvCredentialsProviderSerDe() throws JsonProcessingException {
    ObjectMapper mapper = cluster.drillbit().getContext().getLpPersistence().getMapper();
    CredentialsProvider envCredentialsProvider = new EnvCredentialsProvider(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, "myLoginVar", UsernamePasswordCredentials.PASSWORD, "myPassVar"));
    String serialized = mapper.writerFor(CredentialsProvider.class).writeValueAsString(envCredentialsProvider);
    String expected = "{\n" + "  \"credentialsProviderType\" : \"EnvCredentialsProvider\",\n" + "  \"envVariables\" : {\n" + "    \"username\" : \"myLoginVar\",\n" + "    \"password\" : \"myPassVar\"\n" + "  }\n" + "}";
    assertEquals(expected, serialized);
    CredentialsProvider deserialized = mapper.readerFor(CredentialsProvider.class).readValue(serialized);
    assertEquals(envCredentialsProvider, deserialized);
}
Also used : EnvCredentialsProvider(org.apache.drill.exec.store.security.EnvCredentialsProvider) EnvCredentialsProvider(org.apache.drill.exec.store.security.EnvCredentialsProvider) PlainCredentialsProvider(org.apache.drill.common.logical.security.PlainCredentialsProvider) CredentialsProvider(org.apache.drill.common.logical.security.CredentialsProvider) HadoopCredentialsProvider(org.apache.drill.exec.store.security.HadoopCredentialsProvider) VaultCredentialsProvider(org.apache.drill.exec.store.security.vault.VaultCredentialsProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Aggregations

CredentialsProvider (org.apache.drill.common.logical.security.CredentialsProvider)4 EnvCredentialsProvider (org.apache.drill.exec.store.security.EnvCredentialsProvider)4 HadoopCredentialsProvider (org.apache.drill.exec.store.security.HadoopCredentialsProvider)4 VaultCredentialsProvider (org.apache.drill.exec.store.security.vault.VaultCredentialsProvider)4 ClusterTest (org.apache.drill.test.ClusterTest)4 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DrillConfig (org.apache.drill.common.config.DrillConfig)1 PlainCredentialsProvider (org.apache.drill.common.logical.security.PlainCredentialsProvider)1 Configuration (org.apache.hadoop.conf.Configuration)1