Search in sources :

Example 1 with AuthenticationClient

use of co.cask.cdap.security.authentication.client.AuthenticationClient in project cdap-ingest by caskdata.

the class StreamReader method createAuthClient.

/**
   * Creates the Authorization client instance and configures with appropriate Gateway server parameters.
   *
   * @return configured {@link co.cask.cdap.security.authentication.client.AuthenticationClient} instance
   * @throws Exception
   */
public AuthenticationClient createAuthClient() throws Exception {
    AuthenticationClient authClient = (AuthenticationClient) Class.forName(authClientClassName).newInstance();
    if (StringUtils.isNotEmpty(cdapHost)) {
        authClient.setConnectionInfo(cdapHost, cdapPort, ssl);
        if (StringUtils.isNotEmpty(authClientPropertiesPath)) {
            Properties authClientProperties = getProperties(authClientPropertiesPath);
            authClient.configure(authClientProperties);
        }
    }
    return authClient;
}
Also used : AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) BasicAuthenticationClient(co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient) Properties(java.util.Properties)

Example 2 with AuthenticationClient

use of co.cask.cdap.security.authentication.client.AuthenticationClient in project cdap-ingest by caskdata.

the class StreamClientIT method getTestClient.

private StreamClient getTestClient() throws IOException {
    Properties properties = getProperties(System.getProperty(CONFIG_NAME));
    RestStreamClient.Builder clientBuilder = RestStreamClient.builder(properties.getProperty("host"), Integer.valueOf(properties.getProperty("port")));
    clientBuilder.ssl(Boolean.valueOf(properties.getProperty("ssl", "false")));
    clientBuilder.verifySSLCert(Boolean.valueOf(properties.getProperty("verify.ssl.cert", "false")));
    clientBuilder.version(properties.getProperty("version", "v2"));
    clientBuilder.writerPoolSize(Integer.valueOf(properties.getProperty("writerPoolSize", "10")));
    if (properties.getProperty("host") != null) {
        AuthenticationClient client = new BasicAuthenticationClient();
        client.setConnectionInfo(properties.getProperty("host"), Integer.valueOf(properties.getProperty("port")), Boolean.valueOf(properties.getProperty("ssl", "false")));
        String authProperties = properties.getProperty("auth_properties");
        if (authProperties != null) {
            Properties authClientProperties = getProperties(authProperties);
            client.configure(authClientProperties);
            clientBuilder.authClient(client);
        }
    }
    return clientBuilder.build();
}
Also used : BasicAuthenticationClient(co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient) RestStreamClient(co.cask.cdap.client.rest.RestStreamClient) Properties(java.util.Properties) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) BasicAuthenticationClient(co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient)

Example 3 with AuthenticationClient

use of co.cask.cdap.security.authentication.client.AuthenticationClient in project cdap-ingest by caskdata.

the class RestStreamClientTest method testSuccessAuthTruncate.

@Test
public void testSuccessAuthTruncate() throws IOException {
    AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
    AccessToken accessToken = Mockito.mock(AccessToken.class);
    Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
    Mockito.when(accessToken.getValue()).thenReturn(AUTH_TOKEN);
    Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
    streamClient = RestStreamClient.builder(testServerHost, testServerPort).authClient(authClient).build();
    streamClient.truncate(TestUtils.SUCCESS_STREAM_NAME);
}
Also used : AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) Test(org.junit.Test)

Example 4 with AuthenticationClient

use of co.cask.cdap.security.authentication.client.AuthenticationClient in project cdap-ingest by caskdata.

the class RestStreamWriterTest method testNotAuthorizedEmptyTokenStringWrite.

@Test
public void testNotAuthorizedEmptyTokenStringWrite() throws IOException, InterruptedException {
    AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
    AccessToken accessToken = Mockito.mock(AccessToken.class);
    Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
    Mockito.when(accessToken.getValue()).thenReturn(StringUtils.EMPTY);
    Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
    streamClient = RestStreamClient.builder(testServerHost, testServerPort).authClient(authClient).build();
    streamWriter = streamClient.createWriter(TestUtils.AUTH_STREAM_NAME + TestUtils.WRITER_TEST_STREAM_NAME_POSTFIX);
    try {
        streamWriter.write(RestTest.EXPECTED_WRITER_CONTENT, Charsets.UTF_8).get();
    } catch (ExecutionException e) {
        assertEquals(HttpFailureException.class, e.getCause().getClass());
    }
}
Also used : HttpFailureException(co.cask.cdap.common.http.exception.HttpFailureException) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 5 with AuthenticationClient

use of co.cask.cdap.security.authentication.client.AuthenticationClient in project cdap-ingest by caskdata.

the class RestStreamWriterTest method testNotAuthorizedUnknownTokenStringWrite.

@Test
public void testNotAuthorizedUnknownTokenStringWrite() throws IOException, InterruptedException {
    AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
    AccessToken accessToken = Mockito.mock(AccessToken.class);
    Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
    Mockito.when(accessToken.getValue()).thenReturn("test");
    Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
    streamClient = RestStreamClient.builder(testServerHost, testServerPort).authClient(authClient).build();
    streamWriter = streamClient.createWriter(TestUtils.AUTH_STREAM_NAME + TestUtils.WRITER_TEST_STREAM_NAME_POSTFIX);
    try {
        streamWriter.write(RestTest.EXPECTED_WRITER_CONTENT, Charsets.UTF_8).get();
    } catch (ExecutionException e) {
        assertEquals(HttpFailureException.class, e.getCause().getClass());
    }
}
Also used : HttpFailureException(co.cask.cdap.common.http.exception.HttpFailureException) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

AuthenticationClient (co.cask.cdap.security.authentication.client.AuthenticationClient)21 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)16 Test (org.junit.Test)15 HttpFailureException (co.cask.cdap.common.http.exception.HttpFailureException)10 BasicAuthenticationClient (co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient)5 Properties (java.util.Properties)4 RestStreamClient (co.cask.cdap.client.rest.RestStreamClient)2 ExecutionException (java.util.concurrent.ExecutionException)2 StreamClient (co.cask.cdap.client.StreamClient)1 ConnectionConfig (co.cask.cdap.client.config.ConnectionConfig)1 UnauthenticatedException (co.cask.cdap.common.UnauthenticatedException)1 Credential (co.cask.cdap.security.authentication.client.Credential)1 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ConsoleReader (jline.console.ConsoleReader)1