Example usage for javax.security.auth.login CredentialNotFoundException CredentialNotFoundException

List of usage examples for javax.security.auth.login CredentialNotFoundException CredentialNotFoundException

Introduction

In this page you can find the example usage for javax.security.auth.login CredentialNotFoundException CredentialNotFoundException.

Prototype

public CredentialNotFoundException(String msg) 

Source Link

Document

Constructs a CredentialNotFoundException with the specified detail message.

Usage

From source file:br.com.ingenieux.jenkins.plugins.awsebdeployment.AWSClientFactory.java

public static AmazonWebServicesCredentials lookupNamedCredential(String credentialsId)
        throws CredentialNotFoundException {
    List<AmazonWebServicesCredentials> credentialList = CredentialsProvider.lookupCredentials(
            AmazonWebServicesCredentials.class, Jenkins.getInstance(), ACL.SYSTEM,
            Collections.<DomainRequirement>emptyList());

    AmazonWebServicesCredentials cred = CredentialsMatchers.firstOrNull(credentialList,
            CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId)));

    if (cred == null) {
        throw new CredentialNotFoundException(credentialsId);
    }/*from  w w  w . ja  va  2 s . c o m*/
    return cred;
}

From source file:br.com.ingenieux.jenkins.plugins.codecommit.CodeCommitURLHelper.java

private Iterable<RepositoryUsernameReference> fetchCodeCommitRepositoryNames(GitSCM scm)
        throws CredentialNotFoundException {
    AWSCredentialsProvider credentials = new DefaultAWSCredentialsProviderChain();

    if (isNotBlank(credentialId)) {
        credentials = CredentialsFactory.getCredentials(credentialId);

        if (null == credentials)
            throw new CredentialNotFoundException(
                    "CredentialId '" + credentialId + "' specified but not found.");
    }/*from w ww . ja  va 2s. co  m*/

    Set<RepositoryUsernameReference> results = new LinkedHashSet<RepositoryUsernameReference>();

    for (RemoteConfig cfg : scm.getRepositories()) {
        for (URIish u : cfg.getURIs()) {
            final String repositoryUrl = u.toPrivateASCIIString();
            final Matcher m = PATTERN_CODECOMMIT_REPO.matcher(repositoryUrl);

            if (m.matches()) {
                final String awsRegion = m.group(1);
                final String repositoryName = m.group(2);

                String usernamePassword = new CodeCommitRequestSigner(credentials, repositoryName, awsRegion,
                        new Date()).getPushUrl();

                int lastIndex = usernamePassword.lastIndexOf(':');

                String username = usernamePassword.substring(0, lastIndex);

                String password = usernamePassword.substring(1 + lastIndex);

                results.add(new RepositoryUsernameReference(repositoryUrl, repositoryName, username, password));
            }
        }
    }

    return results;
}