Search in sources :

Example 1 with Credential

use of co.cask.cdap.security.authentication.client.Credential 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(co.cask.cdap.security.authentication.client.Credential) ConsoleReader(jline.console.ConsoleReader) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) BasicAuthenticationClient(co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient) Properties(java.util.Properties)

Aggregations

AccessToken (co.cask.cdap.security.authentication.client.AccessToken)1 AuthenticationClient (co.cask.cdap.security.authentication.client.AuthenticationClient)1 Credential (co.cask.cdap.security.authentication.client.Credential)1 BasicAuthenticationClient (co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient)1 Properties (java.util.Properties)1 ConsoleReader (jline.console.ConsoleReader)1