public FormValidation doCheckCredentialsId(@AncestorInPath ItemGroup context, @QueryParameter String value) { AccessControlled _context = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (_context == null || !_context.hasPermission(Computer.CONFIGURE)) { return FormValidation.ok(); // no need to alarm a user that cannot configure } for (ListBoxModel.Option o : CredentialsProvider.listCredentials(StandardUsernameCredentials.class, context, ACL.SYSTEM, Collections.<DomainRequirement>singletonList(SSHLauncher.SSH_SCHEME), SSHAuthenticator.matcher(Connection.class))) { if (StringUtils.equals(value, o.value)) { return FormValidation.ok(); } } return FormValidation.error(Messages.SSHLauncher_SelectedCredentialsMissing()); }
public FormValidation doCheckCredentialsId(@AncestorInPath ItemGroup context, @QueryParameter String value) { AccessControlled _context = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (_context == null || !_context.hasPermission(Computer.CONFIGURE)) { return FormValidation.ok(); // no need to alarm a user that cannot configure } for (ListBoxModel.Option o : CredentialsProvider.listCredentials(StandardUsernameCredentials.class, context, ACL.SYSTEM, Collections.singletonList(SSHLauncher.SSH_SCHEME), SSHAuthenticator.matcher(Connection.class))) { if (StringUtils.equals(value, o.value)) { return FormValidation.ok(); } } return FormValidation.error(Messages.SSHLauncher_SelectedCredentialsMissing()); }
public FormValidation doCheckCredentialsId(@AncestorInPath ItemGroup context, @QueryParameter String host, @QueryParameter String port, @QueryParameter String value) { AccessControlled _context = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (_context == null || !_context.hasPermission(Computer.CONFIGURE)) { return FormValidation.ok(); // no need to alarm a user that cannot configure } try { int portValue = Integer.parseInt(port); for (ListBoxModel.Option o : CredentialsProvider .listCredentials(StandardUsernameCredentials.class, context, ACL.SYSTEM, Collections.<DomainRequirement>singletonList( new HostnamePortRequirement(host, portValue) ), SSHAuthenticator.matcher(Connection.class))) { if (StringUtils.equals(value, o.value)) { return FormValidation.ok(); } } } catch (NumberFormatException e) { return FormValidation.warning(e, Messages.SSHLauncher_PortNotANumber()); } return FormValidation.error(Messages.SSHLauncher_SelectedCredentialsMissing()); }
public FormValidation doCheckCredentialsId(@AncestorInPath ItemGroup context, @AncestorInPath AccessControlled _context, @QueryParameter String host, @QueryParameter String port, @QueryParameter String value) { Jenkins jenkins = Jenkins.getInstance(); if ((_context == jenkins && !jenkins.hasPermission(Computer.CREATE)) || (_context != jenkins && !_context.hasPermission(Computer.CONFIGURE))) { return FormValidation.ok(); // no need to alarm a user that cannot configure } try { int portValue = Integer.parseInt(port); for (ListBoxModel.Option o : CredentialsProvider .listCredentials(StandardUsernameCredentials.class, context, ACL.SYSTEM, Collections.singletonList( new HostnamePortRequirement(host, portValue) ), SSHAuthenticator.matcher(Connection.class))) { if (StringUtils.equals(value, o.value)) { return FormValidation.ok(); } } } catch (NumberFormatException e) { return FormValidation.warning(e, Messages.SSHLauncher_PortNotANumber()); } return FormValidation.error(Messages.SSHLauncher_SelectedCredentialsMissing()); }
public FormValidation doCheckCredentialsId(@CheckForNull @AncestorInPath Item item, @QueryParameter String credentialsId, @QueryParameter String serverUrl) { if (item == null) { if (!Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)) { return FormValidation.ok(); } } else if (!item.hasPermission(Item.EXTENDED_READ) && !item.hasPermission(CredentialsProvider.USE_ITEM)) { return FormValidation.ok(); } if (StringUtils.isBlank(credentialsId)) { return FormValidation.warning(Messages.NPMRegistry_DescriptorImpl_emptyCredentialsId()); } List<DomainRequirement> domainRequirement = URIRequirementBuilder.fromUri(serverUrl).build(); if (CredentialsProvider.listCredentials(StandardUsernameCredentials.class, item, getAuthentication(item), domainRequirement, CredentialsMatchers.withId(credentialsId)).isEmpty()) { return FormValidation.error(Messages.NPMRegistry_DescriptorImpl_invalidCredentialsId()); } return FormValidation.ok(); }
.listCredentials(StandardUsernameCredentials.class, project, project instanceof Queue.Task ? Tasks.getAuthenticationOf((Queue.Task) project) : ACL.SYSTEM,
for (ListBoxModel.Option o : CredentialsProvider.listCredentials( StandardUsernameCredentials.class, context,
return listCredentials(type, Jenkins.getInstance(), authentication, domainRequirements, matcher); return listCredentials(type, (ItemGroup) item, authentication, domainRequirements, matcher); LOGGER.log(Level.FINE, "Listing legacy credentials of type {0} identified by resolver {1}", new Object[]{type, resolver}); return listCredentials((Class) resolver.getFromClass(), item, authentication, domainRequirements, matcher);
return FormValidation.ok(); if (CredentialsProvider.listCredentials( StandardCredentials.class, context,
return FormValidation.ok(); if (CredentialsProvider.listCredentials( StandardCredentials.class, context,
return listCredentials(type, Jenkins.getInstance(), authentication, domainRequirements, matcher); return listCredentials(type, (ItemGroup) item, authentication, domainRequirements, matcher); LOGGER.log(Level.FINE, "Listing legacy credentials of type {0} identified by resolver {1}", new Object[]{type, resolver}); return listCredentials((Class) resolver.getFromClass(), item, authentication, domainRequirements, matcher);
/** * Adds the ids of the specified credential type that are available to the specified context as the specified * authentication with the specified domain requirements and match the specified filter. * * @param authentication the authentication to search with * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @param matcher the filter to apply to the credentials. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher) { addMissing(CredentialsProvider.listCredentials(type, context, authentication, domainRequirements, matcher)); return this; }
LOGGER.log(Level.FINE, "Listing legacy credentials of type {0} identified by resolver {1}", new Object[]{type, resolver}); return listCredentials((Class) resolver.getFromClass(), itemGroup, authentication, domainRequirements, matcher);
LOGGER.log(Level.FINE, "Listing legacy credentials of type {0} identified by resolver {1}", new Object[]{type, resolver}); return listCredentials((Class) resolver.getFromClass(), itemGroup, authentication, domainRequirements, matcher);
/** * Adds the ids of the specified credential type that are available to the specified context as the specified * authentication with the specified domain requirements and match the specified filter. * * @param authentication the authentication to search with * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @param matcher the filter to apply to the credentials. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, Item, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull Authentication authentication, @Nullable Item context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher) { addMissing(CredentialsProvider.listCredentials(type, context, authentication, domainRequirements, matcher)); return this; }
/** * Adds the ids of the specified credential type that are available to the specified context as the specified * authentication with the specified domain requirements and match the specified filter. * * @param authentication the authentication to search with * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @param matcher the filter to apply to the credentials. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher) { addMissing(CredentialsProvider.listCredentials(type, context, authentication, domainRequirements, matcher)); return this; }
/** * Adds the ids of the specified credential type that are available to the specified context as the specified * authentication with the specified domain requirements and match the specified filter. * * @param authentication the authentication to search with * @param context the context to add credentials from. * @param type the base class of the credentials to add. * @param domainRequirements the domain requirements. * @param matcher the filter to apply to the credentials. * @return {@code this} for method chaining. * @see CredentialsProvider#listCredentials(Class, ItemGroup, Authentication, List, CredentialsMatcher) * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull Authentication authentication, @NonNull ItemGroup context, @NonNull Class<? extends C> type, @NonNull List<DomainRequirement> domainRequirements, @NonNull CredentialsMatcher matcher) { addMissing(CredentialsProvider.listCredentials(type, context, authentication, domainRequirements, matcher)); return this; }
@Test public void credentialsListableAtFolderScope() throws Exception { Folder f = createFolder(); ListBoxModel asGroup = CredentialsProvider.listCredentials(StandardUsernamePasswordCredentials.class, (ItemGroup) f, ACL.SYSTEM, Collections.emptyList(), CredentialsMatchers.always()); ListBoxModel asItem = CredentialsProvider.listCredentials(StandardUsernamePasswordCredentials.class, (Item) f, ACL.SYSTEM, Collections.emptyList(), CredentialsMatchers.always()); assertThat(asGroup, is(asItem)); assertThat(asGroup.size(), is(0)); assertThat(asItem.size(), is(0)); CredentialsStore folderStore = getFolderStore(f); UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "test-id", "description", "test-user", "secret"); folderStore.addCredentials(Domain.global(), credentials); asGroup = CredentialsProvider.listCredentials(StandardUsernamePasswordCredentials.class, (ItemGroup) f, ACL.SYSTEM, Collections.emptyList(), CredentialsMatchers.always()); asItem = CredentialsProvider.listCredentials(StandardUsernamePasswordCredentials.class, (Item) f, ACL.SYSTEM, Collections.emptyList(), CredentialsMatchers.always()); assertThat(asGroup.size(), is(1)); assertThat(asGroup.get(0).value, is("test-id")); assertThat(asItem.size(), is(1)); assertThat(asItem.get(0).value, is("test-id")); }