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);
}
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);
}
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);
}
Aggregations