use of org.apache.drill.exec.store.security.HadoopCredentialsProvider 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);
}
use of org.apache.drill.exec.store.security.HadoopCredentialsProvider in project drill by apache.
the class CredentialsProviderSerDeTest method testHadoopCredentialsProviderSerDe.
@Test
public void testHadoopCredentialsProviderSerDe() throws JsonProcessingException {
ObjectMapper mapper = cluster.drillbit().getContext().getLpPersistence().getMapper();
CredentialsProvider credentialsProvider = new HadoopCredentialsProvider(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, "myLoginProp", UsernamePasswordCredentials.PASSWORD, "myPassProp"));
String serialized = mapper.writerFor(CredentialsProvider.class).writeValueAsString(credentialsProvider);
String expected = "{\n" + " \"credentialsProviderType\" : \"HadoopCredentialsProvider\",\n" + " \"propertyNames\" : {\n" + " \"username\" : \"myLoginProp\",\n" + " \"password\" : \"myPassProp\"\n" + " }\n" + "}";
assertEquals(expected, serialized);
CredentialsProvider deserialized = mapper.readerFor(CredentialsProvider.class).readValue(serialized);
assertEquals(credentialsProvider, deserialized);
}
Aggregations