Search in sources :

Example 1 with AuthenticationClient

use of io.cdap.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() == null ? -1 : connectionInfo.getPort(), connectionInfo.isSSLEnabled());
    return authenticationClient;
}
Also used : BasicAuthenticationClient(io.cdap.cdap.security.authentication.client.basic.BasicAuthenticationClient) BasicAuthenticationClient(io.cdap.cdap.security.authentication.client.basic.BasicAuthenticationClient) AuthenticationClient(io.cdap.cdap.security.authentication.client.AuthenticationClient)

Example 2 with AuthenticationClient

use of io.cdap.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;
}
Also used : Credential(io.cdap.cdap.security.authentication.client.Credential) ConsoleReader(jline.console.ConsoleReader) AccessToken(io.cdap.cdap.security.authentication.client.AccessToken) BasicAuthenticationClient(io.cdap.cdap.security.authentication.client.basic.BasicAuthenticationClient) AuthenticationClient(io.cdap.cdap.security.authentication.client.AuthenticationClient) Properties(java.util.Properties)

Example 3 with AuthenticationClient

use of io.cdap.cdap.security.authentication.client.AuthenticationClient in project cdap by caskdata.

the class IntegrationTestBase method fetchAccessToken.

protected AccessToken fetchAccessToken(String username, String password) throws IOException, TimeoutException, InterruptedException {
    Properties properties = new Properties();
    properties.setProperty("security.auth.client.username", username);
    properties.setProperty("security.auth.client.password", password);
    properties.setProperty("security.auth.client.verify.ssl.cert", Boolean.toString(getClientConfig().isVerifySSLCert()));
    final AuthenticationClient authClient = new BasicAuthenticationClient();
    authClient.configure(properties);
    ConnectionConfig connectionConfig = getClientConfig().getConnectionConfig();
    authClient.setConnectionInfo(connectionConfig.getHostname(), connectionConfig.getPort(), connectionConfig.isSSLEnabled());
    checkServicesWithRetry(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return authClient.getAccessToken() != null;
        }
    }, "Unable to connect to Authentication service to obtain access token, Connection info : " + connectionConfig);
    return authClient.getAccessToken();
}
Also used : BasicAuthenticationClient(io.cdap.cdap.security.authentication.client.basic.BasicAuthenticationClient) Properties(java.util.Properties) BasicAuthenticationClient(io.cdap.cdap.security.authentication.client.basic.BasicAuthenticationClient) AuthenticationClient(io.cdap.cdap.security.authentication.client.AuthenticationClient) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) AccessException(io.cdap.cdap.api.security.AccessException) TimeoutException(java.util.concurrent.TimeoutException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) UnauthenticatedException(io.cdap.cdap.security.spi.authentication.UnauthenticatedException)

Aggregations

AuthenticationClient (io.cdap.cdap.security.authentication.client.AuthenticationClient)3 BasicAuthenticationClient (io.cdap.cdap.security.authentication.client.basic.BasicAuthenticationClient)3 Properties (java.util.Properties)2 AccessException (io.cdap.cdap.api.security.AccessException)1 ConnectionConfig (io.cdap.cdap.client.config.ConnectionConfig)1 AccessToken (io.cdap.cdap.security.authentication.client.AccessToken)1 Credential (io.cdap.cdap.security.authentication.client.Credential)1 UnauthenticatedException (io.cdap.cdap.security.spi.authentication.UnauthenticatedException)1 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ConsoleReader (jline.console.ConsoleReader)1