Java Code Examples for hudson.util.Secret#toString()

The following examples show how to use hudson.util.Secret#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AxivionSuite.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
private UsernamePasswordCredentials withValidCredentials() {
    final List<StandardUsernamePasswordCredentials> all =
            CredentialsProvider.lookupCredentials(
                    StandardUsernamePasswordCredentials.class,
                    (Item) null,
                    ACL.SYSTEM,
                    Collections.emptyList());

    StandardUsernamePasswordCredentials jenkinsCredentials =
            CredentialsMatchers.firstOrNull(all,
                    CredentialsMatchers.withId(credentialsId));

    if (jenkinsCredentials == null) {
        throw new ParsingException("Could not find the credentials for " + credentialsId);
    }

    return new UsernamePasswordCredentials(
            jenkinsCredentials.getUsername(),
            Secret.toString(jenkinsCredentials.getPassword()));
}
 
Example 2
Source File: JiraClientFactoryImpl.java    From jira-ext-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public JiraClient newJiraClient()
{
    Config.PluginDescriptor config = Config.getGlobalConfig();
    String jiraUrl = config.getJiraBaseUrl();
    String username = config.getUsername();
    String password = Secret.toString(config.getPassword());

    BasicCredentials creds = new BasicCredentials(username, password);
    JiraClient client = new JiraClient(jiraUrl, creds);
    DefaultHttpClient httpClient = (DefaultHttpClient)client.getRestClient().getHttpClient();
    int timeoutInSeconds = config.getTimeout();
    HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), timeoutInSeconds * 1000);
    HttpConnectionParams.setSoTimeout(httpClient.getParams(), timeoutInSeconds * 1000);
    return client;
}
 
Example 3
Source File: AWSDeviceFarmRecorder.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Refresh button clicked, clear the project and device pool caches
 * so the next click on the drop-down will get fresh content from the API.
 *
 * @return Whether or not the form was ok.
 */
@SuppressWarnings("unused")
public FormValidation doRefresh() {
    String skid = Secret.toString(this.skid);
    String akid = Secret.toString(this.akid);
    if (roleArn != null && !roleArn.isEmpty() && akid != null && !akid.isEmpty() && skid != null && !skid.isEmpty()) {
        return FormValidation.error("AWS Device Farm IAM Role ARN *OR* AKID/SKID must be set!");
    }

    // Clear local caches
    projectsCache.clear();
    poolsCache.clear();
    vpceCache.clear();
    testSpecCache.clear();
    return FormValidation.ok();
}
 
Example 4
Source File: ServerKeyMaterialFactory.java    From docker-commons-plugin with MIT License 5 votes vote down vote up
public ServerKeyMaterialFactory(@CheckForNull final DockerServerCredentials credentials) {
    if (credentials != null) {
        key = Secret.toString(credentials.getClientKeySecret());
        cert = credentials.getClientCertificate();
        ca = credentials.getServerCaCertificate();
    } else {
        key = null;
        cert = null;
        ca = null;
    }
}
 
Example 5
Source File: AWSDeviceFarmRecorder.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Validate top level configuration values.
 *
 * @param log Destination Task Log
 * @return Whether or not the configuration is valid.
 */
private boolean validateConfiguration(@Nonnull PrintStream log) {
    String roleArn = getRoleArn();
    String akid = Secret.toString(getAkid());
    String skid = Secret.toString(getSkid());

    // [Required]: Auth Credentials
    if ((roleArn == null || roleArn.isEmpty()) && (akid == null || akid.isEmpty() || skid == null || skid.isEmpty())) {
        writeToLog(log, "Either IAM Role ARN or AKID/SKID must be set.");
        return false;
    }

    // [Required]: Project
    if (projectName == null || projectName.isEmpty()) {
        writeToLog(log, "Project must be set.");
        return false;
    }
    // [Required]: DevicePool
    if (devicePoolName == null || devicePoolName.isEmpty()) {
        writeToLog(log, "DevicePool must be set.");
        return false;
    }
    // [Required]: App Artifact
    if (!ifWebApp && (appArtifact == null || appArtifact.isEmpty())) {
        writeToLog(log, "Application Artifact must be set.");
        return false;
    }
    // [Required]: At least one test.
    if (testToRun == null || stringToTestType(testToRun) == null) {
        writeToLog(log, "A test type must be set.");
        return false;
    }
    return true;
}
 
Example 6
Source File: AWSDeviceFarmRecorder.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns Custom device farm instance based on the params provided.
 * @param roleArn the role arn
 * @param akid the access key
 * @param skid the secret key
 * @return the AWSDeviceFarm instance
 */
