/** * {@inheritDoc} */ @Override public void exitExpression(CQLParser.ExpressionContext ctx) { if (ctx.AND() != null) { CredentialsMatcher second = expression.pop(); CredentialsMatcher first = expression.pop(); expression.push(CredentialsMatchers.allOf(first, second)); } else if (ctx.OR() != null) { CredentialsMatcher second = expression.pop(); CredentialsMatcher first = expression.pop(); expression.push(CredentialsMatchers.anyOf(first, second)); } else { expression.push(primary); } }
/** * {@inheritDoc} */ @Override public void exitExpression(CQLParser.ExpressionContext ctx) { if (ctx.AND() != null) { CredentialsMatcher second = expression.pop(); CredentialsMatcher first = expression.pop(); expression.push(CredentialsMatchers.allOf(first, second)); } else if (ctx.OR() != null) { CredentialsMatcher second = expression.pop(); CredentialsMatcher first = expression.pop(); expression.push(CredentialsMatchers.anyOf(first, second)); } else { expression.push(primary); } }
private <T extends StandardCredentials> T credentials(AbstractGitSCMSource source, @Nonnull Class<T> type) { String credentialsId = source.getCredentialsId(); if (credentialsId == null) { return null; } return CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials( type, source.getOwner(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), CredentialsMatchers.allOf( CredentialsMatchers.withId(credentialsId), CredentialsMatchers.instanceOf(type))); } }
private static AmazonWebServicesCredentials lookupNamedCredential(String credentialsId) throws CredentialNotFoundException { List<AmazonWebServicesCredentials> credentialList = CredentialsProvider.lookupCredentials( AmazonWebServicesCredentials.class, Jenkins.get(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()); AmazonWebServicesCredentials cred = CredentialsMatchers.firstOrNull(credentialList, CredentialsMatchers.allOf( CredentialsMatchers.withId(credentialsId))); if (cred == null) { throw new CredentialNotFoundException(credentialsId); } return cred; }
private StandardUsernamePasswordCredentials getCredentials(String credentialsId) { if (null == credentialsId) return null; return CredentialsMatchers .firstOrNull( CredentialsProvider.lookupCredentials( StandardUsernamePasswordCredentials.class, (Item) null, ACL.SYSTEM, (DomainRequirement) null ), CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId), instanceOf(UsernamePasswordCredentials.class)) ); } }
/** * Resolves the specified scan credentials in the specified context for use against the specified API endpoint. * * @param context the context. * @param apiUri the API endpoint. * @param scanCredentialsId the credentials to resolve. * @return the {@link StandardCredentials} or {@code null} */ @CheckForNull public static StandardCredentials lookupScanCredentials(@CheckForNull Item context, @CheckForNull String apiUri, @CheckForNull String scanCredentialsId) { if (Util.fixEmpty(scanCredentialsId) == null) { return null; } else { return CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( StandardUsernameCredentials.class, context, context instanceof Queue.Task ? Tasks.getDefaultAuthenticationOf((Queue.Task) context) : ACL.SYSTEM, githubDomainRequirements(apiUri) ), CredentialsMatchers.allOf(CredentialsMatchers.withId(scanCredentialsId), githubScanCredentialsMatcher()) ); } }
private StandardUsernameCredentials retrieveExistingCredentials(final String username, final String privkey) { return CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, Jenkins.getInstance(), ACL.SYSTEM, SSHLauncher.SSH_SCHEME), CredentialsMatchers.allOf( CredentialsMatchers.withUsername(username), new CredentialsMatcher() { public boolean matches(Credentials item) { for (String key : SSHUserPrivateKey.class.cast(item).getPrivateKeys()) { if (pemKeyEquals(key, privkey)) { return true; } } return false; } })); }
/** * Plugins that want to refer to a {@link IdCredentials} should do so via ID string, * and use this method to resolve it and convert to {@link DockerRegistryToken}. * * @param context * If you are a build step trying to access DockerHub in the context of a build/job, * specify that job. Otherwise null. If you are scoped to something else, you might * have to interact with {@link CredentialsProvider} directly. */ public @CheckForNull DockerRegistryToken getToken(Item context) { if (credentialsId == null) { return null; } // as a build step, your access to credentials are constrained by what the build // can access, hence Jenkins.getAuthentication() List<DomainRequirement> requirements = Collections.emptyList(); try { requirements = Collections.<DomainRequirement>singletonList(new HostnameRequirement(getEffectiveUrl().getHost())); } catch (IOException e) { // shrug off this error and move on. We are matching with ID anyway. } // look for subtypes that know how to create a token, such as Google Container Registry return AuthenticationTokens.convert(DockerRegistryToken.class, firstOrNull(CredentialsProvider.lookupCredentials( IdCredentials.class, context, Jenkins.getAuthentication(),requirements), allOf(AuthenticationTokens.matcher(DockerRegistryToken.class), withId(credentialsId)))); }
/** * Populate the credentials dropdown box * @return A ListBoxModel containing all global credentials */ public ListBoxModel doFillCredentialsIdItems() { return new StandardListBoxModel() .withEmptySelection() .withMatching( CredentialsMatchers.allOf(CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class)), CredentialsProvider.lookupCredentials(StandardCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()) ); } }
public static Credentials credentialsLookup(String credentialsId, Item item) { UsernamePasswordCredentials usernamePasswordCredentials = CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( UsernamePasswordCredentials.class, item, ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId)) ); if (usernamePasswordCredentials != null) { return new Credentials(usernamePasswordCredentials.getUsername(), usernamePasswordCredentials.getPassword().getPlainText()); } return Credentials.EMPTY_CREDENTIALS; }
public static Optional<StandardCredentials> findCredentials( Item item, String credentialsId, String uri) { if (isNullOrEmpty(credentialsId)) { return absent(); } return fromNullable( CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( StandardCredentials.class, item, item instanceof Queue.Task ? Tasks.getAuthenticationOf((Queue.Task) item) : ACL.SYSTEM, URIRequirementBuilder.fromUri(uri).build()), CredentialsMatchers.allOf( CredentialsMatchers.withId(credentialsId), CredentialsMatchers.anyOf( CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class), CredentialsMatchers.instanceOf(StringCredentials.class))))); }
private StandardUsernamePasswordCredentials getCredentials() { Authentication defaultAuth = null; if (job instanceof Queue.Task) { defaultAuth = Tasks.getDefaultAuthenticationOf((Queue.Task)this.job); } return CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( StandardUsernamePasswordCredentials.class, this.job, defaultAuth, URIRequirementBuilder.fromUri(stashHost).build() ), CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId))); }
private static StandardUsernameCredentials retrieveExistingCredentials(String username, final Secret password, String privatekey) { final String privatekeyContent = getPrivateKeyContent(password, privatekey); return CredentialsMatchers.firstOrNull(CredentialsProvider .lookupCredentials(StandardUsernameCredentials.class, Hudson.getInstance(), ACL.SYSTEM, SSH_SCHEME), allOf( withUsername(username), new CredentialsMatcher() { public boolean matches(@NonNull Credentials item) { if (item instanceof StandardUsernamePasswordCredentials && password != null && StandardUsernamePasswordCredentials.class.cast(item).getPassword().equals(password)) { return true; } if (privatekeyContent != null && item instanceof SSHUserPrivateKey) { for (String key : SSHUserPrivateKey.class.cast(item).getPrivateKeys()) { if (pemKeyEquals(key, privatekeyContent)) { return true; } } } return false; } })); }
private static StandardUsernameCredentials retrieveExistingCredentials(String username, final Secret password, String privatekey) { final String privatekeyContent = getPrivateKeyContent(password, privatekey); return CredentialsMatchers.firstOrNull(CredentialsProvider .lookupCredentials(StandardUsernameCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, SSH_SCHEME), allOf( withUsername(username), new CredentialsMatcher() { public boolean matches(@NonNull Credentials item) { if (item instanceof StandardUsernamePasswordCredentials && password != null && StandardUsernamePasswordCredentials.class.cast(item).getPassword().equals(password)) { return true; } if (privatekeyContent != null && item instanceof SSHUserPrivateKey) { for (String key : SSHUserPrivateKey.class.cast(item).getPrivateKeys()) { if (pemKeyEquals(key, privatekeyContent)) { return true; } } } return false; } })); }
/** * Looks up the {@link StandardCredentials} to use for auto-management of hooks. * * @return the credentials or {@code null}. */ @CheckForNull public StandardCredentials credentials() { return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( StandardCredentials.class, Jenkins.getActiveInstance(), ACL.SYSTEM, URIRequirementBuilder.fromUri(serverUrl).build() ), CredentialsMatchers.allOf( AuthenticationTokens.matcher(GiteaAuth.class), CredentialsMatchers.withId(credentialsId) ) ); }
public StandardCredentials credentials(SCMSourceOwner owner) { return CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( StandardCredentials.class, owner, Jenkins.getAuthentication(), URIRequirementBuilder.fromUri(serverUrl).build() ), CredentialsMatchers.allOf( AuthenticationTokens.matcher(GiteaAuth.class), CredentialsMatchers.withId(credentialsId) ) ); }
public StandardCredentials credentials() { return CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( StandardCredentials.class, getOwner(), Jenkins.getAuthentication(), URIRequirementBuilder.fromUri(serverUrl).build() ), CredentialsMatchers.allOf( AuthenticationTokens.matcher(GiteaAuth.class), CredentialsMatchers.withId(credentialsId) ) ); }
@CheckForNull protected StandardUsernameCredentials getCredentials() { String credentialsId = getCredentialsId(); if (credentialsId == null) { return null; } return CredentialsMatchers .firstOrNull( CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, getOwner(), ACL.SYSTEM, URIRequirementBuilder.fromUri(getRemote()).build()), CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId), GitClient.CREDENTIALS_MATCHER)); }
private SVNRepositoryView openSession(SVNURL repoURL) throws SVNException, IOException { return new SVNRepositoryView(repoURL, credentialsId == null ? null : CredentialsMatchers .firstOrNull(CredentialsProvider.lookupCredentials(StandardCredentials.class, getOwner(), ACL.SYSTEM, URIRequirementBuilder.fromUri(repoURL.toString()).build()), CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId), CredentialsMatchers.anyOf(CredentialsMatchers.instanceOf(StandardCredentials.class), CredentialsMatchers.instanceOf(SSHUserPrivateKey.class))))); }
@Override public SCMFileSystem build(Item owner, SCM scm, SCMRevision rev) throws IOException, InterruptedException { if (rev != null && !(rev instanceof SubversionSCMSource.SCMRevisionImpl)) { return null; } try { SubversionSCM svn = (SubversionSCM) scm; ModuleLocation moduleLocation = svn.getLocations()[0]; StandardCredentials credentials = null; SVNURL repoURL = moduleLocation.getSVNURL(); if (moduleLocation.credentialsId != null) { credentials = CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(StandardCredentials.class, owner, ACL.SYSTEM, URIRequirementBuilder.fromUri(repoURL.toString()).build()), CredentialsMatchers.allOf(CredentialsMatchers.withId(moduleLocation.credentialsId), CredentialsMatchers.anyOf(CredentialsMatchers.instanceOf(StandardCredentials.class), CredentialsMatchers.instanceOf(SSHUserPrivateKey.class)))); } SVNRepository repository = createRepository(repoURL, credentials); return new SubversionSCMFileSystem(repository, rev); } catch (SVNException e) { throw new IOException("failed to create SVNRepositoryView", e); } }