/** * Helper method that returns a safe description of a {@link SSHUser}. * * @param c the credentials. * @return the description. */ @Nonnull public static String description(@Nonnull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + (description != null ? " (" + description + ")" : ""); }
/** * @deprecated * * deprecated but used by not deprecated constructor */ @Deprecated public SSHLauncher(String host, int port, StandardUsernameCredentials credentials, String jvmOptions, String javaPath, JDKInstaller jdkInstaller, String prefixStartSlaveCmd, String suffixStartSlaveCmd, Integer launchTimeoutSeconds, Integer maxNumRetries, Integer retryWaitTime, SshHostKeyVerificationStrategy sshHostKeyVerificationStrategy) { this(host, port, credentials != null ? credentials.getId() : null, jvmOptions, javaPath, null, prefixStartSlaveCmd, suffixStartSlaveCmd, launchTimeoutSeconds, maxNumRetries, retryWaitTime, sshHostKeyVerificationStrategy); this.credentials = credentials; }
@Override public String apply(@Nullable Entry<String, StandardUsernameCredentials> entry) { if (entry == null) return null; String mavenServerId = entry.getKey(); StandardUsernameCredentials credentials = entry.getValue(); return "[" + "mavenServerId: '" + mavenServerId + "', " + "jenkinsCredentials: '" + credentials.getId() + "', " + "username: '" + credentials.getUsername() + "', " + "type: '" + ClassUtils.getShortName(credentials.getClass()) + "']"; } }
/** * Returns the username to authenticate as. * * @return the username to authenticate as. * @since 1.4 */ public String getUsername() { return username == null ? getUser().getUsername() : username; }
/** * Hash a URL into a string that only contains characters that are safe as directory names. */ static String hashSource(String source, StandardUsernameCredentials credentials, @CheckForNull String masterCacheRoot) { if (!source.endsWith("/")) { source += "/"; } Matcher m = Pattern.compile(".+[/]([^/:]+)(:\\d+)?[/]?").matcher(source); String digestible = source; if (credentials != null){ digestible += '#' + credentials.getId(); } if (masterCacheRoot != null){ digestible += "#" + masterCacheRoot.replaceAll(File.pathSeparator, "_"); } BigInteger hash; try { hash = new BigInteger(1, MessageDigest.getInstance("SHA-1").digest(digestible.getBytes("UTF-8"))); } catch (Exception x) { throw new AssertionError(x); } return String.format("%040X%s%s", hash, m.matches() ? "-" + m.group(1) : "", credentials == null ? "" : "-" + credentials.getUsername().replace("@", "-at-")); }
@Override public String getUser() { return SSHLauncher.lookupSystemCredentials(credentialsId).getUsername(); }
/** * {@inheritDoc} */ @NonNull @Override public String getName(@NonNull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + (description != null ? " (" + description + ")" : ""); } }
private @CheckForNull StandardUsernameCredentials getCredentials(@CheckForNull String credentialsId) { if (credentialsId != null) { for (StandardUsernameCredentials c : availableCredentials(getOwner(), source)) { if (c.getId().equals(credentialsId)) { return c; } } } return null; }
public String getAdminUser() { if (!isNullOrEmpty(vmUser)) { return vmUser; } final StandardUsernameCredentials u = CredentialsHelper.getCredentialsById(adminCredentialsId); if (null == u || isNullOrEmpty(u.getUsername())) { return "root"; } else { return u.getUsername(); } }
/** * {@inheritDoc} */ @NonNull @Override public String getName(@NonNull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + (description != null ? " (" + description + ")" : ""); } }
public StandardUsernameCredentials getCredentials() { String credentialsId = this.credentialsId == null ? (this.credentials == null ? null : this.credentials.getId()) : this.credentialsId; try { // only ever want from the system // lookup every time so that we always have the latest StandardUsernameCredentials credentials = credentialsId != null ? SSHLauncher.lookupSystemCredentials(credentialsId) : null; if (credentials != null) { this.credentials = credentials; return credentials; } } catch (Throwable t) { // ignore } if (credentials == null) { if (credentialsId == null && (username != null || password != null || privatekey != null)) { credentials = upgrade(username, password, privatekey, host); this.credentialsId = credentials.getId(); } } return this.credentials; }
public String getJenkinsUser() { if (!isNullOrEmpty(jenkinsUser)) { return jenkinsUser; } final StandardUsernameCredentials u = CredentialsHelper.getCredentialsById(credentialsId); if (null == u || isNullOrEmpty(u.getUsername())) { return "jenkins"; } else { return u.getUsername(); } }
/** * {@inheritDoc} */ @NonNull @Override public String getName(@NonNull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + "/******" + (description != null ? " (" + description + ")" : ""); } }
public StandardUsernameCredentials getCredentials() { String credentialsId = this.credentialsId == null ? (this.credentials == null ? null : this.credentials.getId()) : this.credentialsId; try { // only ever want from the system // lookup every time so that we always have the latest StandardUsernameCredentials credentials = credentialsId != null ? SSHLauncher.lookupSystemCredentials(credentialsId) : null; if (credentials != null) { this.credentials = credentials; return credentials; } } catch (Throwable t) { // ignore } if (credentials == null) { if (credentialsId == null && (username != null || password != null || privatekey != null)) { credentials = upgrade(username, password, privatekey, host); this.credentialsId = credentials.getId(); } } return this.credentials; }
@DataBoundConstructor public CredentialsSSHSite(final String hostname, final String port, final String credentialId, final String serverAliveInterval, final String timeout) { final StandardUsernameCredentials credentials = lookupCredentialsById(credentialId); if (credentials != null) { this.username = credentials.getUsername(); } this.hostname = hostname; try { this.port = Integer.parseInt(port); } catch (final NumberFormatException e) { this.port = 22; } this.credentialId = credentialId; this.setServerAliveInterval(serverAliveInterval); this.setTimeout(timeout); }
/** * {@inheritDoc} */ @NonNull @Override public String getName(@NonNull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + "/******" + (description != null ? " (" + description + ")" : ""); } }
public StandardUsernameCredentials getCredentials() { String credentialsId = this.credentialsId == null ? (this.credentials == null ? null : this.credentials.getId()) : this.credentialsId; try { // only ever want from the system // lookup every time so that we always have the latest StandardUsernameCredentials credentials = credentialsId == null ? null : SSHLauncher.lookupSystemCredentials(credentialsId); if (credentials != null) { this.credentials = credentials; return credentials; } } catch (Throwable t) { // ignore } if (credentials == null) { if (credentialsId == null) { credentials = SSHLauncher.upgrade(username, password, privatekey, null); this.credentialsId = credentials.getId(); } } return credentials; }
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; }
/** * {@inheritDoc} */ @NonNull protected String describe(@NonNull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + (description != null ? " (" + description + ")" : ""); }
public StandardUsernameCredentials getCredentials() { String credentialsId = this.credentialsId == null ? (this.credentials == null ? null : this.credentials.getId()) : this.credentialsId; try { // only ever want from the system // lookup every time so that we always have the latest StandardUsernameCredentials credentials = credentialsId == null ? null : SSHLauncher.lookupSystemCredentials(credentialsId); if (credentials != null) { this.credentials = credentials; return credentials; } } catch (Throwable t) { // ignore } if (credentials == null) { if (credentialsId == null) { credentials = SSHLauncher.upgrade(username, password, privatekey, null); this.credentialsId = credentials.getId(); } } return credentials; }