/** * Adds a collection of credentials (they will be filtered with {@link SSHAuthenticator#matcher()} implicitly). * * @param col the collection of credentials. * @return {@code this} for method chaining. * @deprecated use {@link #withMatching(CredentialsMatcher, Iterable)} or {@link #withAll(Iterable)} */ @Deprecated public SSHUserListBoxModel addCollection(Collection<? extends StandardUsernameCredentials> col) { withMatching(SSHAuthenticator.matcher(), col); return this; }
/** * Adds all the system-scoped credentials (they will be filtered with {@link SSHAuthenticator#matcher()} * implicitly). * <p> * These credentials are meant to be used for system configuration and other things scoped to the {@link Jenkins} * object, * such as slaves. * </p> * * @param domainRequirements the domain requirements * @return {@code this} for method chaining. */ public SSHUserListBoxModel withSystemScopeCredentials(DomainRequirement... domainRequirements) { return withSystemScopeCredentials(SSHAuthenticator.matcher(), domainRequirements); }
/** * Adds all the system-scoped credentials (they will be filtered with {@link SSHAuthenticator#matcher()} * implicitly). * <p> * These credentials are meant to be used for system configuration and other things scoped to the {@link Jenkins} * object, * such as slaves. * </p> * * @param domainRequirements the domain requirements * @return {@code this} for method chaining. */ public SSHUserListBoxModel withSystemScopeCredentials(List<DomainRequirement> domainRequirements) { return withSystemScopeCredentials(SSHAuthenticator.matcher(), domainRequirements); }
/** * Filters {@link Credentials} returning only those which are supported with the specified type of connection. * * @param credentials the credentials to filter. * @param connectionClass the type of connection to filter for. * @return a list of {@link SSHUser} credentials appropriate for use with the supplied type of connection. * @deprecated Use * {@link CredentialsMatchers#filter(List, CredentialsMatcher)} * and {@link #matcher(Class)} */ public static List<? extends StandardUsernameCredentials> filter(Iterable<? extends Credentials> credentials, Class<?> connectionClass) { List<StandardUsernameCredentials> result = new ArrayList<StandardUsernameCredentials>(); CredentialsMatcher matcher = matcher(connectionClass); for (Credentials credential : credentials) { if (credential instanceof StandardUsernameCredentials && matcher.matches(credential)) { result.add((StandardUsernameCredentials) credential); } } return result; }
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 ListBoxModel doFillAdminCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String currentValue) { if (!(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()).hasPermission(Computer.CONFIGURE)) { return new StandardUsernameListBoxModel().includeCurrentValue(currentValue); } return new StandardUsernameListBoxModel().includeMatchingAs( ACL.SYSTEM, context, StandardUsernameCredentials.class, Collections.<DomainRequirement>singletonList(SSHLauncher.SSH_SCHEME), SSHAuthenticator.matcher(Connection.class)).includeCurrentValue(currentValue); }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String currentValue) { if (!(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()).hasPermission(Computer.CONFIGURE)) { return new StandardUsernameListBoxModel().includeCurrentValue(currentValue); } return new StandardUsernameListBoxModel().includeMatchingAs( ACL.SYSTEM, context, StandardUsernameCredentials.class, Collections.<DomainRequirement>singletonList(SSHLauncher.SSH_SCHEME), SSHAuthenticator.matcher(Connection.class)).includeCurrentValue(currentValue); }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String credentialsId) { AccessControlled _context = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (_context == null || !_context.hasPermission(Computer.CONFIGURE)) { return new StandardUsernameListBoxModel() .includeCurrentValue(credentialsId); } return new StandardUsernameListBoxModel() .includeMatchingAs( ACL.SYSTEM, context, StandardUsernameCredentials.class, Collections.singletonList(SSHLauncher.SSH_SCHEME), SSHAuthenticator.matcher(Connection.class) ) .includeCurrentValue(credentialsId); }
public ListBoxModel doFillCredentialIdItems(final @AncestorInPath ItemGroup<?> context) { final List<StandardUsernameCredentials> credentials = CredentialsProvider.lookupCredentials( StandardUsernameCredentials.class, context, ACL.SYSTEM, CredentialsSSHSite.NO_REQUIREMENTS); return new SSHUserListBoxModel().withEmptySelection().withMatching( SSHAuthenticator.matcher(JSchConnector.class), credentials); }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String credentialsId) { AccessControlled _context = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (_context == null || !_context.hasPermission(Computer.CONFIGURE)) { return new StandardUsernameListBoxModel() .includeCurrentValue(credentialsId); } return new StandardUsernameListBoxModel() .includeMatchingAs( ACL.SYSTEM, context, StandardUsernameCredentials.class, Collections.<DomainRequirement>singletonList(SSHLauncher.SSH_SCHEME), SSHAuthenticator.matcher(Connection.class) ) .includeCurrentValue(credentialsId); }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String host, @QueryParameter String port, @QueryParameter String credentialsId) { AccessControlled _context = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (_context == null || !_context.hasPermission(Computer.CONFIGURE)) { return new StandardUsernameListBoxModel() .includeCurrentValue(credentialsId); } try { int portValue = Integer.parseInt(port); return new StandardUsernameListBoxModel() .includeMatchingAs( ACL.SYSTEM, Jenkins.getActiveInstance(), StandardUsernameCredentials.class, Collections.<DomainRequirement>singletonList( new HostnamePortRequirement(host, portValue) ), SSHAuthenticator.matcher(Connection.class)) .includeCurrentValue(credentialsId); // always add the current value last in case already present } catch (NumberFormatException ex) { return new StandardUsernameListBoxModel() .includeCurrentValue(credentialsId); } }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath AccessControlled context, @QueryParameter String host, @QueryParameter String port, @QueryParameter String credentialsId) { Jenkins jenkins = Jenkins.getInstance(); if ((context == jenkins && !jenkins.hasPermission(Computer.CREATE)) || (context != jenkins && !context.hasPermission(Computer.CONFIGURE))) { return new StandardUsernameListBoxModel() .includeCurrentValue(credentialsId); } try { int portValue = Integer.parseInt(port); return new StandardUsernameListBoxModel() .includeMatchingAs( ACL.SYSTEM, jenkins, StandardUsernameCredentials.class, Collections.singletonList( new HostnamePortRequirement(host, portValue) ), SSHAuthenticator.matcher(Connection.class)) .includeCurrentValue(credentialsId); // always add the current value last in case already present } catch (NumberFormatException ex) { return new StandardUsernameListBoxModel() .includeCurrentValue(credentialsId); } }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) { AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (!ac.hasPermission(Jenkins.ADMINISTER)) { return new ListBoxModel(); } return new SSHUserListBoxModel().withMatching(SSHAuthenticator.matcher(Connection.class), CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, context, ACL.SYSTEM, SSHLauncher.SSH_SCHEME)); } }
public static ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) { AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (!ac.hasPermission(Jenkins.ADMINISTER)) { return new ListBoxModel(); } return new SSHUserListBoxModel().withMatching( SSHAuthenticator.matcher(Connection.class), CredentialsProvider.lookupCredentials( StandardUsernameCredentials.class, context, ACL.SYSTEM, SSHLauncher.SSH_SCHEME) ); }
public static ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) { AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (!ac.hasPermission(Jenkins.ADMINISTER)) { return new ListBoxModel(); } return new SSHUserListBoxModel().withMatching( SSHAuthenticator.matcher(Connection.class), CredentialsProvider.lookupCredentials( StandardUsernameCredentials.class, context, ACL.SYSTEM, SSHLauncher.SSH_SCHEME) ); }
@Restricted(DoNotUse.class) @RequirePOST public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) { if (!(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getActiveInstance()).hasPermission(Computer.CONFIGURE)) { return new ListBoxModel(); } List<StandardUsernameCredentials> credentials = CredentialsProvider.lookupCredentials( StandardUsernameCredentials.class, context, ACL.SYSTEM, SSHLauncher.SSH_SCHEME ); return new StandardUsernameListBoxModel() .withMatching(SSHAuthenticator.matcher(Connection.class), credentials) .withEmptySelection() ; } }