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