/** * Returns the username to authenticate as. * * @return the username to authenticate as. * @since 1.4 */ public String getUsername() { return username == null ? getUser().getUsername() : username; }
@Override public String getUser() { return SSHLauncher.lookupSystemCredentials(credentialsId).getUsername(); }
/** * 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 + ")" : ""); }
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(); } }
@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()) + "']"; } }
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(); } }
/** * 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-")); }
@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); }
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 @Override public String getName(@NonNull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + (description != null ? " (" + description + ")" : ""); } }
/** * {@inheritDoc} */ @NonNull @Override public String getName(@NonNull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + (description != null ? " (" + description + ")" : ""); } }
/** * {@inheritDoc} */ @NonNull @Override public String getName(@NonNull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + "/******" + (description != null ? " (" + description + ")" : ""); } }
/** * {@inheritDoc} */ @NonNull @Override public String getName(@NonNull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + "/******" + (description != null ? " (" + description + ")" : ""); } }
/** * {@inheritDoc} */ @NonNull protected String describe(@NonNull StandardUsernameCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getUsername() + (description != null ? " (" + description + ")" : ""); }