/** * 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; }
private Session createSession(final PrintStream logger) throws JSchException, IOException, InterruptedException { final StandardUsernameCredentials user = lookupCredentialsById(credentialId); if (user == null) { String message = "Credentials with id '" + credentialId + "', no longer exist!"; logger.println(message); throw new InterruptedException(message); } final JSchConnector connector = new JSchConnector(user.getUsername(), getResolvedHostname(), port); final SSHAuthenticator<JSchConnector, StandardUsernameCredentials> authenticator = SSHAuthenticator .newInstance(connector, user); authenticator.authenticate(new StreamTaskListener(logger, Charset.defaultCharset())); final Session session = connector.getSession(); session.setServerAliveInterval(serverAliveInterval); final Properties config = new Properties(); //TODO put this as configuration option instead of ignoring by default config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(timeout); return session; }
/** * @deprecated as of 0.3 * Use {@link #authenticate(TaskListener)} and provide a listener to receive errors. */ public final boolean authenticate() { synchronized (lock) { if (canAuthenticate()) { try { authenticated = doAuthenticate(); } catch (Throwable t) { Logger.getLogger(getClass().getName()) .log(Level.WARNING, "Uncaught exception escaped doAuthenticate method", t); authenticated = false; } } return isAuthenticated() || Mode.BEFORE_CONNECT.equals(getAuthenticationMode()); } }
/** * Authenticate the bound connection using the supplied credentials. * * @return For an {@link #getAuthenticationMode()} of {@link Mode#BEFORE_CONNECT} the return value is * always {@code true} otherwise the return value is {@code true} if and only if authentication was * successful. */ public final boolean authenticate(TaskListener listener) { setListener(listener); return authenticate(); }
/** * @deprecated Use {@link #newInstance(Object, StandardUsernameCredentials)} instead. */ @Deprecated public static SSHAuthenticator<Object, StandardUsernameCredentials> newInstance(Object connection, SSHUser user) throws InterruptedException, IOException { return newInstance(connection, (StandardUsernameCredentials) user, null); }
factories = lookupFactories(); } catch (LinkageError e) { if (result != null && result.canAuthenticate()) { return result;
/** * Creates an authenticator that may be able to authenticate the supplied connection with the supplied user. * * @param connection the connection to authenticate on. * @param user the user to authenticate with. * @param <C> the type of connection. * @param <U> the type of user. * @return a {@link SSHAuthenticator} that may or may not be able to successfully authenticate. */ @NonNull public static <C, U extends StandardUsernameCredentials> SSHAuthenticator<C, U> newInstance(@NonNull C connection, @NonNull U user) throws InterruptedException, IOException { return newInstance(connection, user, null); }
/** * 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); }
throw new AbortException("Cannot find SSH User credentials with id: " + credentialsId); if (SSHAuthenticator.newInstance(connection, credentials).authenticate(listener) && connection.isAuthenticationComplete()) { logger.println(Messages.SSHLauncher_AuthenticationSuccessful(getTimestamp()));
/** * 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); }
authenticated = smart.supports(item) && smart.get(uri, item) && SSHAuthenticator.newInstance(con, item.getValue(), uri.getUser()) .authenticate(smart.listener); } else if (credentialsProvider instanceof CredentialsProviderImpl) { CredentialsProviderImpl sshcp = (CredentialsProviderImpl) credentialsProvider; authenticated = SSHAuthenticator.newInstance(con, sshcp.cred).authenticate(sshcp.listener); } else { authenticated = false;
/** * 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; }
throw new AbortException("Cannot find SSH User credentials with id: " + credentialsId); if (SSHAuthenticator.newInstance(connection, credentials).authenticate(listener) && connection.isAuthenticationComplete()) { logger.println(Messages.SSHLauncher_AuthenticationSuccessful(getTimestamp()));
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); }