@Override public String getAWSSecretKey() { return credentials.getPassword(); } });
@Override public char[] reqPassword(final Resource<?> resource) { return credentials.getPassword().toCharArray(); }
@Override public boolean validate(final Credentials credentials, final LoginOptions options) { if(super.validate(credentials, options)) { if(options.password) { return Base64.validateIsBase64String(credentials.getPassword()); } return true; } return false; } }
@Override public DescriptiveUrl getSetup(final String hostname, final Scheme method, final Path container, final Credentials credentials) { final String setup = String.format("provider=%s,protocol=%s,endpoint=%s,key=%s,secret=%s", hostname, method.name(), containerService.getContainer(container).getName(), credentials.getUsername(), credentials.getPassword()); final String encoded; encoded = this.encode(new String(Base64.encodeBase64(setup.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8)); final String formatted = String.format("%s?setup=%s", target, encoded); if(log.isInfoEnabled()) { log.info(String.format("Setup URL %s", formatted)); } return new DescriptiveUrl(URI.create(formatted), DescriptiveUrl.Type.analytics); }
@Override public void windowDidBecomeKey(final NSNotification notification) { // Reset credentials this.updateField(usernameField, credentials.getUsername()); this.updateField(passwordField, credentials.getPassword()); }
@Override public void authSucceeded(final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { final HttpClientContext clientContext = HttpClientContext.adapt(context); final Credentials credentials = clientContext.getAttribute(PROXY_CREDENTIALS_INPUT_ID, Credentials.class); if(null != credentials) { clientContext.removeAttribute(PROXY_CREDENTIALS_INPUT_ID); if(log.isInfoEnabled()) { log.info(String.format("Save passphrase for proxy %s", authhost)); } keychain.addCredentials(authhost.toURI(), credentials.getUsername(), credentials.getPassword()); } super.authSucceeded(authhost, authScheme, context); }
@Override public void validate(final Host bookmark, final String message, final LoginCallback prompt, final LoginOptions options) throws LoginCanceledException, LoginFailureException { final Credentials credentials = bookmark.getCredentials(); if(input.hasOption(TerminalOptionsBuilder.Params.username.name())) { credentials.setUsername(input.getOptionValue(TerminalOptionsBuilder.Params.username.name())); } if(input.hasOption(TerminalOptionsBuilder.Params.password.name())) { credentials.setPassword(input.getOptionValue(TerminalOptionsBuilder.Params.password.name())); } if(input.hasOption(TerminalOptionsBuilder.Params.identity.name())) { credentials.setIdentity(LocalFactory.get(input.getOptionValue(TerminalOptionsBuilder.Params.identity.name()))); } if(StringUtils.isNotBlank(credentials.getUsername()) && StringUtils.isNotBlank(credentials.getPassword())) { return; } super.validate(bookmark, message, prompt, options); } }
@Override public char[] provideNewPassword(final Resource<?> resource, final String prompt) { try { final StringAppender message = new StringAppender().append(prompt); final Credentials changed = callback.prompt(host, credentials.getUsername(), LocaleFactory.localizedString("Change Password", "Credentials"), message.toString(), new LoginOptions(host.getProtocol()).anonymous(false).user(false).publickey(false)); return changed.getPassword().toCharArray(); } catch(LoginCanceledException e) { // Return null if user cancels return StringUtils.EMPTY.toCharArray(); } }
@Override public char[] reqPassword(Resource<?> resource) { if(StringUtils.isEmpty(credentials.getIdentityPassphrase())) { try { // Use password prompt final Credentials input = prompt.prompt(bookmark, LocaleFactory.localizedString("Private key password protected", "Credentials"), String.format("%s (%s)", LocaleFactory.localizedString("Enter the passphrase for the private key file", "Credentials"), identity.getAbbreviatedPath()), new LoginOptions() .icon(bookmark.getProtocol().disk()) .user(false).password(true) ); credentials.setSaved(input.isSaved()); credentials.setIdentityPassphrase(input.getPassword()); } catch(LoginCanceledException e) { canceled.set(true); // Return null if user cancels return StringUtils.EMPTY.toCharArray(); } } return credentials.getIdentityPassphrase().toCharArray(); }
@Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { try { final IRODSAccount account = client.getIRODSAccount(); final Credentials credentials = host.getCredentials(); account.setUserName(credentials.getUsername()); account.setPassword(credentials.getPassword()); final AuthResponse response = client.getIRODSAccessObjectFactory().authenticateIRODSAccount(account); if(log.isDebugEnabled()) { log.debug(String.format("Connected to %s", response.getStartupResponse())); } if(!response.isSuccessful()) { throw new LoginFailureException(MessageFormat.format(LocaleFactory.localizedString( "Login {0} with username and password", "Credentials"), BookmarkNameProvider.toString(host))); } } catch(JargonException e) { throw new IRODSExceptionMappingService().map(e); } }
@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); }
@Override public char[] reqPassword(Resource<?> resource) { if(StringUtils.isEmpty(credentials.getIdentityPassphrase())) { try { // Use password prompt final Credentials input = prompt.prompt(bookmark, LocaleFactory.localizedString("Private key password protected", "Credentials"), String.format("%s (%s)", LocaleFactory.localizedString("Enter the passphrase for the private key file", "Credentials"), identity.getAbbreviatedPath()), new LoginOptions() .icon(bookmark.getProtocol().disk()) .user(false).password(true) ); credentials.setSaved(input.isSaved()); credentials.setIdentityPassphrase(input.getPassword()); } catch(LoginCanceledException e) { // Return null if user cancels return StringUtils.EMPTY.toCharArray(); } } config.setPassword(credentials.getIdentityPassphrase()); return credentials.getIdentityPassphrase().toCharArray(); }
@Override public void change(final Host bookmark) { updateField(passwordField, credentials.getPassword()); passwordField.cell().setPlaceholderString(options.getPasswordPlaceholder()); passwordField.setEnabled(options.password && !credentials.isAnonymousLogin()); if(options.keychain) { if(StringUtils.isBlank(bookmark.getHostname())) { return; } if(StringUtils.isBlank(credentials.getUsername())) { return; } final String password = keychain.getPassword(bookmark.getProtocol().getScheme(), bookmark.getPort(), bookmark.getHostname(), credentials.getUsername()); if(StringUtils.isNotBlank(password)) { credentials.setPassword(password); updateField(passwordField, password); } } } });
/** * 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()); } }
@Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { try { final String accountId = host.getCredentials().getUsername(); final String applicationKey = host.getCredentials().getPassword(); // Save tokens for 401 error response when expired retryHandler.setTokens(accountId, applicationKey, client.authenticate(accountId, applicationKey).getAuthorizationToken()); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override protected IRODSFileSystemAO connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) throws BackgroundException { try { final IRODSFileSystem fs = this.configure(IRODSFileSystem.instance()); final IRODSAccessObjectFactory factory = fs.getIRODSAccessObjectFactory(); final String region = this.getRegion(); final String resource = this.getResource(); final Credentials credentials = host.getCredentials(); try { return factory.getIRODSFileSystemAO(new URIEncodingIRODSAccount(credentials.getUsername(), credentials.getPassword(), new IRODSHomeFinderService(IRODSSession.this).find().getAbsolute(), region, resource)); } catch(IllegalArgumentException e) { throw new LoginFailureException(e.getMessage(), e); } } catch(JargonException e) { throw new IRODSExceptionMappingService().map(e); } }
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final FileKey key = new NodesApi(session.getClient()).getUserFileKey( Long.parseLong(nodeid.getFileid(file, new DisabledListProgressListener())), StringUtils.EMPTY); final UserPrivateKey privateKey = new UserPrivateKey(); final UserKeyPairContainer keyPairContainer = session.keyPair(); privateKey.setPrivateKey(keyPairContainer.getPrivateKeyContainer().getPrivateKey()); privateKey.setVersion(keyPairContainer.getPrivateKeyContainer().getVersion()); final UserKeyPair userKeyPair = new UserKeyPair(); userKeyPair.setUserPrivateKey(privateKey); if(log.isDebugEnabled()) { log.debug(String.format("Attempt to unlock private key %s", privateKey)); } final Credentials passphrase = new TripleCryptKeyPair().unlock(callback, session.getHost(), userKeyPair); final PlainFileKey plainFileKey = Crypto.decryptFileKey(TripleCryptConverter.toCryptoEncryptedFileKey(key), privateKey, passphrase.getPassword()); return new CryptoInputStream(proxy.read(file, status, callback), Crypto.createFileDecryptionCipher(plainFileKey), CryptoUtils.stringToByteArray(plainFileKey.getTag())); } catch(ApiException e) { throw new SDSExceptionMappingService().map("Download {0} failed", e, file); } catch(CryptoException e) { throw new CryptoExceptionMappingService().map("Download {0} failed", e, file); } }
@Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final StorageCredentials credentials = client.getCredentials(); if(host.getCredentials().isPasswordAuthentication()) { // Update credentials ((StorageCredentialsAccountAndKey) credentials).updateKey(host.getCredentials().getPassword()); } else if(host.getCredentials().isTokenAuthentication()) { if(!StringUtils.equals(host.getCredentials().getToken(), ((StorageCredentialsSharedAccessSignature) credentials).getToken())) { this.interrupt(); this.open(proxy, new DisabledHostKeyCallback(), prompt); } } // Fetch reference for directory to check login credentials try { this.getFeature(ListService.class).list(new AzureHomeFinderService(this).find(), new DisabledListProgressListener() { @Override public void chunk(final Path parent, final AttributedList<Path> list) throws ListCanceledException { throw new ListCanceledException(list); } }); } catch(ListCanceledException e) { // Success } }
private String login(final LoginCallback controller, final LoginRequest request) throws BackgroundException { try { try { return new AuthApi(client).login(request).getToken(); } catch(ApiException e) { throw new SDSExceptionMappingService().map(e); } } catch(PartialLoginFailureException e) { final Credentials additional = controller.prompt(host, host.getCredentials().getUsername(), LocaleFactory.localizedString("Provide additional login credentials", "Credentials"), e.getDetail(), new LoginOptions() .icon(host.getProtocol().disk()) .user(false) .keychain(false) ); return this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .password(additional.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(); }