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;
}
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();
}
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);
}
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());
}
}
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());
}
}
Aggregations