Search in sources :

Example 26 with AccessToken

use of co.cask.cdap.security.authentication.client.AccessToken in project cdap by caskdata.

the class IntegrationTestManager method getQueryClient.

@Override
public Connection getQueryClient(NamespaceId namespace) throws Exception {
    Map<String, String> connParams = new HashMap<>();
    connParams.put(ExploreConnectionParams.Info.NAMESPACE.getName(), namespace.getNamespace());
    AccessToken accessToken = clientConfig.getAccessToken();
    if (accessToken != null) {
        connParams.put(ExploreConnectionParams.Info.EXPLORE_AUTH_TOKEN.getName(), accessToken.getValue());
    }
    connParams.put(ExploreConnectionParams.Info.SSL_ENABLED.getName(), Boolean.toString(clientConfig.getConnectionConfig().isSSLEnabled()));
    connParams.put(ExploreConnectionParams.Info.VERIFY_SSL_CERT.getName(), Boolean.toString(clientConfig.isVerifySSLCert()));
    ConnectionConfig connConfig = clientConfig.getConnectionConfig();
    String url = String.format("%s%s:%d?%s", Constants.Explore.Jdbc.URL_PREFIX, connConfig.getHostname(), connConfig.getPort(), Joiner.on("&").withKeyValueSeparator("=").join(connParams));
    return new ExploreDriver().connect(url, new Properties());
}
Also used : ExploreDriver(co.cask.cdap.explore.jdbc.ExploreDriver) HashMap(java.util.HashMap) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) Properties(java.util.Properties) ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig)

Example 27 with AccessToken

use of co.cask.cdap.security.authentication.client.AccessToken in project cdap by caskdata.

the class RESTClientTest method testPutSuccessWithAccessToken.

@Test
public void testPutSuccessWithAccessToken() throws Exception {
    URL url = getBaseURI().resolve("/api/testPutAuth").toURL();
    HttpRequest request = HttpRequest.put(url).build();
    HttpResponse response = restClient.execute(request, new AccessToken(ACCESS_TOKEN, 82000L, "Bearer"));
    verifyResponse(response, only(200), any(), only("Access token received: " + ACCESS_TOKEN));
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL) Test(org.junit.Test)

Example 28 with AccessToken

use of co.cask.cdap.security.authentication.client.AccessToken in project cdap by caskdata.

the class RESTClientTest method testGetUnauthorizedWithAccessToken.

@Test(expected = UnauthenticatedException.class)
public void testGetUnauthorizedWithAccessToken() throws Exception {
    URL url = getBaseURI().resolve("/api/testGetAuth").toURL();
    HttpRequest request = HttpRequest.get(url).build();
    restClient.execute(request, new AccessToken("Unknown", 82000L, "Bearer"));
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) URL(java.net.URL) Test(org.junit.Test)

Example 29 with AccessToken

use of co.cask.cdap.security.authentication.client.AccessToken in project cdap by caskdata.

the class RESTClientTest method testDeleteForbidden.

@Test(expected = UnauthorizedException.class)
public void testDeleteForbidden() throws Exception {
    URL url = getBaseURI().resolve("/api/testDeleteForbidden").toURL();
    HttpRequest request = HttpRequest.delete(url).build();
    restClient.execute(request, new AccessToken("Unknown", 82000L, "Bearer"));
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) URL(java.net.URL) Test(org.junit.Test)

Example 30 with AccessToken

use of co.cask.cdap.security.authentication.client.AccessToken in project cdap by caskdata.

the class RESTClientTest method testPostSuccessWithAccessToken.

@Test
public void testPostSuccessWithAccessToken() throws Exception {
    URL url = getBaseURI().resolve("/api/testPostAuth").toURL();
    HttpRequest request = HttpRequest.post(url).build();
    HttpResponse response = restClient.execute(request, new AccessToken(ACCESS_TOKEN, 82000L, "Bearer"));
    verifyResponse(response, only(200), any(), only("Access token received: " + ACCESS_TOKEN));
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL) Test(org.junit.Test)

Aggregations

AccessToken (co.cask.cdap.security.authentication.client.AccessToken)34 Test (org.junit.Test)29 AuthenticationClient (co.cask.cdap.security.authentication.client.AuthenticationClient)16 URL (java.net.URL)15 HttpRequest (co.cask.common.http.HttpRequest)13 HttpFailureException (co.cask.common.http.exception.HttpFailureException)10 HttpResponse (co.cask.common.http.HttpResponse)6 ConnectionConfig (co.cask.cdap.client.config.ConnectionConfig)2 IOException (java.io.IOException)2 Properties (java.util.Properties)2 ExecutionException (java.util.concurrent.ExecutionException)2 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)1 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)1 ClientConfig (co.cask.cdap.client.config.ClientConfig)1 BadRequestException (co.cask.cdap.common.BadRequestException)1 StreamNotFoundException (co.cask.cdap.common.StreamNotFoundException)1 UnauthenticatedException (co.cask.cdap.common.UnauthenticatedException)1 ExploreDriver (co.cask.cdap.explore.jdbc.ExploreDriver)1 Credential (co.cask.cdap.security.authentication.client.Credential)1 BasicAuthenticationClient (co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient)1