Search in sources :

Example 1 with DefaultPasswordProvider

use of org.apache.druid.metadata.DefaultPasswordProvider in project druid by druid-io.

the class TestAWSCredentialsProvider method testWithFileSessionCredentials.

@Test
public void testWithFileSessionCredentials() throws IOException {
    AWSCredentialsConfig config = EasyMock.createMock(AWSCredentialsConfig.class);
    EasyMock.expect(config.getAccessKey()).andReturn(new DefaultPasswordProvider(""));
    EasyMock.expect(config.getSecretKey()).andReturn(new DefaultPasswordProvider(""));
    File file = folder.newFile();
    try (BufferedWriter out = Files.newWriter(file, StandardCharsets.UTF_8)) {
        out.write("sessionToken=sessionTokenSample\nsecretKey=secretKeySample\naccessKey=accessKeySample\n");
    }
    EasyMock.expect(config.getFileSessionCredentials()).andReturn(file.getAbsolutePath()).atLeastOnce();
    EasyMock.replay(config);
    AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
    AWSCredentials credentials = provider.getCredentials();
    Assert.assertTrue(credentials instanceof AWSSessionCredentials);
    AWSSessionCredentials sessionCredentials = (AWSSessionCredentials) credentials;
    Assert.assertEquals("accessKeySample", sessionCredentials.getAWSAccessKeyId());
    Assert.assertEquals("secretKeySample", sessionCredentials.getAWSSecretKey());
    Assert.assertEquals("sessionTokenSample", sessionCredentials.getSessionToken());
    // try to create
    ServerSideEncryptingAmazonS3.Builder amazonS3ClientBuilder = s3Module.getServerSideEncryptingAmazonS3Builder(provider, new AWSProxyConfig(), new AWSEndpointConfig(), new AWSClientConfig(), new S3StorageConfig(new NoopServerSideEncryption()));
    s3Module.getAmazonS3Client(amazonS3ClientBuilder);
}
Also used : AWSClientConfig(org.apache.druid.common.aws.AWSClientConfig) AWSCredentialsConfig(org.apache.druid.common.aws.AWSCredentialsConfig) AWSCredentials(com.amazonaws.auth.AWSCredentials) BufferedWriter(java.io.BufferedWriter) AWSEndpointConfig(org.apache.druid.common.aws.AWSEndpointConfig) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) AWSProxyConfig(org.apache.druid.common.aws.AWSProxyConfig) DefaultPasswordProvider(org.apache.druid.metadata.DefaultPasswordProvider) File(java.io.File) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 2 with DefaultPasswordProvider

use of org.apache.druid.metadata.DefaultPasswordProvider in project druid by druid-io.

the class TestAWSCredentialsProvider method testWithFixedAWSKeys.

@Test
public void testWithFixedAWSKeys() {
    AWSCredentialsConfig config = EasyMock.createMock(AWSCredentialsConfig.class);
    EasyMock.expect(config.getAccessKey()).andReturn(new DefaultPasswordProvider("accessKeySample")).atLeastOnce();
    EasyMock.expect(config.getSecretKey()).andReturn(new DefaultPasswordProvider("secretKeySample")).atLeastOnce();
    EasyMock.replay(config);
    AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
    AWSCredentials credentials = provider.getCredentials();
    Assert.assertEquals("accessKeySample", credentials.getAWSAccessKeyId());
    Assert.assertEquals("secretKeySample", credentials.getAWSSecretKey());
    // try to create
    ServerSideEncryptingAmazonS3.Builder amazonS3ClientBuilder = s3Module.getServerSideEncryptingAmazonS3Builder(provider, new AWSProxyConfig(), new AWSEndpointConfig(), new AWSClientConfig(), new S3StorageConfig(new NoopServerSideEncryption()));
    s3Module.getAmazonS3Client(amazonS3ClientBuilder);
}
Also used : AWSEndpointConfig(org.apache.druid.common.aws.AWSEndpointConfig) AWSProxyConfig(org.apache.druid.common.aws.AWSProxyConfig) AWSClientConfig(org.apache.druid.common.aws.AWSClientConfig) DefaultPasswordProvider(org.apache.druid.metadata.DefaultPasswordProvider) AWSCredentialsConfig(org.apache.druid.common.aws.AWSCredentialsConfig) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 3 with DefaultPasswordProvider

use of org.apache.druid.metadata.DefaultPasswordProvider in project druid by druid-io.

