use of co.cask.cdap.security.authentication.client.AuthenticationClient in project cdap by caskdata.
the class CLIConfig method getAuthenticationClient.
private AuthenticationClient getAuthenticationClient(ConnectionConfig connectionInfo) {
AuthenticationClient authenticationClient = new BasicAuthenticationClient();
authenticationClient.setConnectionInfo(connectionInfo.getHostname(), connectionInfo.getPort(), connectionInfo.isSSLEnabled());
return authenticationClient;
}
use of co.cask.cdap.security.authentication.client.AuthenticationClient in project cdap by caskdata.
the class CLIConfig method getNewAccessToken.
private UserAccessToken getNewAccessToken(ConnectionConfig connectionInfo, PrintStream output, boolean debug) throws IOException {
AuthenticationClient authenticationClient = getAuthenticationClient(connectionInfo);
Properties properties = new Properties();
properties.put(BasicAuthenticationClient.VERIFY_SSL_CERT_PROP_NAME, String.valueOf(clientConfig.isVerifySSLCert()));
String username = "";
// obtain new access token via manual user input
output.printf("Authentication is enabled in the CDAP instance: %s.\n", connectionInfo.getHostname());
ConsoleReader reader = new ConsoleReader();
for (Credential credential : authenticationClient.getRequiredCredentials()) {
String prompt = "Please, specify " + credential.getDescription() + "> ";
String credentialValue;
if (credential.isSecret()) {
credentialValue = reader.readLine(prompt, '*');
} else {
credentialValue = reader.readLine(prompt);
}
properties.put(credential.getName(), credentialValue);
if (credential.getName().contains("username")) {
username = credentialValue;
}
}
authenticationClient.configure(properties);
AccessToken accessToken = authenticationClient.getAccessToken();
UserAccessToken userToken = new UserAccessToken(accessToken, username);
if (accessToken != null) {
if (saveAccessToken(userToken, connectionInfo.getHostname()) && debug) {
output.printf("Saved access token to %s\n", getAccessTokenFile(connectionInfo.getHostname()).getAbsolutePath());
}
}
return userToken;
}
use of co.cask.cdap.security.authentication.client.AuthenticationClient in project cdap-ingest by caskdata.
the class CdapFlumeIT method createStream.
private void createStream() throws Exception {
RestStreamClient.Builder builder = RestStreamClient.builder(streamReader.getCdapHost(), streamReader.getCdapPort()).ssl(streamReader.getSsl());
if (streamReader.getAuthClientPropertiesPath() != null) {
AuthenticationClient authClient = streamReader.createAuthClient();
builder.authClient(authClient);
}
StreamClient streamClient = builder.build();
streamClient.create(streamName);
}
use of co.cask.cdap.security.authentication.client.AuthenticationClient in project cdap-ingest by caskdata.
the class RestStreamClientTest method testNotAuthorizedUnknownTokenSetTTL.
@Test
public void testNotAuthorizedUnknownTokenSetTTL() 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.setTTL(TestUtils.AUTH_STREAM_NAME, STREAM_TTL);
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 testNotAuthorizedEmptyTokenTruncate.
@Test
public void testNotAuthorizedEmptyTokenTruncate() 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.truncate(TestUtils.AUTH_STREAM_NAME);
Assert.fail("Expected HttpFailureException");
} catch (HttpFailureException e) {
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
}
}
Aggregations