Search in sources :

Example 1 with PlainCredentialsProvider

use of org.apache.drill.common.logical.security.PlainCredentialsProvider in project drill by apache.

the class TestOAuthProcess method setup.

@BeforeClass
public static void setup() throws Exception {
    ACCESS_TOKEN_RESPONSE = Files.asCharSource(DrillFileUtils.getResourceAsFile("/data/oauth_access_token_response.json"), Charsets.UTF_8).read();
    REFRESH_TOKEN_RESPONSE = Files.asCharSource(DrillFileUtils.getResourceAsFile("/data/token_refresh.json"), Charsets.UTF_8).read();
    TEST_JSON_RESPONSE_WITH_DATATYPES = Files.asCharSource(DrillFileUtils.getResourceAsFile("/data/response2.json"), Charsets.UTF_8).read();
    ClusterFixtureBuilder builder = new ClusterFixtureBuilder(dirTestWatcher).configProperty(ExecConstants.HTTP_ENABLE, true).configProperty(ExecConstants.HTTP_PORT_HUNT, true);
    startCluster(builder);
    int portNumber = cluster.drillbit().getWebServerPort();
    hostname = "http://localhost:" + portNumber + "/storage/" + CONNECTION_NAME;
    Map<String, String> creds = new HashMap<>();
    creds.put("clientID", "12345");
    creds.put("clientSecret", "54321");
    creds.put("accessToken", null);
    creds.put("refreshToken", null);
    creds.put(OAuthTokenCredentials.TOKEN_URI, "http://localhost:" + MOCK_SERVER_PORT + "/get_access_token");
    CredentialsProvider credentialsProvider = new PlainCredentialsProvider(creds);
    HttpApiConfig connectionConfig = HttpApiConfig.builder().url("http://localhost:" + MOCK_SERVER_PORT + "/getdata").method("get").requireTail(false).inputType("json").build();
    HttpOAuthConfig oAuthConfig = HttpOAuthConfig.builder().callbackURL(hostname + "/update_oath2_authtoken").build();
    Map<String, HttpApiConfig> configs = new HashMap<>();
    configs.put("test", connectionConfig);
    // Add storage plugin for test OAuth
    HttpStoragePluginConfig mockStorageConfigWithWorkspace = new HttpStoragePluginConfig(false, configs, TIMEOUT, "", 80, "", "", "", oAuthConfig, credentialsProvider);
    mockStorageConfigWithWorkspace.setEnabled(true);
    cluster.defineStoragePlugin("localOauth", mockStorageConfigWithWorkspace);
}
Also used : PlainCredentialsProvider(org.apache.drill.common.logical.security.PlainCredentialsProvider) HashMap(java.util.HashMap) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) PlainCredentialsProvider(org.apache.drill.common.logical.security.PlainCredentialsProvider) CredentialsProvider(org.apache.drill.common.logical.security.CredentialsProvider) BeforeClass(org.junit.BeforeClass)

Example 2 with PlainCredentialsProvider

use of org.apache.drill.common.logical.security.PlainCredentialsProvider in project drill by apache.

the class CredentialsProviderSerDeTest method testPlainCredentialsProviderSerDe.

@Test
public void testPlainCredentialsProviderSerDe() throws JsonProcessingException {
    ObjectMapper mapper = cluster.drillbit().getContext().getLpPersistence().getMapper();
    CredentialsProvider credentialsProvider = new PlainCredentialsProvider(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, "myLogin", UsernamePasswordCredentials.PASSWORD, "myPass"));
    String serialized = mapper.writerFor(CredentialsProvider.class).writeValueAsString(credentialsProvider);
    String expected = "{\n" + "  \"credentialsProviderType\" : \"PlainCredentialsProvider\",\n" + "  \"credentials\" : {\n" + "    \"username\" : \"myLogin\",\n" + "    \"password\" : \"myPass\"\n" + "  }\n" + "}";
    assertEquals(expected, serialized);
    CredentialsProvider deserialized = mapper.readerFor(CredentialsProvider.class).readValue(serialized);
    assertEquals(credentialsProvider, deserialized);
}
Also used : PlainCredentialsProvider(org.apache.drill.common.logical.security.PlainCredentialsProvider) 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)

Example 3 with PlainCredentialsProvider

use of org.apache.drill.common.logical.security.PlainCredentialsProvider in project drill by apache.

the class CredentialsProviderSerDeTest method testPlainCredentialsProviderWithNoType.

@Test
public void testPlainCredentialsProviderWithNoType() throws JsonProcessingException {
    ObjectMapper mapper = cluster.drillbit().getContext().getLpPersistence().getMapper();
    CredentialsProvider expected = new PlainCredentialsProvider(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, "myLogin", UsernamePasswordCredentials.PASSWORD, "myPass"));
    String serialized = "{\n" + "  \"credentials\" : {\n" + "    \"username\" : \"myLogin\",\n" + "    \"password\" : \"myPass\"\n" + "  }\n" + "}";
    CredentialsProvider deserialized = mapper.readerFor(CredentialsProvider.class).readValue(serialized);
    assertEquals(expected, deserialized);
}
Also used : PlainCredentialsProvider(org.apache.drill.common.logical.security.PlainCredentialsProvider) 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)3 PlainCredentialsProvider (org.apache.drill.common.logical.security.PlainCredentialsProvider)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 EnvCredentialsProvider (org.apache.drill.exec.store.security.EnvCredentialsProvider)2 HadoopCredentialsProvider (org.apache.drill.exec.store.security.HadoopCredentialsProvider)2 VaultCredentialsProvider (org.apache.drill.exec.store.security.vault.VaultCredentialsProvider)2 ClusterTest (org.apache.drill.test.ClusterTest)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 ClusterFixtureBuilder (org.apache.drill.test.ClusterFixtureBuilder)1 BeforeClass (org.junit.BeforeClass)1