/** * Tries to find {@link StringCredentials} by id and returns secret from it. * * @param credentialsId id to find creds * * @return secret from creds or empty optional */ @Nonnull public static Optional<Secret> secretFor(String credentialsId) { List<StringCredentials> creds = filter( lookupCredentials(StringCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), withId(trimToEmpty(credentialsId)) ); return FluentIterableWrapper.from(creds) .transform(new NullSafeFunction<StringCredentials, Secret>() { @Override protected Secret applyNullSafe(@Nonnull StringCredentials input) { return input.getSecret(); } }).first(); }
public static StandardUsernamePasswordCredentials migrateCredentials(@Nonnull String username, String password, @CheckForNull URL url) { List<StandardUsernamePasswordCredentials> credentials = CredentialsMatchers.filter( CredentialsProvider.lookupCredentials( StandardUsernamePasswordCredentials.class,
final DomainRequirement domainRequirement = null; final List<StandardUsernamePasswordCredentials> credentials = CredentialsMatchers.filter( CredentialsProvider.lookupCredentials( StandardUsernamePasswordCredentials.class,
Jenkins jenkins = getJenkins(); List<StandardUsernamePasswordCredentials> credentials = CredentialsMatchers.filter(CredentialsProvider .lookupCredentials(StandardUsernamePasswordCredentials.class, jenkins, ACL.SYSTEM, domainRequirements), CredentialsMatchers.withUsername(principal)
@CheckForNull private static FormValidation checkForDuplicates(String value, ModelObject context, ModelObject object) { CredentialsMatcher withId = CredentialsMatchers.withId(value); for (CredentialsStore store : CredentialsProvider.lookupStores(object)) { if (!store.hasPermission(CredentialsProvider.VIEW)) { continue; } ModelObject storeContext = store.getContext(); for (Domain domain : store.getDomains()) { for (Credentials match : CredentialsMatchers.filter(store.getCredentials(domain), withId)) { if (storeContext == context) { return FormValidation.error("This ID is already in use"); } else { CredentialsScope scope = match.getScope(); if (scope != null && !scope.isVisible(context)) { // scope is not exported to child contexts continue; } return FormValidation.warning("The ID ‘%s’ is already in use in %s", value, storeContext instanceof Item ? ((Item) storeContext).getFullDisplayName() : storeContext.getDisplayName()); } } } } return null; }
@CheckForNull private static FormValidation checkForDuplicates(String value, ModelObject context, ModelObject object) { CredentialsMatcher withId = CredentialsMatchers.withId(value); for (CredentialsStore store : CredentialsProvider.lookupStores(object)) { if (!store.hasPermission(CredentialsProvider.VIEW)) { continue; } ModelObject storeContext = store.getContext(); for (Domain domain : store.getDomains()) { for (Credentials match : CredentialsMatchers.filter(store.getCredentials(domain), withId)) { if (storeContext == context) { return FormValidation.error("This ID is already in use"); } else { CredentialsScope scope = match.getScope(); if (scope != null && !scope.isVisible(context)) { // scope is not exported to child contexts continue; } return FormValidation.warning("The ID ‘%s’ is already in use in %s", value, storeContext instanceof Item ? ((Item) storeContext).getFullDisplayName() : storeContext.getDisplayName()); } } } } return null; }