Java Code Examples for com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials#getUsername()

The following examples show how to use com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials#getUsername() . 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: GlobalKafkaConfiguration.java    From remoting-kafka-plugin with MIT License 5 votes vote down vote up
public String getKafkaUsername() throws RemotingKafkaConfigurationException {
    StandardUsernamePasswordCredentials credential = getCredential(kafkaCredentialsId);
    if (credential == null) {
        throw new RemotingKafkaConfigurationException("No Kafka credential provided");
    }
    return credential.getUsername();
}
 
Example 3
Source File: GlobalKafkaConfiguration.java    From remoting-kafka-plugin with MIT License 5 votes vote down vote up
public String getSSLTruststoreLocation() throws RemotingKafkaConfigurationException {
    StandardUsernamePasswordCredentials credential = getCredential(sslTruststoreCredentialsId);
    if (credential == null) {
        throw new RemotingKafkaConfigurationException("No SSL truststore credential provided");
    }
    return credential.getUsername();
}
 
Example 4
Source File: GlobalKafkaConfiguration.java    From remoting-kafka-plugin with MIT License 5 votes vote down vote up
public String getSSLKeystoreLocation() throws RemotingKafkaConfigurationException {
    StandardUsernamePasswordCredentials credential = getCredential(sslKeystoreCredentialsId);
    if (credential == null) {
        throw new RemotingKafkaConfigurationException("No SSL keystore credential provided");
    }
    return credential.getUsername();
}
 
Example 5
Source File: UsernamePasswordBinding.java    From credentials-binding-plugin with MIT License 5 votes vote down vote up
@Override public SingleEnvironment bindSingle(@Nonnull Run<?,?> build,
                                              @Nullable FilePath workspace,
                                              @Nullable Launcher launcher,
                                              @Nonnull TaskListener listener) throws IOException, InterruptedException {
    StandardUsernamePasswordCredentials credentials = getCredentials(build);
    return new SingleEnvironment(credentials.getUsername() + ':' + credentials.getPassword().getPlainText());
}
 
Example 6
Source File: BitbucketApi.java    From blueocean-plugin with MIT License 4 votes vote down vote up
protected BitbucketApi(@Nonnull String apiUrl, @Nonnull StandardUsernamePasswordCredentials credentials) {
    this.apiUrl = ensureTrailingSlash(apiUrl);
    this.request = new HttpRequest.HttpRequestBuilder(apiUrl).credentials(credentials).build();
    this.userName = credentials.getUsername();
}
 
Example 7
Source File: Connector.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
public static @Nonnull GitHub connect(@CheckForNull String apiUri, @CheckForNull StandardCredentials credentials) throws IOException {
    String apiUrl = Util.fixEmptyAndTrim(apiUri);
    apiUrl = apiUrl != null ? apiUrl : GitHubServerConfig.GITHUB_URL;
    String username;
    String password;
    String hash;
    String authHash;
    Jenkins jenkins = Jenkins.get();
    if (credentials == null) {
        username = null;
        password = null;
        hash = "anonymous";
        authHash = "anonymous";
    } else if (credentials instanceof StandardUsernamePasswordCredentials) {
        StandardUsernamePasswordCredentials c = (StandardUsernamePasswordCredentials) credentials;
        username = c.getUsername();
        password = c.getPassword().getPlainText();
        hash = Util.getDigestOf(password + SALT); // want to ensure pooling by credential
        authHash = Util.getDigestOf(password + "::" + jenkins.getLegacyInstanceId());
    } else {
        // TODO OAuth support
        throw new IOException("Unsupported credential type: " + credentials.getClass().getName());
    }
    synchronized (githubs) {
        Details details = new Details(apiUrl, hash);
        GitHub hub = githubs.get(details);
        if (hub != null) {
            Integer count = usage.get(hub);
            usage.put(hub, count == null ? 1 : Math.max(count + 1, 1));
            return hub;
        }

        Cache cache = getCache(jenkins, apiUrl, authHash, username);

        GitHubBuilder gb = createGitHubBuilder(apiUrl, cache);

        if (username != null) {
            gb.withPassword(username, password);
        }

        hub = gb.build();
        githubs.put(details, hub);
        usage.put(hub, 1);
        lastUsed.remove(hub);
        return hub;
    }
}