@Test(expected = LoginCanceledException.class) public void testConnectionWarning() throws Exception { final Host host = new Host(new TestProtocol(), "test.cyberduck.ch", new Credentials( "u", "p" )); final AtomicBoolean warned = new AtomicBoolean(false); final Session session = new NullSession(host); final LoginConnectionService l = new LoginConnectionService(new DisabledLoginCallback() { @Override public void warn(final Host bookmark, final String title, final String message, final String continueButton, final String disconnectButton, final String preference) throws LoginCanceledException { warned.set(true); throw new LoginCanceledException(); } }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()); try { l.connect(session, PathCache.empty(), new DisabledCancelCallback()); fail(); } catch(LoginCanceledException e) { assertTrue(warned.get()); throw e; } }
@Override public void connect(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { if(session.isConnected()) { this.close(session); } final Host bookmark = session.getHost(); final HostnameConfigurator configurator = HostnameConfiguratorFactory.get(bookmark.getProtocol()); final String hostname = configurator.getHostname(bookmark.getHostname()); listener.message(MessageFormat.format(LocaleFactory.localizedString("Resolving {0}", "Status"), hostname)); final Proxy proxy = this.proxy.find(bookmark); if(proxy == Proxy.DIRECT) { try { resolver.resolve(hostname, callback); } catch(ResolveFailedException e) { log.warn(String.format("DNS resolver failed for %s", hostname)); throw e; } } listener.message(MessageFormat.format(LocaleFactory.localizedString("Opening {0} connection to {1}", "Status"), bookmark.getProtocol().getName(), hostname)); session.open(proxy, key, prompt); listener.message(MessageFormat.format(LocaleFactory.localizedString("{0} connection opened", "Status"), bookmark.getProtocol().getName())); bookmark.setTimestamp(new Date()); if(session.alert(prompt)) { prompt.warn(bookmark, MessageFormat.format(LocaleFactory.localizedString("Unsecured {0} connection", "Credentials"), bookmark.getProtocol().getName()), MessageFormat.format("{0} {1}.", MessageFormat.format(LocaleFactory.localizedString("{0} will be sent in plaintext.", "Credentials"), bookmark.getProtocol().getPasswordPlaceholder()), LocaleFactory.localizedString("Please contact your web hosting service provider for assistance", "Support")), LocaleFactory.localizedString("Continue", "Credentials"), LocaleFactory.localizedString("Disconnect", "Credentials"), String.format("connection.unsecure.%s", bookmark.getHostname())); } try { this.authenticate(proxy, session, cache, callback); } catch(BackgroundException e) { this.close(session); throw e; } }
LoginConnectionService implements ConnectionService { @Override public void connect(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { if(session.isConnected()) { this.close(session); } final Host bookmark = session.getHost(); final HostnameConfigurator configurator = HostnameConfiguratorFactory.get(bookmark.getProtocol()); final String hostname = configurator.getHostname(bookmark.getHostname()); listener.message(MessageFormat.format(LocaleFactory.localizedString("Resolving {0}", "Status"), hostname)); final Proxy proxy = this.proxy.find(bookmark); if(proxy == Proxy.DIRECT) { try { resolver.resolve(hostname, callback); } catch(ResolveFailedException e) { log.warn(String.format("DNS resolver failed for %s", hostname)); throw e; } } listener.message(MessageFormat.format(LocaleFactory.localizedString("Opening {0} connection to {1}", "Status"), bookmark.getProtocol().getName(), hostname)); session.open(proxy, key, prompt); listener.message(MessageFormat.format(LocaleFactory.localizedString("{0} connection opened", "Status"), bookmark.getProtocol().getName())); bookmark.setTimestamp(new Date()); if(session.alert(prompt)) { prompt.warn(bookmark, MessageFormat.format(LocaleFactory.localizedString("Unsecured {0} connection", "Credentials"), bookmark.getProtocol().getName()), MessageFormat.format("{0} {1}.", MessageFormat.format(LocaleFactory.localizedString("{0} will be sent in plaintext.", "Credentials"), bookmark.getProtocol().getPasswordPlaceholder()), LocaleFactory.localizedString("Please contact your web hosting service provider for assistance", "Support")), LocaleFactory.localizedString("Continue", "Credentials"), LocaleFactory.localizedString("Disconnect", "Credentials"), String.format("connection.unsecure.%s", bookmark.getHostname())); } try { this.authenticate(proxy, session, cache, callback); } catch(BackgroundException e) { this.close(session); throw e; } } }
LoginConnectionService implements ConnectionService { @Override public void connect(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { if(session.isConnected()) { this.close(session); } final Host bookmark = session.getHost(); final HostnameConfigurator configurator = HostnameConfiguratorFactory.get(bookmark.getProtocol()); final String hostname = configurator.getHostname(bookmark.getHostname()); listener.message(MessageFormat.format(LocaleFactory.localizedString("Resolving {0}", "Status"), hostname)); final Proxy proxy = this.proxy.find(bookmark); if(proxy == Proxy.DIRECT) { try { resolver.resolve(hostname, callback); } catch(ResolveFailedException e) { log.warn(String.format("DNS resolver failed for %s", hostname)); throw e; } } listener.message(MessageFormat.format(LocaleFactory.localizedString("Opening {0} connection to {1}", "Status"), bookmark.getProtocol().getName(), hostname)); session.open(proxy, key, prompt); listener.message(MessageFormat.format(LocaleFactory.localizedString("{0} connection opened", "Status"), bookmark.getProtocol().getName())); bookmark.setTimestamp(new Date()); if(session.alert(prompt)) { prompt.warn(bookmark, MessageFormat.format(LocaleFactory.localizedString("Unsecured {0} connection", "Credentials"), bookmark.getProtocol().getName()), MessageFormat.format("{0} {1}.", MessageFormat.format(LocaleFactory.localizedString("{0} will be sent in plaintext.", "Credentials"), bookmark.getProtocol().getPasswordPlaceholder()), LocaleFactory.localizedString("Please contact your web hosting service provider for assistance", "Support")), LocaleFactory.localizedString("Continue", "Credentials"), LocaleFactory.localizedString("Disconnect", "Credentials"), String.format("connection.unsecure.%s", bookmark.getHostname())); } try { this.authenticate(proxy, session, cache, callback); } catch(BackgroundException e) { this.close(session); throw e; } } LoginConnectionService(final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final HostPasswordStore keychain,
                                  final ProgressListener listener);  LoginConnectionService(final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final HostPasswordStore keychain,
                                  final ProgressListener listener,
                                  final ProxyFinder proxy);  LoginConnectionService(final LoginService login,
                                  final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final ProgressListener listener);  LoginConnectionService(final LoginService login,
                                  final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final ProgressListener listener,
                                  final ProxyFinder proxy); }
LoginConnectionService implements ConnectionService { @Override public void connect(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { if(session.isConnected()) { this.close(session); } final Host bookmark = session.getHost(); final HostnameConfigurator configurator = HostnameConfiguratorFactory.get(bookmark.getProtocol()); final String hostname = configurator.getHostname(bookmark.getHostname()); listener.message(MessageFormat.format(LocaleFactory.localizedString("Resolving {0}", "Status"), hostname)); final Proxy proxy = this.proxy.find(bookmark); if(proxy == Proxy.DIRECT) { try { resolver.resolve(hostname, callback); } catch(ResolveFailedException e) { log.warn(String.format("DNS resolver failed for %s", hostname)); throw e; } } listener.message(MessageFormat.format(LocaleFactory.localizedString("Opening {0} connection to {1}", "Status"), bookmark.getProtocol().getName(), hostname)); session.open(proxy, key, prompt); listener.message(MessageFormat.format(LocaleFactory.localizedString("{0} connection opened", "Status"), bookmark.getProtocol().getName())); bookmark.setTimestamp(new Date()); if(session.alert(prompt)) { prompt.warn(bookmark, MessageFormat.format(LocaleFactory.localizedString("Unsecured {0} connection", "Credentials"), bookmark.getProtocol().getName()), MessageFormat.format("{0} {1}.", MessageFormat.format(LocaleFactory.localizedString("{0} will be sent in plaintext.", "Credentials"), bookmark.getProtocol().getPasswordPlaceholder()), LocaleFactory.localizedString("Please contact your web hosting service provider for assistance", "Support")), LocaleFactory.localizedString("Continue", "Credentials"), LocaleFactory.localizedString("Disconnect", "Credentials"), String.format("connection.unsecure.%s", bookmark.getHostname())); } try { this.authenticate(proxy, session, cache, callback); } catch(BackgroundException e) { this.close(session); throw e; } } LoginConnectionService(final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final HostPasswordStore keychain,
                                  final ProgressListener listener);  LoginConnectionService(final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final HostPasswordStore keychain,
                                  final ProgressListener listener,
                                  final ProxyFinder proxy);  LoginConnectionService(final LoginService login,
                                  final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final ProgressListener listener);  LoginConnectionService(final LoginService login,
                                  final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final ProgressListener listener,
                                  final ProxyFinder proxy); @Override boolean check(final Session<?> session, final Cache<Path> cache, final CancelCallback callback); @Override void close(final Session<?> session); @Override void connect(final Session<?> session, final Cache<Path> cache, final CancelCallback callback); }
LoginConnectionService implements ConnectionService { @Override public void connect(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { if(session.isConnected()) { this.close(session); } final Host bookmark = session.getHost(); final HostnameConfigurator configurator = HostnameConfiguratorFactory.get(bookmark.getProtocol()); final String hostname = configurator.getHostname(bookmark.getHostname()); listener.message(MessageFormat.format(LocaleFactory.localizedString("Resolving {0}", "Status"), hostname)); final Proxy proxy = this.proxy.find(bookmark); if(proxy == Proxy.DIRECT) { try { resolver.resolve(hostname, callback); } catch(ResolveFailedException e) { log.warn(String.format("DNS resolver failed for %s", hostname)); throw e; } } listener.message(MessageFormat.format(LocaleFactory.localizedString("Opening {0} connection to {1}", "Status"), bookmark.getProtocol().getName(), hostname)); session.open(proxy, key, prompt); listener.message(MessageFormat.format(LocaleFactory.localizedString("{0} connection opened", "Status"), bookmark.getProtocol().getName())); bookmark.setTimestamp(new Date()); if(session.alert(prompt)) { prompt.warn(bookmark, MessageFormat.format(LocaleFactory.localizedString("Unsecured {0} connection", "Credentials"), bookmark.getProtocol().getName()), MessageFormat.format("{0} {1}.", MessageFormat.format(LocaleFactory.localizedString("{0} will be sent in plaintext.", "Credentials"), bookmark.getProtocol().getPasswordPlaceholder()), LocaleFactory.localizedString("Please contact your web hosting service provider for assistance", "Support")), LocaleFactory.localizedString("Continue", "Credentials"), LocaleFactory.localizedString("Disconnect", "Credentials"), String.format("connection.unsecure.%s", bookmark.getHostname())); } try { this.authenticate(proxy, session, cache, callback); } catch(BackgroundException e) { this.close(session); throw e; } } LoginConnectionService(final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final HostPasswordStore keychain,
                                  final ProgressListener listener);  LoginConnectionService(final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final HostPasswordStore keychain,
                                  final ProgressListener listener,
                                  final ProxyFinder proxy);  LoginConnectionService(final LoginService login,
                                  final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final ProgressListener listener);  LoginConnectionService(final LoginService login,
                                  final LoginCallback prompt,
                                  final HostKeyCallback key,
                                  final ProgressListener listener,
                                  final ProxyFinder proxy); @Override boolean check(final Session<?> session, final Cache<Path> cache, final CancelCallback callback); @Override void close(final Session<?> session); @Override void connect(final Session<?> session, final Cache<Path> cache, final CancelCallback callback);  }