the class EmitterTest method testBasicAuthenticationAndNewlineSeparating.

@Test
public void testBasicAuthenticationAndNewlineSeparating() throws Exception {
    final List<UnitEvent> events = Arrays.asList(new UnitEvent("test", 1), new UnitEvent("test", 2));
    emitter = manualFlushEmitterWithBasicAuthenticationAndNewlineSeparating(new DefaultPasswordProvider("foo:bar"));
    httpClient.setGoHandler(new GoHandler() {

        @Override
        protected ListenableFuture<Response> go(Request request) throws JsonProcessingException {
            Assert.assertEquals(TARGET_URL, request.getUrl());
            Assert.assertEquals("application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE));
            Assert.assertEquals("Basic " + StringUtils.encodeBase64String(StringUtils.toUtf8("foo:bar")), request.getHeaders().get(HttpHeaders.Names.AUTHORIZATION));
            Assert.assertEquals(StringUtils.format("%s\n%s\n", JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(1))), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString());
            return GoHandlers.immediateFuture(okResponse());
        }
    }.times(1));
    for (UnitEvent event : events) {
        emitter.emit(event);
    }
    emitter.flush();
    waitForEmission(emitter, 1);
    closeNoFlush(emitter);
    Assert.assertTrue(httpClient.succeeded());
}
Also used : Response(org.asynchttpclient.Response) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) UnitEvent(org.apache.druid.java.util.emitter.service.UnitEvent) Request(org.asynchttpclient.Request) DefaultPasswordProvider(org.apache.druid.metadata.DefaultPasswordProvider) Test(org.junit.Test)

Example 4 with DefaultPasswordProvider

use of org.apache.druid.metadata.DefaultPasswordProvider in project druid by druid-io.

the class HttpInputSourceTest method testConstructorAllowsOnlyCustomProtocols.

@Test
public void testConstructorAllowsOnlyCustomProtocols() {
    final HttpInputSourceConfig customConfig = new HttpInputSourceConfig(ImmutableSet.of("druid"));
    new HttpInputSource(ImmutableList.of(URI.create("druid:///")), "myName", new DefaultPasswordProvider("myPassword"), customConfig);
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Only [druid] protocols are allowed");
    new HttpInputSource(ImmutableList.of(URI.create("https:///")), "myName", new DefaultPasswordProvider("myPassword"), customConfig);
}
Also used : DefaultPasswordProvider(org.apache.druid.metadata.DefaultPasswordProvider) Test(org.junit.Test)

Example 5 with DefaultPasswordProvider

use of org.apache.druid.metadata.DefaultPasswordProvider in project druid by druid-io.

the class HttpInputSourceTest method testConstructorAllowsOnlyDefaultProtocols.

@Test
public void testConstructorAllowsOnlyDefaultProtocols() {
    new HttpInputSource(ImmutableList.of(URI.create("http:///")), "myName", new DefaultPasswordProvider("myPassword"), new HttpInputSourceConfig(null));
    new HttpInputSource(ImmutableList.of(URI.create("https:///")), "myName", new DefaultPasswordProvider("myPassword"), new HttpInputSourceConfig(null));
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Only [http, https] protocols are allowed");
    new HttpInputSource(ImmutableList.of(URI.create("my-protocol:///")), "myName", new DefaultPasswordProvider("myPassword"), new HttpInputSourceConfig(null));
}
Also used : DefaultPasswordProvider(org.apache.druid.metadata.DefaultPasswordProvider) Test(org.junit.Test)

Aggregations

DefaultPasswordProvider (org.apache.druid.metadata.DefaultPasswordProvider)9 Test (org.junit.Test)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)2 Std (com.fasterxml.jackson.databind.InjectableValues.Std)2 AWSClientConfig (org.apache.druid.common.aws.AWSClientConfig)2 AWSCredentialsConfig (org.apache.druid.common.aws.AWSCredentialsConfig)2 AWSEndpointConfig (org.apache.druid.common.aws.AWSEndpointConfig)2 AWSProxyConfig (org.apache.druid.common.aws.AWSProxyConfig)2 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)1 SmileFactory (com.fasterxml.jackson.dataformat.smile.SmileFactory)1 Injector (com.google.inject.Injector)1 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 Properties (java.util.Properties)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Validator (javax.validation.Validator)1 InputSource (org.apache.druid.data.input.InputSource)1