@Override public StandardUsernameCredentials getCredentials() { return new BasicSSHUserPrivateKey(CredentialsScope.SYSTEM, "InstanceIdentity", user, new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource(privateKey), null, "private key for docker ssh agent"); } }
/** * {@inheritDoc} */ @Override public String getDisplayName() { return Messages.BasicSSHUserPrivateKey_FileOnMasterPrivateKeySourceDisplayName(); } }
/** * {@inheritDoc} */ @Override public String getDisplayName() { return Messages.BasicSSHUserPrivateKey_UsersPrivateKeySourceDisplayName(); } }
/** * {@inheritDoc} */ @Override public SSHUserPrivateKey snapshot(SSHUserPrivateKey credentials) { if (credentials instanceof BasicSSHUserPrivateKey) { final PrivateKeySource keySource = ((BasicSSHUserPrivateKey) credentials).getPrivateKeySource(); if (keySource.isSnapshotSource()) { return credentials; } } final Secret passphrase = credentials.getPassphrase(); return new BasicSSHUserPrivateKey(credentials.getScope(), credentials.getId(), credentials.getUsername(), new DirectEntryPrivateKeySource(credentials.getPrivateKeys()), passphrase == null ? null : passphrase.getEncryptedValue(), credentials.getDescription()); } }
private static DirectEntryPrivateKeySource handleKey(final String json, final String key) { String value = getJsonString(json, "private_key"); if (null == value) { return new DirectEntryPrivateKeySource(key); } return new DirectEntryPrivateKeySource(value); }
/** * Constructor for stapler. * * @param scope the credentials scope * @param username the username. * @param privateKeySource the private key. * @param passphrase the password. * @param description the description. */ @DataBoundConstructor public BasicSSHUserPrivateKey(CredentialsScope scope, String id, String username, PrivateKeySource privateKeySource, String passphrase, String description) { super(scope, id, username, description); this.privateKeySource = privateKeySource == null ? new DirectEntryPrivateKeySource("") : privateKeySource; this.passphrase = fixEmpty(passphrase == null ? null : Secret.fromString(passphrase)); }
@Override protected boolean doAuthenticate() { final Session session = getConnection().getSession(); session.setUserInfo(new JSchUserInfo()); session.setPassword(getUser().getPassword().getPlainText()); return true; }
@Override public boolean canAuthenticate() { return !getConnection().hasSession() || (getConnection().getSession().isConnected() && getConnection().getSession().getUserInfo() == null); }
/** * {@inheritDoc} */ @Override public boolean canAuthenticate() { return !getConnection().hasSession() || (getConnection().getSession().isConnected() && getConnection().getSession().getUserInfo() == null); }
/** * {@inheritDoc} */ @Override public String getDisplayName() { return Messages.BasicSSHUserPrivateKey_DisplayName(); }
/** * {@inheritDoc} */ @Override public String getDisplayName() { return Messages.BasicSSHUserPrivateKey_DirectEntryPrivateKeySourceDisplayName(); } }
/** * {@inheritDoc} */ @NonNull public String getPrivateKey() { List<String> privateKeys = getPrivateKeys(); return privateKeys.isEmpty() ? "" : privateKeys.get(0); }
public synchronized Session getSession() { if (!hasSession()) { try { session = jsch.getSession(username, host, port); } catch (JSchException e) { throw new SSHAuthenticatorException(e); } } return session; }
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") protected <C, U extends StandardUsernameCredentials> SSHAuthenticator<C, U> newInstance(@NonNull C session, @NonNull U user) { return newInstance(session, user, null); }
/** * {@inheritDoc} */ @Override protected <C, U extends StandardUsernameCredentials> SSHAuthenticator<C, U> newInstance(@NonNull C connection, @NonNull U user) { return newInstance(connection, user, null); }
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") protected <C, U extends StandardUsernameCredentials> SSHAuthenticator<C, U> newInstance(@NonNull C connection, @NonNull U user) { return newInstance(connection, user, null); }
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") protected <C, U extends StandardUsernameCredentials> SSHAuthenticator<C, U> newInstance(@NonNull C session, @NonNull U user) { return newInstance(session, user, null); }
private Object writeReplace() { if (/* XStream */Channel.current() == null) { return this; } if (privateKeySource == null || privateKeySource.isSnapshotSource()) { return this; } return CredentialsProvider.snapshot(this); }
private Object readResolve() { if (privateKeyFile != null && privateKeyFile.startsWith("---") && privateKeyFile.contains("---BEGIN") && privateKeyFile.contains("---END")) { // this is a borked upgrade, not actually the file name but is actually the key contents return new DirectEntryPrivateKeySource(privateKeyFile); } return this; }
@NonNull public PrivateKeySource getPrivateKeySource() { return privateKeySource == null ? new DirectEntryPrivateKeySource("") : privateKeySource; }