final Local key = credentials.getIdentity(); String passphrase = this.getPassword(bookmark.getHostname(), key.getAbbreviatedPath()); if(null == passphrase) {
this.addPassword(bookmark.getHostname(), credentials.getIdentity().getAbbreviatedPath(), credentials.getIdentityPassphrase());
if(StringUtils.isNotBlank(credentials.getPassword())) { if(credentials.isPublicKeyAuthentication()) { keychain.addPassword(bookmark.getHostname(), credentials.getIdentity().getAbbreviatedPath(), credentials.getPassword());
identity ? String.format("-i \"%s\"", host.getCredentials().getIdentity().getAbsolute()) : StringUtils.EMPTY, host.getCredentials().getUsername(), host.getHostname(),
if(!credentials.getIdentity().attributes().getPermission().isReadable()) { log.warn(String.format("Prompt to select identity file not readable %s", credentials.getIdentity())); credentials.setIdentity(prompt.select(credentials.getIdentity()));
public String authenticate(final Host bookmark, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final Credentials credentials = bookmark.getCredentials(); final Local identity = credentials.getIdentity(); final KeyFormat format = this.detectKeyFormat(identity); final FileKeyProvider provider = this.buildProvider(identity, format);
final Local identity = credentials.getIdentity(); final FileKeyProvider provider; final AtomicBoolean canceled = new AtomicBoolean();
bookmark.getCredentials().setIdentity(input.getIdentity()); publickey.set(true);
@Override public void change(final Host bookmark) { privateKeyPopup.setEnabled(options.publickey); if(credentials.isPublicKeyAuthentication()) { privateKeyPopup.selectItemAtIndex(privateKeyPopup.indexOfItemWithRepresentedObject(credentials.getIdentity().getAbsolute())); } else { privateKeyPopup.selectItemWithTitle(LocaleFactory.localizedString("None")); } if(credentials.isPublicKeyAuthentication()) { final Local key = credentials.getIdentity(); if(-1 == privateKeyPopup.indexOfItemWithRepresentedObject(key.getAbsolute()).intValue()) { final NSInteger index = new NSInteger(0); privateKeyPopup.insertItemWithTitle_atIndex(key.getAbbreviatedPath(), index); privateKeyPopup.itemAtIndex(index).setRepresentedObject(key.getAbsolute()); } } } });
dict.setStringForKey(credentials.getCertificate(), "Client Certificate"); if(null != credentials.getIdentity()) { dict.setStringForKey(credentials.getIdentity().getAbbreviatedPath(), "Private Key File"); dict.setObjectForKey(credentials.getIdentity(), "Private Key File Dictionary");
@Override public Boolean authenticate(final Host bookmark, final LoginCallback callback, final CancelCallback cancel) throws BackgroundException { final Credentials credentials = bookmark.getCredentials(); if(StringUtils.isBlank(credentials.getPassword())) { final Credentials input = callback.prompt(bookmark, credentials.getUsername(), String.format("%s %s", LocaleFactory.localizedString("Login", "Login"), bookmark.getHostname()), MessageFormat.format(LocaleFactory.localizedString( "Login {0} with username and password", "Credentials"), BookmarkNameProvider.toString(bookmark)), // Change of username or service not allowed new LoginOptions(bookmark.getProtocol()).user(false)); if(input.isPublicKeyAuthentication()) { credentials.setIdentity(input.getIdentity()); return new SFTPPublicKeyAuthentication(session).authenticate(bookmark, callback, cancel); } credentials.setSaved(input.isSaved()); credentials.setPassword(input.getPassword()); } return this.authenticate(bookmark, credentials, callback, cancel); }
credentials.setSaved(input.isSaved()); if(input.isPublicKeyAuthentication()) { credentials.setIdentity(input.getIdentity());
/** * Prompt for credentials if not found in keychain * * @param bookmark Host configuration * @param message Message in prompt * @param prompt Login prompt * @param options Available login options for protocol * @throws LoginCanceledException Prompt canceled by user */ public void prompt(final Host bookmark, final String message, final LoginCallback prompt, final LoginOptions options) throws LoginCanceledException { final Credentials credentials = bookmark.getCredentials(); if(options.password) { final Credentials input = prompt.prompt(bookmark, credentials.getUsername(), String.format("%s %s", LocaleFactory.localizedString("Login", "Login"), bookmark.getHostname()), message, options); credentials.setSaved(input.isSaved()); credentials.setUsername(input.getUsername()); credentials.setPassword(input.getPassword()); credentials.setIdentity(input.getIdentity()); } if(options.token) { final Credentials input = prompt.prompt(bookmark, LocaleFactory.localizedString("Provide additional login credentials", "Credentials"), message, options); credentials.setSaved(input.isSaved()); credentials.setToken(input.getPassword()); } }
@Action public void hostFieldDidChange(final NSNotification sender) { final String input = hostField.stringValue(); if(Scheme.isURL(input)) { final Host parsed = HostParser.parse(input); bookmark.setHostname(parsed.getHostname()); bookmark.setProtocol(parsed.getProtocol()); bookmark.setPort(parsed.getPort()); bookmark.setDefaultPath(parsed.getDefaultPath()); } else { bookmark.setHostname(input); final Credentials auto = CredentialsConfiguratorFactory.get(bookmark.getProtocol()).configure(bookmark); final Credentials credentials = bookmark.getCredentials(); credentials.setUsername(auto.getUsername()); credentials.setPassword(auto.getPassword()); credentials.setIdentity(auto.getIdentity()); credentials.setToken(auto.getToken()); credentials.setCertificate(auto.getCertificate()); } this.update(); }