@Ignore @Test(expected = ProxyLoginFailureException.class) public void testConnectProxyInvalidCredentials() throws Exception { final Host host = new Host(new SDSProtocol(), "duck.dracoon.com", new Credentials( System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key") )); final SDSSession session = new SDSSession(host, new DefaultX509TrustManager(), new KeychainX509KeyManager(new DisabledCertificateIdentityCallback(), host, new DisabledCertificateStore())) { }; final LoginConnectionService c = new LoginConnectionService( new DisabledLoginCallback() { @Override public Credentials prompt(final Host bookmark, final String username, final String title, final String reason, final LoginOptions options) { return new Credentials("test", "n"); } }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener(), new ProxyFinder() { @Override public Proxy find(final Host target) { return new Proxy(Proxy.Type.HTTP, "localhost", 3128); } } ); c.connect(session, PathCache.empty(), new DisabledCancelCallback()); }
@Override protected SDSApiClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) throws BackgroundException { final HttpClientBuilder configuration = builder.build(proxy, this, prompt); if(PreferencesFactory.get().getBoolean("sds.oauth.migrate.enable")) { if(host.getProtocol().isDeprecated()) { final Credentials credentials = host.getCredentials(); if(!host.getCredentials().validate(host.getProtocol(), new LoginOptions(host.getProtocol()))) { log.warn(String.format("Skip migration with missing credentials for %s", host)); } else { if(log.isDebugEnabled()) { log.debug(String.format("Attempt migration to OAuth flow for %s", host)); } try { for(Protocol oauth : ProtocolFactory.get().find(new OAuthFinderPredicate(host.getProtocol().getIdentifier()))) { final TokenResponse response = new PasswordTokenRequest(new ApacheHttpTransport(builder.build(proxy, this, prompt).build()), new JacksonFactory(), new GenericUrl(Scheme.isURL(oauth.getOAuthTokenUrl()) ? oauth.getOAuthTokenUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( oauth.getScheme(), host.getPort(), null, host.getHostname(), oauth.getOAuthTokenUrl())), host.getCredentials().getUsername(), host.getCredentials().getPassword() ) .setClientAuthentication(new BasicAuthentication(oauth.getOAuthClientId(), oauth.getOAuthClientSecret())) .setRequestInitializer(new UserAgentHttpRequestInitializer(new PreferencesUseragentProvider())) .execute(); final long expiryInMilliseconds = System.currentTimeMillis() + response.getExpiresInSeconds() * 1000; credentials.setOauth(new OAuthTokens(response.getAccessToken(), response.getRefreshToken(), expiryInMilliseconds)); credentials.setSaved(true); log.warn(String.format("Switch bookmark %s to protocol %s", host, oauth)); host.setProtocol(oauth); break; } } catch(IOException e) { log.warn(String.format("Failure %s running password flow to migrate to OAuth", e)); } } } } switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: authorizationService = new OAuth2RequestInterceptor(builder.build(proxy, this, prompt).addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) { if(StringUtils.equals(((HttpRequestWrapper) request).getTarget().getHostName(), host.getHostname())) { request.addHeader(HttpHeaders.AUTHORIZATION, String.format("Basic %s", Base64.encodeToString(String.format("%s:%s", host.getProtocol().getOAuthClientId(), host.getProtocol().getOAuthClientSecret()).getBytes(StandardCharsets.UTF_8), false))); } } }).build(), host) { @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if(StringUtils.equals(((HttpRequestWrapper) request).getTarget().getHostName(), host.getHostname())) { super.process(request, context); } } } .withRedirectUri(CYBERDUCK_REDIRECT_URI.equals(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : Scheme.isURL(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getOAuthRedirectUrl()) ); try { authorizationService.withParameter("user_agent_info", Base64.encodeToString(InetAddress.getLocalHost().getHostName().getBytes(StandardCharsets.UTF_8), false)); } catch(UnknownHostException e) { throw new DefaultIOExceptionMappingService().map(e); } configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt)); configuration.addInterceptorLast(authorizationService); configuration.addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) { request.removeHeaders(SDSSession.SDS_AUTH_TOKEN_HEADER); } }); break; default: retryHandler = new SDSErrorResponseInterceptor(this); configuration.setServiceUnavailableRetryStrategy(retryHandler); configuration.addInterceptorLast(retryHandler); break; } final CloseableHttpClient apache = configuration.build(); final SDSApiClient client = new SDSApiClient(apache); final int timeout = PreferencesFactory.get().getInteger("connection.timeout.seconds") * 1000; client.setConnectTimeout(timeout); 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() .register(new InputStreamProvider()) .register(MultiPartFeature.class) .register(new JSON()) .register(JacksonFeature.class) .connectorProvider(new HttpComponentsProvider(apache)))); client.setUserAgent(new PreferencesUseragentProvider().get()); return client; }
SDSSession extends HttpSession<SDSApiClient> { @Override protected SDSApiClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) throws BackgroundException { final HttpClientBuilder configuration = builder.build(proxy, this, prompt); if(PreferencesFactory.get().getBoolean("sds.oauth.migrate.enable")) { if(host.getProtocol().isDeprecated()) { final Credentials credentials = host.getCredentials(); if(!host.getCredentials().validate(host.getProtocol(), new LoginOptions(host.getProtocol()))) { log.warn(String.format("Skip migration with missing credentials for %s", host)); } else { if(log.isDebugEnabled()) { log.debug(String.format("Attempt migration to OAuth flow for %s", host)); } try { for(Protocol oauth : ProtocolFactory.get().find(new OAuthFinderPredicate(host.getProtocol().getIdentifier()))) { final TokenResponse response = new PasswordTokenRequest(new ApacheHttpTransport(builder.build(proxy, this, prompt).build()), new JacksonFactory(), new GenericUrl(Scheme.isURL(oauth.getOAuthTokenUrl()) ? oauth.getOAuthTokenUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( oauth.getScheme(), host.getPort(), null, host.getHostname(), oauth.getOAuthTokenUrl())), host.getCredentials().getUsername(), host.getCredentials().getPassword() ) .setClientAuthentication(new BasicAuthentication(oauth.getOAuthClientId(), oauth.getOAuthClientSecret())) .setRequestInitializer(new UserAgentHttpRequestInitializer(new PreferencesUseragentProvider())) .execute(); final long expiryInMilliseconds = System.currentTimeMillis() + response.getExpiresInSeconds() * 1000; credentials.setOauth(new OAuthTokens(response.getAccessToken(), response.getRefreshToken(), expiryInMilliseconds)); credentials.setSaved(true); log.warn(String.format("Switch bookmark %s to protocol %s", host, oauth)); host.setProtocol(oauth); break; } } catch(IOException e) { log.warn(String.format("Failure %s running password flow to migrate to OAuth", e)); } } } } switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: authorizationService = new OAuth2RequestInterceptor(builder.build(proxy, this, prompt).addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) { if(StringUtils.equals(((HttpRequestWrapper) request).getTarget().getHostName(), host.getHostname())) { request.addHeader(HttpHeaders.AUTHORIZATION, String.format("Basic %s", Base64.encodeToString(String.format("%s:%s", host.getProtocol().getOAuthClientId(), host.getProtocol().getOAuthClientSecret()).getBytes(StandardCharsets.UTF_8), false))); } } }).build(), host) { @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if(StringUtils.equals(((HttpRequestWrapper) request).getTarget().getHostName(), host.getHostname())) { super.process(request, context); } } } .withRedirectUri(CYBERDUCK_REDIRECT_URI.equals(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : Scheme.isURL(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getOAuthRedirectUrl()) ); try { authorizationService.withParameter("user_agent_info", Base64.encodeToString(InetAddress.getLocalHost().getHostName().getBytes(StandardCharsets.UTF_8), false)); } catch(UnknownHostException e) { throw new DefaultIOExceptionMappingService().map(e); } configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt)); configuration.addInterceptorLast(authorizationService); configuration.addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) { request.removeHeaders(SDSSession.SDS_AUTH_TOKEN_HEADER); } }); break; default: retryHandler = new SDSErrorResponseInterceptor(this); configuration.setServiceUnavailableRetryStrategy(retryHandler); configuration.addInterceptorLast(retryHandler); break; } final CloseableHttpClient apache = configuration.build(); final SDSApiClient client = new SDSApiClient(apache); final int timeout = PreferencesFactory.get().getInteger("connection.timeout.seconds") * 1000; client.setConnectTimeout(timeout); 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() .register(new InputStreamProvider()) .register(MultiPartFeature.class) .register(new JSON()) .register(JacksonFeature.class) .connectorProvider(new HttpComponentsProvider(apache)))); client.setUserAgent(new PreferencesUseragentProvider().get()); return client; } }
SDSSession extends HttpSession<SDSApiClient> { @Override protected SDSApiClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) throws BackgroundException { final HttpClientBuilder configuration = builder.build(proxy, this, prompt); if(PreferencesFactory.get().getBoolean("sds.oauth.migrate.enable")) { if(host.getProtocol().isDeprecated()) { final Credentials credentials = host.getCredentials(); if(!host.getCredentials().validate(host.getProtocol(), new LoginOptions(host.getProtocol()))) { log.warn(String.format("Skip migration with missing credentials for %s", host)); } else { if(log.isDebugEnabled()) { log.debug(String.format("Attempt migration to OAuth flow for %s", host)); } try { for(Protocol oauth : ProtocolFactory.get().find(new OAuthFinderPredicate(host.getProtocol().getIdentifier()))) { final TokenResponse response = new PasswordTokenRequest(new ApacheHttpTransport(builder.build(proxy, this, prompt).build()), new JacksonFactory(), new GenericUrl(Scheme.isURL(oauth.getOAuthTokenUrl()) ? oauth.getOAuthTokenUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( oauth.getScheme(), host.getPort(), null, host.getHostname(), oauth.getOAuthTokenUrl())), host.getCredentials().getUsername(), host.getCredentials().getPassword() ) .setClientAuthentication(new BasicAuthentication(oauth.getOAuthClientId(), oauth.getOAuthClientSecret())) .setRequestInitializer(new UserAgentHttpRequestInitializer(new PreferencesUseragentProvider())) .execute(); final long expiryInMilliseconds = System.currentTimeMillis() + response.getExpiresInSeconds() * 1000; credentials.setOauth(new OAuthTokens(response.getAccessToken(), response.getRefreshToken(), expiryInMilliseconds)); credentials.setSaved(true); log.warn(String.format("Switch bookmark %s to protocol %s", host, oauth)); host.setProtocol(oauth); break; } } catch(IOException e) { log.warn(String.format("Failure %s running password flow to migrate to OAuth", e)); } } } } switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: authorizationService = new OAuth2RequestInterceptor(builder.build(proxy, this, prompt).addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) { if(StringUtils.equals(((HttpRequestWrapper) request).getTarget().getHostName(), host.getHostname())) { request.addHeader(HttpHeaders.AUTHORIZATION, String.format("Basic %s", Base64.encodeToString(String.format("%s:%s", host.getProtocol().getOAuthClientId(), host.getProtocol().getOAuthClientSecret()).getBytes(StandardCharsets.UTF_8), false))); } } }).build(), host) { @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if(StringUtils.equals(((HttpRequestWrapper) request).getTarget().getHostName(), host.getHostname())) { super.process(request, context); } } } .withRedirectUri(CYBERDUCK_REDIRECT_URI.equals(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : Scheme.isURL(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getOAuthRedirectUrl()) ); try { authorizationService.withParameter("user_agent_info", Base64.encodeToString(InetAddress.getLocalHost().getHostName().getBytes(StandardCharsets.UTF_8), false)); } catch(UnknownHostException e) { throw new DefaultIOExceptionMappingService().map(e); } configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt)); configuration.addInterceptorLast(authorizationService); configuration.addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) { request.removeHeaders(SDSSession.SDS_AUTH_TOKEN_HEADER); } }); break; default: retryHandler = new SDSErrorResponseInterceptor(this); configuration.setServiceUnavailableRetryStrategy(retryHandler); configuration.addInterceptorLast(retryHandler); break; } final CloseableHttpClient apache = configuration.build(); final SDSApiClient client = new SDSApiClient(apache); final int timeout = PreferencesFactory.get().getInteger("connection.timeout.seconds") * 1000; client.setConnectTimeout(timeout); 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() .register(new InputStreamProvider()) .register(MultiPartFeature.class) .register(new JSON()) .register(JacksonFeature.class) .connectorProvider(new HttpComponentsProvider(apache)))); client.setUserAgent(new PreferencesUseragentProvider().get()); return client; } SDSSession(final Host host, final X509TrustManager trust, final X509KeyManager key); }
SDSSession extends HttpSession<SDSApiClient> { @Override protected SDSApiClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) throws BackgroundException { final HttpClientBuilder configuration = builder.build(proxy, this, prompt); if(PreferencesFactory.get().getBoolean("sds.oauth.migrate.enable")) { if(host.getProtocol().isDeprecated()) { final Credentials credentials = host.getCredentials(); if(!host.getCredentials().validate(host.getProtocol(), new LoginOptions(host.getProtocol()))) { log.warn(String.format("Skip migration with missing credentials for %s", host)); } else { if(log.isDebugEnabled()) { log.debug(String.format("Attempt migration to OAuth flow for %s", host)); } try { for(Protocol oauth : ProtocolFactory.get().find(new OAuthFinderPredicate(host.getProtocol().getIdentifier()))) { final TokenResponse response = new PasswordTokenRequest(new ApacheHttpTransport(builder.build(proxy, this, prompt).build()), new JacksonFactory(), new GenericUrl(Scheme.isURL(oauth.getOAuthTokenUrl()) ? oauth.getOAuthTokenUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( oauth.getScheme(), host.getPort(), null, host.getHostname(), oauth.getOAuthTokenUrl())), host.getCredentials().getUsername(), host.getCredentials().getPassword() ) .setClientAuthentication(new BasicAuthentication(oauth.getOAuthClientId(), oauth.getOAuthClientSecret())) .setRequestInitializer(new UserAgentHttpRequestInitializer(new PreferencesUseragentProvider())) .execute(); final long expiryInMilliseconds = System.currentTimeMillis() + response.getExpiresInSeconds() * 1000; credentials.setOauth(new OAuthTokens(response.getAccessToken(), response.getRefreshToken(), expiryInMilliseconds)); credentials.setSaved(true); log.warn(String.format("Switch bookmark %s to protocol %s", host, oauth)); host.setProtocol(oauth); break; } } catch(IOException e) { log.warn(String.format("Failure %s running password flow to migrate to OAuth", e)); } } } } switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: authorizationService = new OAuth2RequestInterceptor(builder.build(proxy, this, prompt).addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) { if(StringUtils.equals(((HttpRequestWrapper) request).getTarget().getHostName(), host.getHostname())) { request.addHeader(HttpHeaders.AUTHORIZATION, String.format("Basic %s", Base64.encodeToString(String.format("%s:%s", host.getProtocol().getOAuthClientId(), host.getProtocol().getOAuthClientSecret()).getBytes(StandardCharsets.UTF_8), false))); } } }).build(), host) { @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if(StringUtils.equals(((HttpRequestWrapper) request).getTarget().getHostName(), host.getHostname())) { super.process(request, context); } } } .withRedirectUri(CYBERDUCK_REDIRECT_URI.equals(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : Scheme.isURL(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getOAuthRedirectUrl()) ); try { authorizationService.withParameter("user_agent_info", Base64.encodeToString(InetAddress.getLocalHost().getHostName().getBytes(StandardCharsets.UTF_8), false)); } catch(UnknownHostException e) { throw new DefaultIOExceptionMappingService().map(e); } configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt)); configuration.addInterceptorLast(authorizationService); configuration.addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) { request.removeHeaders(SDSSession.SDS_AUTH_TOKEN_HEADER); } }); break; default: retryHandler = new SDSErrorResponseInterceptor(this); configuration.setServiceUnavailableRetryStrategy(retryHandler); configuration.addInterceptorLast(retryHandler); break; } final CloseableHttpClient apache = configuration.build(); final SDSApiClient client = new SDSApiClient(apache); final int timeout = PreferencesFactory.get().getInteger("connection.timeout.seconds") * 1000; client.setConnectTimeout(timeout); 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() .register(new InputStreamProvider()) .register(MultiPartFeature.class) .register(new JSON()) .register(JacksonFeature.class) .connectorProvider(new HttpComponentsProvider(apache)))); client.setUserAgent(new PreferencesUseragentProvider().get()); return client; } SDSSession(final Host host, final X509TrustManager trust, final X509KeyManager key); @Override void login(final Proxy proxy, final LoginCallback controller, final CancelCallback cancel); UserAccountWrapper userAccount(); UserKeyPairContainer keyPair(); SoftwareVersionData softwareVersion(); List<KeyValueEntry> configuration(); @Override @SuppressWarnings("unchecked") T _getFeature(final Class<T> type); }
SDSSession extends HttpSession<SDSApiClient> { @Override protected SDSApiClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) throws BackgroundException { final HttpClientBuilder configuration = builder.build(proxy, this, prompt); if(PreferencesFactory.get().getBoolean("sds.oauth.migrate.enable")) { if(host.getProtocol().isDeprecated()) { final Credentials credentials = host.getCredentials(); if(!host.getCredentials().validate(host.getProtocol(), new LoginOptions(host.getProtocol()))) { log.warn(String.format("Skip migration with missing credentials for %s", host)); } else { if(log.isDebugEnabled()) { log.debug(String.format("Attempt migration to OAuth flow for %s", host)); } try { for(Protocol oauth : ProtocolFactory.get().find(new OAuthFinderPredicate(host.getProtocol().getIdentifier()))) { final TokenResponse response = new PasswordTokenRequest(new ApacheHttpTransport(builder.build(proxy, this, prompt).build()), new JacksonFactory(), new GenericUrl(Scheme.isURL(oauth.getOAuthTokenUrl()) ? oauth.getOAuthTokenUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( oauth.getScheme(), host.getPort(), null, host.getHostname(), oauth.getOAuthTokenUrl())), host.getCredentials().getUsername(), host.getCredentials().getPassword() ) .setClientAuthentication(new BasicAuthentication(oauth.getOAuthClientId(), oauth.getOAuthClientSecret())) .setRequestInitializer(new UserAgentHttpRequestInitializer(new PreferencesUseragentProvider())) .execute(); final long expiryInMilliseconds = System.currentTimeMillis() + response.getExpiresInSeconds() * 1000; credentials.setOauth(new OAuthTokens(response.getAccessToken(), response.getRefreshToken(), expiryInMilliseconds)); credentials.setSaved(true); log.warn(String.format("Switch bookmark %s to protocol %s", host, oauth)); host.setProtocol(oauth); break; } } catch(IOException e) { log.warn(String.format("Failure %s running password flow to migrate to OAuth", e)); } } } } switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: authorizationService = new OAuth2RequestInterceptor(builder.build(proxy, this, prompt).addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) { if(StringUtils.equals(((HttpRequestWrapper) request).getTarget().getHostName(), host.getHostname())) { request.addHeader(HttpHeaders.AUTHORIZATION, String.format("Basic %s", Base64.encodeToString(String.format("%s:%s", host.getProtocol().getOAuthClientId(), host.getProtocol().getOAuthClientSecret()).getBytes(StandardCharsets.UTF_8), false))); } } }).build(), host) { @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if(StringUtils.equals(((HttpRequestWrapper) request).getTarget().getHostName(), host.getHostname())) { super.process(request, context); } } } .withRedirectUri(CYBERDUCK_REDIRECT_URI.equals(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : Scheme.isURL(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : new HostUrlProvider().withUsername(false).withPath(true).get( host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getOAuthRedirectUrl()) ); try { authorizationService.withParameter("user_agent_info", Base64.encodeToString(InetAddress.getLocalHost().getHostName().getBytes(StandardCharsets.UTF_8), false)); } catch(UnknownHostException e) { throw new DefaultIOExceptionMappingService().map(e); } configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt)); configuration.addInterceptorLast(authorizationService); configuration.addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) { request.removeHeaders(SDSSession.SDS_AUTH_TOKEN_HEADER); } }); break; default: retryHandler = new SDSErrorResponseInterceptor(this); configuration.setServiceUnavailableRetryStrategy(retryHandler); configuration.addInterceptorLast(retryHandler); break; } final CloseableHttpClient apache = configuration.build(); final SDSApiClient client = new SDSApiClient(apache); final int timeout = PreferencesFactory.get().getInteger("connection.timeout.seconds") * 1000; client.setConnectTimeout(timeout); 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() .register(new InputStreamProvider()) .register(MultiPartFeature.class) .register(new JSON()) .register(JacksonFeature.class) .connectorProvider(new HttpComponentsProvider(apache)))); client.setUserAgent(new PreferencesUseragentProvider().get()); return client; } SDSSession(final Host host, final X509TrustManager trust, final X509KeyManager key); @Override void login(final Proxy proxy, final LoginCallback controller, final CancelCallback cancel); UserAccountWrapper userAccount(); UserKeyPairContainer keyPair(); SoftwareVersionData softwareVersion(); List<KeyValueEntry> configuration(); @Override @SuppressWarnings("unchecked") T _getFeature(final Class<T> type); static final String SDS_AUTH_TOKEN_HEADER; static final int DEFAULT_CHUNKSIZE; static final String VERSION_REGEX; }