/** * @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; }
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; }
@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 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; }
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 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 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; }
/** * 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-")); }
@CheckForNull StandardUsernameCredentials getCredentials(Job<?,?> owner, EnvVars env) { if (credentialsId != null) { for (StandardUsernameCredentials c : availableCredentials(owner, getSource(env))) { if (c.getId().equals(credentialsId)) { return c; } } } return null; }
/** * Creates a new SSH credential for the jenkins user. * If a record with the same username and private key already exists, only the id of the existing record is returned. * @param user The username. * @param privateKey The privateKey. * @return The Id of the ssh-credential-plugin record (either newly created or already existing). */ @CheckForNull private String convertJenkinsUser(final String user, final String description, final String privateKey) { StandardUsernameCredentials u = retrieveExistingCredentials(user, privateKey); if (null == u) { u = new BasicSSHUserPrivateKey(CredentialsScope.SYSTEM, null, user, new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource(privateKey), null, description); try { return CredentialsHelper.storeCredentials(u); } catch (IOException x) { LOGGER.warning(String.format("Error while saving credentials: %s", x.getMessage())); return null; } } return u.getId(); }
/** * Stores a new credentials record (Used only during migration). * @param u The new credentials to store; * @return The Id of the new record or {@code null} on failure. * @throws IOException on error. */ public static String storeCredentials(final StandardUsernameCredentials u) throws IOException { if (null != u) { try (final ACLContext ctx = ACL.as(ACL.SYSTEM)) { final CredentialsStore s = CredentialsProvider.lookupStores(Jenkins.getInstance()).iterator().next(); s.addCredentials(Domain.global(), u); return u.getId(); } } return null; }
} else { LOGGER.log(Level.WARNING, "Maven Server ID {0}: credentials type of {1} not supported: {2}", new Object[]{mavenServerId, credential == null ? null : credential.getId(), credential == null ? null : credential.getClass()});
/** * @see SSHLauncher#SSHLauncher(String, int, StandardUsernameCredentials, String, String, JDKInstaller, String, * String) */ public SSHConnector(int port, StandardUsernameCredentials credentials, String username, String password, String privatekey, String jvmOptions, String javaPath, JDKInstaller jdkInstaller, String prefixStartSlaveCmd, String suffixStartSlaveCmd, Integer launchTimeoutSeconds, Integer maxNumRetries, Integer retryWaitTime, SshHostKeyVerificationStrategy sshHostKeyVerificationStrategy) { this.jvmOptions = jvmOptions; this.port = port == 0 ? 22 : port; this.credentials = credentials; this.credentialsId = credentials == null ? null : this.credentials.getId(); this.username = username; this.password = Secret.fromString(fixEmpty(password)); this.privatekey = privatekey; this.javaPath = javaPath; this.jdkInstaller = jdkInstaller; this.prefixStartSlaveCmd = fixEmpty(prefixStartSlaveCmd); this.suffixStartSlaveCmd = fixEmpty(suffixStartSlaveCmd); this.launchTimeoutSeconds = launchTimeoutSeconds == null || launchTimeoutSeconds <= 0 ? null : launchTimeoutSeconds; this.maxNumRetries = maxNumRetries != null && maxNumRetries > 0 ? maxNumRetries : 0; this.retryWaitTime = retryWaitTime != null && retryWaitTime > 0 ? retryWaitTime : 0; this.sshHostKeyVerificationStrategy = sshHostKeyVerificationStrategy; }
credentialId = existingCredentials.getId();
/** * @see SSHLauncher#SSHLauncher(String, int, StandardUsernameCredentials, String, String, JDKInstaller, String, * String) */ public SSHConnector(int port, StandardUsernameCredentials credentials, String username, String password, String privatekey, String jvmOptions, String javaPath, JDKInstaller jdkInstaller, String prefixStartSlaveCmd, String suffixStartSlaveCmd, Integer launchTimeoutSeconds, Integer maxNumRetries, Integer retryWaitTime, SshHostKeyVerificationStrategy sshHostKeyVerificationStrategy) { this.jvmOptions = jvmOptions; this.port = port == 0 ? 22 : port; this.credentials = credentials; this.credentialsId = credentials == null ? null : this.credentials.getId(); this.username = username; this.password = Secret.fromString(fixEmpty(password)); this.privatekey = privatekey; this.javaPath = javaPath; this.jdkInstaller = jdkInstaller; this.prefixStartSlaveCmd = fixEmpty(prefixStartSlaveCmd); this.suffixStartSlaveCmd = fixEmpty(suffixStartSlaveCmd); this.launchTimeoutSeconds = launchTimeoutSeconds == null || launchTimeoutSeconds <= 0 ? null : launchTimeoutSeconds; this.maxNumRetries = maxNumRetries != null && maxNumRetries > 0 ? maxNumRetries : 0; this.retryWaitTime = retryWaitTime != null && retryWaitTime > 0 ? retryWaitTime : 0; this.sshHostKeyVerificationStrategy = sshHostKeyVerificationStrategy; }
this.privatekey = null; this.credentials = credentials; this.credentialsId = credentials == null ? null : credentials.getId(); this.javaPath = fixEmpty(javaPath); if (jdkInstaller != null) {