use of co.cask.cdap.security.authentication.client.AccessToken in project cdap-ingest by caskdata.
the class RestStreamClientTest method testSuccessAuthSetTTL.
@Test
public void testSuccessAuthSetTTL() 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);
streamClient.setTTL(TestUtils.SUCCESS_STREAM_NAME, STREAM_TTL);
}
use of co.cask.cdap.security.authentication.client.AccessToken in project cdap-ingest by caskdata.
the class RestStreamClientTest method testNotAuthorizedEmptyTokenCreate.
@Test
public void testNotAuthorizedEmptyTokenCreate() 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.create(TestUtils.AUTH_STREAM_NAME);
Assert.fail("Expected HttpFailureException");
} catch (HttpFailureException e) {
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
}
}
use of co.cask.cdap.security.authentication.client.AccessToken in project cdap-ingest by caskdata.
the class RestStreamClientTest method testSuccessAuthCreate.
@Test
public void testSuccessAuthCreate() 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);
streamClient.create(TestUtils.SUCCESS_STREAM_NAME);
}
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());
}
Aggregations