Search in sources :

Example 26 with HostPreferences

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;
    }
}
Also used : UserAgentHttpRequestInitializer(ch.cyberduck.core.http.UserAgentHttpRequestInitializer) KeychainX509KeyManager(ch.cyberduck.core.ssl.KeychainX509KeyManager) DisabledCertificateIdentityCallback(ch.cyberduck.core.DisabledCertificateIdentityCallback) ProxyHostUrlProvider(ch.cyberduck.core.proxy.ProxyHostUrlProvider) GenericUrl(com.google.api.client.http.GenericUrl) DAVSSLProtocol(ch.cyberduck.core.dav.DAVSSLProtocol) KeychainX509TrustManager(ch.cyberduck.core.ssl.KeychainX509TrustManager) HttpExceptionMappingService(ch.cyberduck.core.http.HttpExceptionMappingService) HttpConnectionPoolBuilder(ch.cyberduck.core.http.HttpConnectionPoolBuilder) KeychainX509KeyManager(ch.cyberduck.core.ssl.KeychainX509KeyManager) X509KeyManager(ch.cyberduck.core.ssl.X509KeyManager) DisabledCertificateTrustCallback(ch.cyberduck.core.DisabledCertificateTrustCallback) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) GsonFactory(com.google.api.client.json.gson.GsonFactory) Host(ch.cyberduck.core.Host) IOException(java.io.IOException) DisabledTranscriptListener(ch.cyberduck.core.DisabledTranscriptListener) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) TokenResponse(com.google.api.client.auth.oauth2.TokenResponse) X509TrustManager(ch.cyberduck.core.ssl.X509TrustManager) KeychainX509TrustManager(ch.cyberduck.core.ssl.KeychainX509TrustManager) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) ThreadLocalHostnameDelegatingTrustManager(ch.cyberduck.core.ssl.ThreadLocalHostnameDelegatingTrustManager) DefaultTrustManagerHostnameCallback(ch.cyberduck.core.ssl.DefaultTrustManagerHostnameCallback) BasicAuthentication(com.google.api.client.http.BasicAuthentication) PasswordTokenRequest(com.google.api.client.auth.oauth2.PasswordTokenRequest) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport) BackgroundException(ch.cyberduck.core.exception.BackgroundException)

Example 27 with HostPreferences

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;
            }
        }
    }
}
Also used : Path(ch.cyberduck.core.Path) Partition(ch.cyberduck.core.collections.Partition) BatchRequest(com.google.api.client.googleapis.batch.BatchRequest) IOException(java.io.IOException) BackgroundException(ch.cyberduck.core.exception.BackgroundException) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 28 with HostPreferences

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;
            }
        }
    }
}
Also used : Path(ch.cyberduck.core.Path) Partition(ch.cyberduck.core.collections.Partition) BatchRequest(com.google.api.client.googleapis.batch.BatchRequest) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) IOException(java.io.IOException) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) File(com.google.api.services.drive.model.File) BackgroundException(ch.cyberduck.core.exception.BackgroundException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 29 with HostPreferences

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();
}
Also used : UseragentProvider(ch.cyberduck.core.UseragentProvider) PreferencesUseragentProvider(ch.cyberduck.core.PreferencesUseragentProvider) GsonFactory(com.google.api.client.json.gson.GsonFactory) UserAgentHttpRequestInitializer(ch.cyberduck.core.http.UserAgentHttpRequestInitializer) OAuth2RequestInterceptor(ch.cyberduck.core.oauth.OAuth2RequestInterceptor) DefaultHttpRateLimiter(ch.cyberduck.core.http.DefaultHttpRateLimiter) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) OAuth2ErrorResponseInterceptor(ch.cyberduck.core.oauth.OAuth2ErrorResponseInterceptor) PreferencesUseragentProvider(ch.cyberduck.core.PreferencesUseragentProvider) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) RateLimitingHttpRequestInterceptor(ch.cyberduck.core.http.RateLimitingHttpRequestInterceptor) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 30 with HostPreferences

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);
    }
}
Also used : DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) IOException(java.io.IOException) File(com.google.api.services.drive.model.File) DateTime(com.google.api.client.util.DateTime) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Aggregations

HostPreferences (ch.cyberduck.core.preferences.HostPreferences)81 IOException (java.io.IOException)33 Path (ch.cyberduck.core.Path)29 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)18 BackgroundException (ch.cyberduck.core.exception.BackgroundException)12 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)11 PathAttributes (ch.cyberduck.core.PathAttributes)11 NotfoundException (ch.cyberduck.core.exception.NotfoundException)11 File (com.google.api.services.drive.model.File)10 AttributedList (ch.cyberduck.core.AttributedList)8 URI (java.net.URI)8 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)7 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)6 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)6 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)6 MemorySegementingOutputStream (ch.cyberduck.core.io.MemorySegementingOutputStream)6 NodesApi (ch.cyberduck.core.sds.io.swagger.client.api.NodesApi)5 Credentials (ch.cyberduck.core.Credentials)4 Partition (ch.cyberduck.core.collections.Partition)4 S3Protocol (ch.cyberduck.core.s3.S3Protocol)4