@Override public String getEndpoint() { return String.format("%s:%d", bookmark.getHostname(), bookmark.getPort()); }
public URIEncodingIRODSAccount(final String user, final String password, final String home, final String region, final String resource) { super(host.getHostname(), host.getPort(), StringUtils.isBlank(user) ? StringUtils.EMPTY : user, password, home, region, resource); this.setUserName(user); }
private String toURL(final Host host) { StringBuilder url = new StringBuilder(host.getProtocol().getScheme().toString()); url.append("://"); url.append(new PunycodeConverter().convert(host.getHostname())); url.append(":").append(host.getPort()); return url.toString(); } }
@Override public void change(final Host bookmark) { updateField(portField, String.valueOf(bookmark.getPort())); portField.setEnabled(bookmark.getProtocol().isPortConfigurable()); } });
@Override public String findLoginToken(final Host bookmark) { if(StringUtils.isEmpty(bookmark.getHostname())) { log.warn("No hostname given"); return null; } if(log.isInfoEnabled()) { log.info(String.format("Fetching login token from keychain for %s", bookmark)); } // Find token named like "Shared Access Signature (SAS) Token" final String token = this.getPassword(bookmark.getProtocol().getScheme(), bookmark.getPort(), bookmark.getHostname(), bookmark.getProtocol().getTokenPlaceholder()); if(null == token) { if(log.isInfoEnabled()) { log.info(String.format("Token not found in keychain for %s", bookmark)); } } return token; }
@Override public Credentials getCredentials(final String username) { // Resolve access key id final String key = PreferencesFactory.get().getProperty(String.format("%s%s", prefix, username)); if(log.isDebugEnabled()) { log.debug(String.format("Lookup access key for user %s with %s", username, key)); } if(null == key) { log.warn(String.format("No access key found for user %s", username)); return null; } return new Credentials(key, PasswordStoreFactory.get().getPassword(bookmark.getProtocol().getScheme(), bookmark.getPort(), bookmark.getHostname(), key)); }
@Override public OAuthTokens findOAuthTokens(final Host bookmark) { final long expiry = preferences.getLong(String.format("%s.oauth.expiry", bookmark.getProtocol().getIdentifier())); final String prefix = this.getOAuthPrefix(bookmark); return new OAuthTokens(this.getPassword(bookmark.getProtocol().getScheme(), bookmark.getPort(), URI.create(bookmark.getProtocol().getOAuthTokenUrl()).getHost(), String.format("%s OAuth2 Access Token", prefix)), this.getPassword(bookmark.getProtocol().getScheme(), bookmark.getPort(), URI.create(bookmark.getProtocol().getOAuthTokenUrl()).getHost(), String.format("%s OAuth2 Refresh Token", prefix)), expiry); }
/** * Find password for login * * @param bookmark Hostname * @return the password fetched from the keychain or null if it was not found */ @Override public String findLoginPassword(final Host bookmark) { if(StringUtils.isEmpty(bookmark.getHostname())) { log.warn("No hostname given"); return null; } final Credentials credentials = bookmark.getCredentials(); if(StringUtils.isEmpty(credentials.getUsername())) { log.warn("No username given"); return null; } if(log.isInfoEnabled()) { log.info(String.format("Fetching login password from keychain for %s", bookmark)); } final String password = this.getPassword(bookmark.getProtocol().getScheme(), bookmark.getPort(), bookmark.getHostname(), credentials.getUsername()); if(null == password) { if(log.isInfoEnabled()) { log.info(String.format("Password not found in keychain for %s", bookmark)); } } return password; }
@Override public Credentials getCredentials(final String username) { // Ignore user but use username from host credentials final String user = host.getCredentials().getUsername(); final String password = store.getPassword(host.getProtocol().getScheme(), host.getPort(), host.getHostname(), user); if(StringUtils.isEmpty(password)) { return null; } return new Credentials(user, password); } }
keychain.addPassword(bookmark.getProtocol().getScheme(), bookmark.getPort(), bookmark.getHostname(), credentials.getUsername(), credentials.getPassword());
@Override public HttpClientBuilder build(final Proxy proxy, final TranscriptListener listener, final LoginCallback prompt) { final HttpClientBuilder builder = super.build(proxy, listener, prompt); // Add filter to inject custom headers to authenticate with proxy builder.setRequestExecutor( new CustomHeaderHttpRequestExecutor(headers) ); // Set proxy router planer builder.setRoutePlanner(new DefaultProxyRoutePlanner( new HttpHost(this.proxy.getHostname(), this.proxy.getPort(), this.proxy.getProtocol().getScheme().name()), new DefaultSchemePortResolver())); return builder; }
/** * @return URL */ public String get(final Host bookmark) { final Scheme scheme = bookmark.getProtocol().getScheme(); final int port = bookmark.getPort(); final String username = bookmark.getCredentials().getUsername(); final String hostname = bookmark.getHostname(); final String path = bookmark.getDefaultPath(); return this.get(scheme, port, username, hostname, path); }
/** * Forces a full reclaim of all caches, and waits until the reclaim completes. Cache contents that need to be retained because they are a part of an active job are retained. * Any cache contents that can be reclaimed will be. This operation may take a very long time to complete, depending on how much of the cache can be reclaimed and how many blobs the cache is managing. */ protected void clear() throws BackgroundException { try { // Cancel all active jobs to remove references to cached objects final Ds3Client ds3Client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); ds3Client.cancelAllActiveJobsSpectraS3(new CancelAllActiveJobsSpectraS3Request()); // Clear cache final RequestEntityRestStorageService client = session.getClient(); final HttpPut request = new HttpPut(String.format("%s://%s:%s/_rest_/cache_filesystem?reclaim", session.getHost().getProtocol().getScheme(), session.getHost().getHostname(), session.getHost().getPort())); client.authorizeHttpRequest(request, null, null); final HttpResponse response = client.getHttpClient().execute(request); if(HttpStatus.SC_NO_CONTENT != response.getStatusLine().getStatusCode()) { throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); } } catch(HttpResponseException e) { throw new HttpResponseExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } catch(ServiceException e) { throw new S3ExceptionMappingService().map(e); } } }
@Override public String get(final Host bookmark) { switch(bookmark.getProtocol().getScheme()) { case sftp: return super.get(Scheme.ftp, bookmark.getPort(), bookmark.getCredentials().getUsername(), bookmark.getHostname(), bookmark.getDefaultPath()); } return super.get(bookmark); } }
@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); } } } });
public OAuth2RequestInterceptor(final HttpClient client, final Host host) { this(client, Scheme.isURL(host.getProtocol().getOAuthTokenUrl()) ? host.getProtocol().getOAuthTokenUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getOAuthTokenUrl()), Scheme.isURL(host.getProtocol().getOAuthAuthorizationUrl()) ? host.getProtocol().getOAuthAuthorizationUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getOAuthAuthorizationUrl()), host.getProtocol().getOAuthClientId(), host.getProtocol().getOAuthClientSecret(), host.getProtocol().getOAuthScopes()); }
@Override public FTPClient connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt) throws BackgroundException { try { final CustomTrustSSLProtocolSocketFactory f = new CustomTrustSSLProtocolSocketFactory(trust, key); final LoggingProtocolCommandListener listener = new LoggingProtocolCommandListener(this); final FTPClient client = new FTPClient(host.getProtocol(), f, f.getSSLContext()) { @Override public void disconnect() throws IOException { try { super.disconnect(); } finally { this.removeProtocolCommandListener(listener); } } }; client.addProtocolCommandListener(listener); this.configure(client); client.connect(new PunycodeConverter().convert(host.getHostname()), host.getPort()); client.setTcpNoDelay(false); return client; } catch(IOException e) { throw new FTPExceptionMappingService().map(e); } }
final Transport transport = connection.getTransport(); transport.setDisconnectListener(disconnectListener); connection.connect(HostnameConfiguratorFactory.get(host.getProtocol()).getHostname(host.getHostname()), host.getPort()); final KeepAlive keepalive = connection.getConnection().getKeepAlive(); keepalive.setKeepAliveInterval(preferences.getInteger("ssh.heartbeat.seconds"));
host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getOAuthRedirectUrl()) ); configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService)); client.setBasePath(new HostUrlProvider().withUsername(false).withPath(true).get(host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getContext())); client.setHttpClient(ClientBuilder.newClient(new ClientConfig()
@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(); }