@Test(expected = LoginCanceledException.class) public void testCancel() throws Exception { LoginService l = new KeychainLoginService(new DisabledPasswordStore()); l.validate(new Host(new TestProtocol(), "h"), "", new DisabledLoginCallback(), new LoginOptions()); }
@Override public void validate(final Host bookmark, final String message, final LoginCallback prompt, final LoginOptions options) throws LoginCanceledException, LoginFailureException { if(log.isDebugEnabled()) { log.debug(String.format("Validate login credentials for %s", bookmark)); } final Credentials credentials = bookmark.getCredentials(); if(credentials.isPublicKeyAuthentication()) { 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())); } } if(options.keychain) { if(options.password) { if(StringUtils.isBlank(credentials.getPassword())) { final String password = keychain.findLoginPassword(bookmark); if(StringUtils.isNotBlank(password)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched password from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setPassword(password); } } } if(options.token) { if(StringUtils.isBlank(credentials.getToken())) { final String token = keychain.findLoginToken(bookmark); if(StringUtils.isNotBlank(token)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched token from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setToken(token); } } } if(options.publickey) { final String passphrase = keychain.findPrivateKeyPassphrase(bookmark); if(StringUtils.isNotBlank(passphrase)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched private key passphrase from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setIdentityPassphrase(passphrase); } } if(options.oauth) { final OAuthTokens tokens = keychain.findOAuthTokens(bookmark); if(tokens.validate()) { if(log.isInfoEnabled()) { log.info(String.format("Fetched OAuth token from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setOauth(tokens); } } } if(!credentials.validate(bookmark.getProtocol(), options)) { final StringAppender details = new StringAppender(); details.append(message); details.append(LocaleFactory.localizedString("No login credentials could be found in the Keychain", "Credentials")); this.prompt(bookmark, details.toString(), prompt, options); } }
KeychainLoginService implements LoginService { @Override public void validate(final Host bookmark, final String message, final LoginCallback prompt, final LoginOptions options) throws LoginCanceledException, LoginFailureException { if(log.isDebugEnabled()) { log.debug(String.format("Validate login credentials for %s", bookmark)); } final Credentials credentials = bookmark.getCredentials(); if(credentials.isPublicKeyAuthentication()) { 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())); } } if(options.keychain) { if(options.password) { if(StringUtils.isBlank(credentials.getPassword())) { final String password = keychain.findLoginPassword(bookmark); if(StringUtils.isNotBlank(password)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched password from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setPassword(password); } } } if(options.token) { if(StringUtils.isBlank(credentials.getToken())) { final String token = keychain.findLoginToken(bookmark); if(StringUtils.isNotBlank(token)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched token from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setToken(token); } } } if(options.publickey) { final String passphrase = keychain.findPrivateKeyPassphrase(bookmark); if(StringUtils.isNotBlank(passphrase)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched private key passphrase from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setIdentityPassphrase(passphrase); } } if(options.oauth) { final OAuthTokens tokens = keychain.findOAuthTokens(bookmark); if(tokens.validate()) { if(log.isInfoEnabled()) { log.info(String.format("Fetched OAuth token from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setOauth(tokens); } } } if(!credentials.validate(bookmark.getProtocol(), options)) { final StringAppender details = new StringAppender(); details.append(message); details.append(LocaleFactory.localizedString("No login credentials could be found in the Keychain", "Credentials")); this.prompt(bookmark, details.toString(), prompt, options); } } }
KeychainLoginService implements LoginService { @Override public void validate(final Host bookmark, final String message, final LoginCallback prompt, final LoginOptions options) throws LoginCanceledException, LoginFailureException { if(log.isDebugEnabled()) { log.debug(String.format("Validate login credentials for %s", bookmark)); } final Credentials credentials = bookmark.getCredentials(); if(credentials.isPublicKeyAuthentication()) { 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())); } } if(options.keychain) { if(options.password) { if(StringUtils.isBlank(credentials.getPassword())) { final String password = keychain.findLoginPassword(bookmark); if(StringUtils.isNotBlank(password)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched password from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setPassword(password); } } } if(options.token) { if(StringUtils.isBlank(credentials.getToken())) { final String token = keychain.findLoginToken(bookmark); if(StringUtils.isNotBlank(token)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched token from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setToken(token); } } } if(options.publickey) { final String passphrase = keychain.findPrivateKeyPassphrase(bookmark); if(StringUtils.isNotBlank(passphrase)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched private key passphrase from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setIdentityPassphrase(passphrase); } } if(options.oauth) { final OAuthTokens tokens = keychain.findOAuthTokens(bookmark); if(tokens.validate()) { if(log.isInfoEnabled()) { log.info(String.format("Fetched OAuth token from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setOauth(tokens); } } } if(!credentials.validate(bookmark.getProtocol(), options)) { final StringAppender details = new StringAppender(); details.append(message); details.append(LocaleFactory.localizedString("No login credentials could be found in the Keychain", "Credentials")); this.prompt(bookmark, details.toString(), prompt, options); } } KeychainLoginService(final HostPasswordStore keychain); }
KeychainLoginService implements LoginService { @Override public void validate(final Host bookmark, final String message, final LoginCallback prompt, final LoginOptions options) throws LoginCanceledException, LoginFailureException { if(log.isDebugEnabled()) { log.debug(String.format("Validate login credentials for %s", bookmark)); } final Credentials credentials = bookmark.getCredentials(); if(credentials.isPublicKeyAuthentication()) { 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())); } } if(options.keychain) { if(options.password) { if(StringUtils.isBlank(credentials.getPassword())) { final String password = keychain.findLoginPassword(bookmark); if(StringUtils.isNotBlank(password)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched password from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setPassword(password); } } } if(options.token) { if(StringUtils.isBlank(credentials.getToken())) { final String token = keychain.findLoginToken(bookmark); if(StringUtils.isNotBlank(token)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched token from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setToken(token); } } } if(options.publickey) { final String passphrase = keychain.findPrivateKeyPassphrase(bookmark); if(StringUtils.isNotBlank(passphrase)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched private key passphrase from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setIdentityPassphrase(passphrase); } } if(options.oauth) { final OAuthTokens tokens = keychain.findOAuthTokens(bookmark); if(tokens.validate()) { if(log.isInfoEnabled()) { log.info(String.format("Fetched OAuth token from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setOauth(tokens); } } } if(!credentials.validate(bookmark.getProtocol(), options)) { final StringAppender details = new StringAppender(); details.append(message); details.append(LocaleFactory.localizedString("No login credentials could be found in the Keychain", "Credentials")); this.prompt(bookmark, details.toString(), prompt, options); } } KeychainLoginService(final HostPasswordStore keychain); @Override void validate(final Host bookmark, final String message, final LoginCallback prompt,
                         final LoginOptions options); boolean prompt(final Host bookmark, final String message, final LoginCallback prompt, final LoginOptions options); @Override boolean authenticate(final Proxy proxy, final Session session, final ProgressListener listener,
                                final LoginCallback prompt, final CancelCallback cancel); }
KeychainLoginService implements LoginService { @Override public void validate(final Host bookmark, final String message, final LoginCallback prompt, final LoginOptions options) throws LoginCanceledException, LoginFailureException { if(log.isDebugEnabled()) { log.debug(String.format("Validate login credentials for %s", bookmark)); } final Credentials credentials = bookmark.getCredentials(); if(credentials.isPublicKeyAuthentication()) { 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())); } } if(options.keychain) { if(options.password) { if(StringUtils.isBlank(credentials.getPassword())) { final String password = keychain.findLoginPassword(bookmark); if(StringUtils.isNotBlank(password)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched password from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setPassword(password); } } } if(options.token) { if(StringUtils.isBlank(credentials.getToken())) { final String token = keychain.findLoginToken(bookmark); if(StringUtils.isNotBlank(token)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched token from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setToken(token); } } } if(options.publickey) { final String passphrase = keychain.findPrivateKeyPassphrase(bookmark); if(StringUtils.isNotBlank(passphrase)) { if(log.isInfoEnabled()) { log.info(String.format("Fetched private key passphrase from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setIdentityPassphrase(passphrase); } } if(options.oauth) { final OAuthTokens tokens = keychain.findOAuthTokens(bookmark); if(tokens.validate()) { if(log.isInfoEnabled()) { log.info(String.format("Fetched OAuth token from keychain for %s", bookmark)); } credentials.setSaved(false); credentials.setOauth(tokens); } } } if(!credentials.validate(bookmark.getProtocol(), options)) { final StringAppender details = new StringAppender(); details.append(message); details.append(LocaleFactory.localizedString("No login credentials could be found in the Keychain", "Credentials")); this.prompt(bookmark, details.toString(), prompt, options); } } KeychainLoginService(final HostPasswordStore keychain); @Override void validate(final Host bookmark, final String message, final LoginCallback prompt,
                         final LoginOptions options); boolean prompt(final Host bookmark, final String message, final LoginCallback prompt, final LoginOptions options); @Override boolean authenticate(final Proxy proxy, final Session session, final ProgressListener listener,
                                final LoginCallback prompt, final CancelCallback cancel);  }