Util method to find credential by id in jenkins

@param credentialsId credentials to find in jenkins
@return {@link CertificateCredentials} or {@link StandardUsernamePasswordCredentials} expected
180428
public static Credentials lookupSystemCredentials(String credentialsId) {
        return firstOrNull(
                lookupCredentials(
                        Credentials.class,
                        Jenkins.getInstance(),
                        ACL.SYSTEM,
                        emptyList()
                ),
                withId(credentialsId)
        );
    }
426926
public Maybe<ApplicationInfo> getApplicationInfo(String clientId) {
        return db.findClientCredentials(clientId).map(creds -> {
            ApplicationInfo appInfo = null;
            if (creds != null) {
                appInfo = ApplicationInfo.loadFromClientCredentials(creds);
            }
            return appInfo;
        });
    }
831398
public static CredentialsProvider newProxyCredentialsProvider
    (HttpClientSettings settings) {
        final CredentialsProvider provider = new BasicCredentialsProvider();
        provider.setCredentials(newAuthScope(settings), newNTCredentials(settings));
        return provider;
    }
907813
protected Single<Boolean> isValidClientCredentials(String clientId, String clientSecret) {
        return db.findClientCredentials(clientId)
                .map(creds -> creds.getSecret().equals(clientSecret))
                .switchIfEmpty(Single.just(false))
                ;
    }
707659
protected Authenticated getAuthObjFromServerId(final Settings settings, final String serverId) {
        if (StringUtils.isEmpty(serverId)) {
            getLog().debug(SERVER_ID_NOT_CONFIG);
            return null;
        }

        final Server server = Utils.getServer(settings, serverId);
        try {
            assureServerExist(server, serverId);
        } catch (MojoExecutionException ex) {
            getLog().error(ex.getMessage());
            return null;
        }

        final ApplicationTokenCredentials credential = getAppTokenCredentialsFromServer(server);
        if (credential == null) {
            getLog().error(AZURE_AUTH_INVALID + serverId);
            return null;
        }

        final Authenticated auth = azureConfigure().authenticate(credential);
        if (auth != null) {
            getLog().info(AUTH_WITH_SERVER_ID + serverId);
        }
        return auth;
    }
1225420
public static DefaultAuthenticationTransaction of(final Service service, final Credential... credentials) {
        val creds = sanitizeCredentials(credentials);
        return new DefaultAuthenticationTransaction(service, creds);
    }
640679
public OvhCredential api_credential_credentialId_GET(Long credentialId) throws IOException {
		String qPath = "/me/api/credential/{credentialId}";
		StringBuilder sb = path(qPath, credentialId);
		String resp = exec(qPath, "GET", sb.toString(), null);
		return convertTo(resp, OvhCredential.class);
	}
493453
public GitRepositoryBuilder credentialProvider(final String username, final String password) {
        if (StringUtils.hasText(username)) {
            this.credentialsProviders.add(new UsernamePasswordCredentialsProvider(username, password));
        }
        return this;
    }
537435
public ClientBuilderForConnector withCredentialsId(String credentialsId)
            throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
        if (isNotBlank(credentialsId)) {
            withCredentials(lookupSystemCredentials(credentialsId));
        } else {
            withSslConfig(null);
        }

        return this;
    }
986652
@Override
    protected final Principal getPrincipal(final Credentials credentials) {
        try {
            Optional<Principal> principalOptional = cache.get(credentials.getApiKey(), new Callable<Optional<Principal>>() {
                public Optional<Principal> call() throws Exception {
                    return Optional.fromNullable(loadPrincipal(credentials));
                }
            });
            return principalOptional.orNull();
        } catch (ExecutionException e) {
            LOG.warn("Exception when loading the cache for credentials with API key " + credentials.getApiKey());
            return null;
        }
    }
507534
static ClientAssertion buildJwt(final AsymmetricKeyCredential credential,
            final String jwtAudience) throws AuthenticationException {
        if (credential == null) {
            throw new IllegalArgumentException("credential is null");
        }

        final long time = System.currentTimeMillis();

        final JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
                .audience(Collections.singletonList(jwtAudience))
                .issuer(credential.getClientId())
                .jwtID(UUID.randomUUID().toString())
                .notBeforeTime(new Date(time))
                .expirationTime(new Date(time
                                + AuthenticationConstants.AAD_JWT_TOKEN_LIFETIME_SECONDS
                                * 1000))
                .subject(credential.getClientId())
                .build();

        SignedJWT jwt;
        try {
            JWSHeader.Builder builder = new Builder(JWSAlgorithm.RS256);
            List<Base64> certs = new ArrayList<Base64>();
            certs.add(new Base64(credential.getPublicCertificate()));
            builder.x509CertChain(certs);
            builder.x509CertThumbprint(new Base64URL(credential
                    .getPublicCertificateHash()));
            jwt = new SignedJWT(builder.build(), claimsSet);
            final RSASSASigner signer = new RSASSASigner(credential.getKey());

            jwt.sign(signer);
        }
        catch (final Exception e) {
            throw new AuthenticationException(e);
        }

        return new ClientAssertion(jwt.serialize());
    }
52155
public Credentials toGrgit() {
        if (username != null && password != null) {
            return new Credentials(username, password);
        } else {
            return null;
        }
    }
174736
public static void bindCurrent(final Credential... credentials) {
        CURRENT_CREDENTIAL_IDS.set(Arrays.stream(credentials).map(Credential::getId).toArray(String[]::new));
    }
708316
protected Credential getCredential(HttpServletRequest req) {
    Credential cred = (Credential) req.getAttribute(AUTH_CREDENTIAL);
    return cred;
  }
588585
public static AWSCredentialsProvider getInstance(final String credentialAccessKey, final String credentialSecretKey,
                                                     final Resource credentialPropertiesFile) {
        return getInstance(credentialAccessKey, credentialSecretKey, credentialPropertiesFile, null, null);
    }
199280
@Beta
    public MSICredentials withIdentityId(String identityId) {
        this.identityId = identityId;
        this.clientId = null;
        this.objectId = null;
        return this;
    }
983901
public static BasicCredential buildCredentialForMetadataSignatureValidation(final Resource resource) throws Exception {
        try {
            val x509FactoryBean = new BasicX509CredentialFactoryBean();
            x509FactoryBean.setCertificateResource(resource);
            x509FactoryBean.afterPropertiesSet();
            return x509FactoryBean.getObject();
        } catch (final Exception e) {
            LOGGER.trace(e.getMessage(), e);

            LOGGER.debug("Credential cannot be extracted from [{}] via X.509. Treating it as a public key to locate credential...", resource);
            val credentialFactoryBean = new BasicResourceCredentialFactoryBean();
            credentialFactoryBean.setPublicKeyInfo(resource);
            credentialFactoryBean.afterPropertiesSet();
            return credentialFactoryBean.getObject();
        }
    }