Search in sources :

Example 6 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 7 with AuthenticationClient

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

the class RestStreamClientTest method testSuccessAuthGetTTL.

@Test
public void testSuccessAuthGetTTL() 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");
    createClient(authClient);
    long ttl = streamClient.getTTL(TestUtils.SUCCESS_STREAM_NAME);
    assertTrue(ttl == STREAM_TTL);
}
Also used : AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) Test(org.junit.Test)

Example 8 with AuthenticationClient

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

the class RestStreamClientTest method testNotAuthorizedUnknownTokenCreate.

@Test
public void testNotAuthorizedUnknownTokenCreate() 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("test");
    Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
    createClient(authClient);
    try {
        streamClient.create(TestUtils.AUTH_STREAM_NAME);
        Assert.fail("Expected HttpFailureException");
    } catch (HttpFailureException e) {
        Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
    }
}
Also used : HttpFailureException(co.cask.common.http.exception.HttpFailureException) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) Test(org.junit.Test)

Example 9 with AuthenticationClient

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

the class RestStreamClientTest method testNotAuthorizedEmptyTokenGetTTL.

@Test
public void testNotAuthorizedEmptyTokenGetTTL() 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(StringUtils.EMPTY);
    Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
    createClient(authClient);
    try {
        streamClient.getTTL(TestUtils.AUTH_STREAM_NAME);
        Assert.fail("Expected HttpFailureException");
    } catch (HttpFailureException e) {
        Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
    }
}
Also used : HttpFailureException(co.cask.common.http.exception.HttpFailureException) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) Test(org.junit.Test)

Example 10 with AuthenticationClient

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

the class RestStreamClientTest method testNotAuthorizedEmptyTokenSetTTL.

@Test
public void testNotAuthorizedEmptyTokenSetTTL() 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(StringUtils.EMPTY);
    Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
    createClient(authClient);
    try {
        streamClient.setTTL(TestUtils.AUTH_STREAM_NAME, STREAM_TTL);
        Assert.fail("Expected HttpFailureException");
    } catch (HttpFailureException e) {
        Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
    }
}
Also used : HttpFailureException(co.cask.common.http.exception.HttpFailureException) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) Test(org.junit.Test)

Aggregations

AuthenticationClient (co.cask.cdap.security.authentication.client.AuthenticationClient)20 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)16 Test (org.junit.Test)15 HttpFailureException (co.cask.common.http.exception.HttpFailureException)10 BasicAuthenticationClient (co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient)4 Properties (java.util.Properties)3 ExecutionException (java.util.concurrent.ExecutionException)2 StreamClient (co.cask.cdap.client.StreamClient)1 ConnectionConfig (co.cask.cdap.client.config.ConnectionConfig)1 RestStreamClient (co.cask.cdap.client.rest.RestStreamClient)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