@Test(expected = LoginCanceledException.class) public void testPasswordChange() throws Exception { final AtomicBoolean connected = new AtomicBoolean(); final AtomicBoolean keychain = new AtomicBoolean(); final AtomicBoolean prompt = new AtomicBoolean(); final LoginConnectionService s = 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) { } @Override public Credentials prompt(final Host bookmark, final String username, final String title, final String reason, final LoginOptions options) { prompt.set(true); return new Credentials(username, "b"); } }, new DisabledHostKeyCallback(), new DisabledPasswordStore() { @Override public String findLoginPassword(final Host bookmark) { keychain.set(true); return "a"; } }, new DisabledProgressListener()); final Session session = new NullSession(new Host(new TestProtocol(), "localhost", new Credentials("user", ""))) { @Override public Void connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) { connected.set(true); return null; } @Override public boolean isConnected() { return connected.get(); } @Override public void login(final Proxy proxy, final LoginCallback l, final CancelCallback cancel) throws BackgroundException { if(prompt.get()) { assertEquals("b", host.getCredentials().getPassword()); throw new LoginCanceledException(); } if(keychain.get()) { assertFalse(prompt.get()); assertEquals("a", host.getCredentials().getPassword()); throw new LoginFailureException("f"); } } }; try { s.check(session, PathCache.empty(), new DisabledCancelCallback()); } finally { assertTrue(keychain.get()); assertTrue(prompt.get()); } }
@Override public boolean check(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { final Host bookmark = session.getHost(); if(bookmark.getProtocol().isHostnameConfigurable() && StringUtils.isBlank(bookmark.getHostname())) { throw new ConnectionCanceledException(); } if(session.isConnected()) { if(log.isDebugEnabled()) { log.debug(String.format("Skip opening connection for session %s", session)); } return false; } synchronized(login) { final LoginOptions options = new LoginOptions(bookmark.getProtocol()); final StringAppender message = new StringAppender(); if(options.password) { message.append(MessageFormat.format(LocaleFactory.localizedString( "Login {0} with username and password", "Credentials"), BookmarkNameProvider.toString(bookmark))); } if(options.publickey) { message.append(LocaleFactory.localizedString( "Select the private key in PEM or PuTTY format", "Credentials")); } login.validate(bookmark, message.toString(), prompt, options); } this.connect(session, cache, callback); return true; }
LoginConnectionService implements ConnectionService { @Override public boolean check(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { final Host bookmark = session.getHost(); if(bookmark.getProtocol().isHostnameConfigurable() && StringUtils.isBlank(bookmark.getHostname())) { throw new ConnectionCanceledException(); } if(session.isConnected()) { if(log.isDebugEnabled()) { log.debug(String.format("Skip opening connection for session %s", session)); } return false; } synchronized(login) { final LoginOptions options = new LoginOptions(bookmark.getProtocol()); final StringAppender message = new StringAppender(); if(options.password) { message.append(MessageFormat.format(LocaleFactory.localizedString( "Login {0} with username and password", "Credentials"), BookmarkNameProvider.toString(bookmark))); } if(options.publickey) { message.append(LocaleFactory.localizedString( "Select the private key in PEM or PuTTY format", "Credentials")); } login.validate(bookmark, message.toString(), prompt, options); } this.connect(session, cache, callback); return true; } }
LoginConnectionService implements ConnectionService { @Override public boolean check(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { final Host bookmark = session.getHost(); if(bookmark.getProtocol().isHostnameConfigurable() && StringUtils.isBlank(bookmark.getHostname())) { throw new ConnectionCanceledException(); } if(session.isConnected()) { if(log.isDebugEnabled()) { log.debug(String.format("Skip opening connection for session %s", session)); } return false; } synchronized(login) { final LoginOptions options = new LoginOptions(bookmark.getProtocol()); final StringAppender message = new StringAppender(); if(options.password) { message.append(MessageFormat.format(LocaleFactory.localizedString( "Login {0} with username and password", "Credentials"), BookmarkNameProvider.toString(bookmark))); } if(options.publickey) { message.append(LocaleFactory.localizedString( "Select the private key in PEM or PuTTY format", "Credentials")); } login.validate(bookmark, message.toString(), prompt, options); } this.connect(session, cache, callback); return true; } 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 boolean check(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { final Host bookmark = session.getHost(); if(bookmark.getProtocol().isHostnameConfigurable() && StringUtils.isBlank(bookmark.getHostname())) { throw new ConnectionCanceledException(); } if(session.isConnected()) { if(log.isDebugEnabled()) { log.debug(String.format("Skip opening connection for session %s", session)); } return false; } synchronized(login) { final LoginOptions options = new LoginOptions(bookmark.getProtocol()); final StringAppender message = new StringAppender(); if(options.password) { message.append(MessageFormat.format(LocaleFactory.localizedString( "Login {0} with username and password", "Credentials"), BookmarkNameProvider.toString(bookmark))); } if(options.publickey) { message.append(LocaleFactory.localizedString( "Select the private key in PEM or PuTTY format", "Credentials")); } login.validate(bookmark, message.toString(), prompt, options); } this.connect(session, cache, callback); return true; } 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 boolean check(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { final Host bookmark = session.getHost(); if(bookmark.getProtocol().isHostnameConfigurable() && StringUtils.isBlank(bookmark.getHostname())) { throw new ConnectionCanceledException(); } if(session.isConnected()) { if(log.isDebugEnabled()) { log.debug(String.format("Skip opening connection for session %s", session)); } return false; } synchronized(login) { final LoginOptions options = new LoginOptions(bookmark.getProtocol()); final StringAppender message = new StringAppender(); if(options.password) { message.append(MessageFormat.format(LocaleFactory.localizedString( "Login {0} with username and password", "Credentials"), BookmarkNameProvider.toString(bookmark))); } if(options.publickey) { message.append(LocaleFactory.localizedString( "Select the private key in PEM or PuTTY format", "Credentials")); } login.validate(bookmark, message.toString(), prompt, options); } this.connect(session, cache, callback); return true; } 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);  }