use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.
the class FreenetAuthenticatedUrlProvider method toUrl.
@Override
public DescriptiveUrl toUrl(final Host bookmark) {
try {
// Run password flow
final TokenResponse response;
try {
final Host target = new Host(new DAVSSLProtocol(), "oauth.freenet.de");
final X509TrustManager trust = new KeychainX509TrustManager(new DisabledCertificateTrustCallback(), new DefaultTrustManagerHostnameCallback(target), CertificateStoreFactory.get());
final X509KeyManager key = new KeychainX509KeyManager(new DisabledCertificateIdentityCallback(), target, CertificateStoreFactory.get());
final CloseableHttpClient client = new HttpConnectionPoolBuilder(target, new ThreadLocalHostnameDelegatingTrustManager(trust, target.getHostname()), key, ProxyFactory.get()).build(ProxyFactory.get().find(new ProxyHostUrlProvider().get(target)), new DisabledTranscriptListener(), new DisabledLoginCallback()).setUserAgent(new FreenetUserAgentProvider().get()).build();
final String username = bookmark.getCredentials().getUsername();
final String password;
if (StringUtils.isBlank(bookmark.getCredentials().getPassword())) {
password = PasswordStoreFactory.get().findLoginPassword(bookmark);
} else {
password = bookmark.getCredentials().getPassword();
}
response = new PasswordTokenRequest(new ApacheHttpTransport(client), new GsonFactory(), new GenericUrl("https://oauth.freenet.de/oauth/token"), username, password).setClientAuthentication(new BasicAuthentication("desktop_client", "6LIGIHuOSkznLomu5xw0EPPBJOXb2jLp")).setRequestInitializer(new UserAgentHttpRequestInitializer(new FreenetUserAgentProvider())).set("world", new HostPreferences(bookmark).getProperty("world")).set("webLogin", Boolean.TRUE).execute();
final FreenetTemporaryLoginResponse login = this.getLoginSession(client, response.getAccessToken());
return new DescriptiveUrl(URI.create(login.urls.login), DescriptiveUrl.Type.authenticated);
} catch (IOException e) {
throw new HttpExceptionMappingService().map(e);
}
} catch (BackgroundException e) {
log.warn(String.format("Failure %s retrieving authenticated URL for %s", e, bookmark));
return DescriptiveUrl.EMPTY;
}
}
use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.
the class DriveBatchDeleteFeature method delete.
@Override
public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException {
// Must split otherwise 413 Request Entity Too Large is returned
for (List<Path> partition : new Partition<>(new ArrayList<>(files.keySet()), new HostPreferences(session.getHost()).getInteger("googledrive.delete.multiple.partition"))) {
final BatchRequest batch = session.getClient().batch();
final List<BackgroundException> failures = new CopyOnWriteArrayList<>();
for (Path file : partition) {
try {
this.queue(file, batch, callback, failures);
} catch (IOException e) {
throw new DriveExceptionMappingService(fileid).map("Cannot delete {0}", e, file);
}
}
if (!partition.isEmpty()) {
try {
batch.execute();
} catch (IOException e) {
throw new DriveExceptionMappingService(fileid).map(e);
}
for (BackgroundException e : failures) {
throw e;
}
}
}
}
use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.
the class DriveBatchTrashFeature method delete.
@Override
public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException {
// Must split otherwise 413 Request Entity Too Large is returned
for (List<Path> partition : new Partition<>(new ArrayList<>(files.keySet()), new HostPreferences(session.getHost()).getInteger("googledrive.delete.multiple.partition"))) {
final BatchRequest batch = session.getClient().batch();
final List<BackgroundException> failures = new CopyOnWriteArrayList<>();
for (Path f : partition) {
try {
if (DriveHomeFinderService.SHARED_DRIVES_NAME.equals(f.getParent())) {
session.getClient().teamdrives().delete(fileid.getFileId(f, new DisabledListProgressListener())).queue(batch, new DeleteBatchCallback<>(f, failures, callback));
} else {
if (f.attributes().isDuplicate()) {
log.warn(String.format("Delete file %s already in trash", f));
new DriveBatchDeleteFeature(session, fileid).queue(f, batch, callback, failures);
continue;
}
final File properties = new File();
properties.setTrashed(true);
session.getClient().files().update(fileid.getFileId(f, new DisabledListProgressListener()), properties).setSupportsAllDrives(new HostPreferences(session.getHost()).getBoolean("googledrive.teamdrive.enable")).queue(batch, new DeleteBatchCallback<>(f, failures, callback));
}
} catch (IOException e) {
throw new DriveExceptionMappingService(fileid).map("Cannot delete {0}", e, f);
}
}
if (!partition.isEmpty()) {
try {
batch.execute();
} catch (IOException e) {
throw new DriveExceptionMappingService(fileid).map(e);
}
for (BackgroundException e : failures) {
throw e;
}
}
}
}
use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.
the class DriveSession method connect.
@Override
protected Drive connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt, final CancelCallback cancel) throws HostParserException {
final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
authorizationService = new OAuth2RequestInterceptor(builder.build(ProxyFactory.get().find(host.getProtocol().getOAuthAuthorizationUrl()), this, prompt).build(), host.getProtocol()).withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
configuration.addInterceptorLast(authorizationService);
configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt));
configuration.addInterceptorLast(new RateLimitingHttpRequestInterceptor(new DefaultHttpRateLimiter(new HostPreferences(host).getInteger("googledrive.limit.requests.second"))));
this.transport = new ApacheHttpTransport(configuration.build());
final UseragentProvider ua = new PreferencesUseragentProvider();
return new Drive.Builder(transport, new GsonFactory(), new UserAgentHttpRequestInitializer(ua)).setApplicationName(ua.get()).build();
}
use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.
the class DriveTimestampFeature method setTimestamp.
@Override
public void setTimestamp(final Path file, final TransferStatus status) throws BackgroundException {
try {
final String fileid = this.fileid.getFileId(file, new DisabledListProgressListener());
final File properties = new File();
properties.setModifiedTime(new DateTime(status.getTimestamp()));
session.getClient().files().update(fileid, properties).setFields("modifiedTime").setSupportsAllDrives(new HostPreferences(session.getHost()).getBoolean("googledrive.teamdrive.enable")).execute();
} catch (IOException e) {
throw new DriveExceptionMappingService(fileid).map("Failure to write attributes of {0}", e, file);
}
}
Aggregations