private AWSDeviceFarm getDeviceFarmInstance(final String roleArn,
                                            final Secret akid,
                                            final Secret skid) {
    AWSDeviceFarm adf;
    if (roleArn == null || roleArn.isEmpty()) {
        return new AWSDeviceFarm(new BasicAWSCredentials(Secret.toString(akid), Secret.toString(skid)));
    } else {
        return new AWSDeviceFarm(roleArn);
    }
}
 
Example 7
Source File: Zulip.java    From zulip-plugin with MIT License 5 votes vote down vote up
public Zulip(String url, String email, Secret apiKey) {
    super();
    if (url != null && url.length() > 0 && !url.endsWith("/") ) {
        url = url + "/";
    }
    this.url = url;
    this.email = email;
    this.apiKey = Secret.toString(apiKey);
}
 
Example 8
Source File: DescriptorImpl.java    From qy-wechat-notification-plugin with Apache License 2.0 4 votes vote down vote up
public String getProxyPassword() {
    return Secret.toString(config.proxyPassword);
}
 
Example 9
Source File: GlobalConfigDataForSonarInstance.java    From sonar-quality-gates-plugin with MIT License 4 votes vote down vote up
public String getPass() {
    return Secret.toString(secretPass);
}
 
Example 10
Source File: VaultTokenCredential.java    From hashicorp-vault-plugin with MIT License 4 votes vote down vote up
@Override
public String getToken(Vault vault) {
    return Secret.toString(token);
}
 
Example 11
Source File: GogsProjectProperty.java    From gogs-webhook-plugin with MIT License 4 votes vote down vote up
public String getGogsSecret() {
    return Secret.toString(gogsSecret);
}
 
Example 12
Source File: ServerKeyMaterialFactoryFromDockerCredentials.java    From docker-commons-plugin with MIT License 4 votes vote down vote up
@NonNull
@Override
public KeyMaterialFactory convert(@NonNull DockerServerCredentials credential) throws AuthenticationTokenException {
    return new ServerKeyMaterialFactory(Secret.toString(credential.getClientKeySecret()), credential.getClientCertificate(), credential.getServerCaCertificate());
}
 
Example 13
Source File: DockerServerCredentials.java    From docker-commons-plugin with MIT License 4 votes vote down vote up
/**
 * @deprecated use {@link #getClientKeySecret()}
 */
@CheckForNull
@Deprecated
public String getClientKey() {
    return Secret.toString(clientKey);
}
 
Example 14
Source File: DatadogHttpClient.java    From jenkins-datadog-plugin with MIT License 4 votes vote down vote up
/**
 * Posts a given {@link JSONObject} payload to the Datadog API, using the
 * user configured apiKey.
 *
 * @param payload - A JSONObject containing a specific subset of a builds metadata.
 * @param type    - A String containing the URL subpath pertaining to the type of API post required.
 * @return a boolean to signify the success or failure of the HTTP POST request.
 * @throws IOException if HttpURLConnection fails to open connection
 */
private boolean post(final JSONObject payload, final String type) {
    String urlParameters = "?api_key=" + Secret.toString(apiKey);
    HttpURLConnection conn = null;
    boolean status = true;

    try {
        logger.finer("Setting up HttpURLConnection...");
        conn = getHttpURLConnection(new URL(url
                + type
                + urlParameters));
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setUseCaches(false);
        conn.setDoInput(true);
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream(), "utf-8");
        logger.finer("Writing to OutputStreamWriter...");
        wr.write(payload.toString());
        wr.close();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
        StringBuilder result = new StringBuilder();
        String line;
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }
        rd.close();
        JSONObject json = (JSONObject) JSONSerializer.toJSON(result.toString());
        if ("ok".equals(json.getString("status"))) {
            logger.finer(String.format("API call of type '%s' was sent successfully!", type));
            logger.finer(String.format("Payload: %s", payload));
        } else {
            logger.fine(String.format("API call of type '%s' failed!", type));
            logger.fine(String.format("Payload: %s", payload));
            status = false;
        }
    } catch (Exception e) {
        try {
            if (conn != null && conn.getResponseCode() == HTTP_FORBIDDEN) {
                logger.severe("Hmmm, your API key may be invalid. We received a 403 error.");
            } else {
                logger.severe(String.format("Client error: %s", e.toString()));
            }
        } catch (IOException ex) {
            logger.severe(ex.toString());
        }
        status = false;
    } finally {
        if (conn != null) {
            conn.disconnect();
        }
    }
    return status;
}