Search in sources :

Example 1 with LoginCanceledException

use of ch.cyberduck.core.exception.LoginCanceledException in project cyberduck by iterate-ch.

the class BrickPairingSchedulerFeature method operate.

/**
 * Pool for pairing key from service
 *
 * @param callback Callback when service returns 200
 */
private void operate(final PasswordCallback callback) throws BackgroundException {
    try {
        final HttpPost resource = new HttpPost(String.format("%s/api/rest/v1/sessions/pairing_key/%s", new HostUrlProvider().withUsername(false).withPath(false).get(session.getHost()), token));
        resource.setHeader(HttpHeaders.ACCEPT, "application/json");
        resource.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
        if (log.isInfoEnabled()) {
            log.info(String.format("Fetch credentials for paring key %s from %s", token, resource));
        }
        final JsonObject json = session.getClient().execute(resource, new AbstractResponseHandler<JsonObject>() {

            @Override
            public JsonObject handleEntity(final HttpEntity entity) throws IOException {
                final ByteArrayOutputStream out = new ByteArrayOutputStream();
                IOUtils.copy(entity.getContent(), out);
                return JsonParser.parseReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray()))).getAsJsonObject();
            }
        });
        if (json.has("nickname")) {
            if (new HostPreferences(session.getHost()).getBoolean("brick.pairing.nickname.configure")) {
                final JsonPrimitive nickname = json.getAsJsonPrimitive("nickname");
                if (StringUtils.isNotBlank(host.getNickname())) {
                    if (!StringUtils.equals(host.getNickname(), nickname.getAsString())) {
                        log.warn(String.format("Mismatch of nickname. Previously authorized as %s and now paired as %s", host.getNickname(), nickname.getAsString()));
                        callback.close(null);
                        throw new LoginCanceledException();
                    }
                }
                host.setNickname(nickname.getAsString());
            }
        }
        final Credentials credentials = host.getCredentials();
        if (json.has("user_username")) {
            credentials.setUsername(json.getAsJsonPrimitive("user_username").getAsString());
        } else {
            throw new LoginFailureException(String.format("Invalid response for pairing key %s", token));
        }
        if (json.has("password")) {
            credentials.setPassword(json.getAsJsonPrimitive("password").getAsString());
        } else {
            throw new LoginFailureException(String.format("Invalid response for pairing key %s", token));
        }
        if (json.has("server")) {
            if (new HostPreferences(session.getHost()).getBoolean("brick.pairing.hostname.configure")) {
                host.setHostname(URI.create(json.getAsJsonPrimitive("server").getAsString()).getHost());
            }
        }
        callback.close(credentials.getUsername());
    } catch (JsonParseException e) {
        throw new DefaultIOExceptionMappingService().map(new IOException(e.getMessage(), e));
    } catch (HttpResponseException e) {
        switch(e.getStatusCode()) {
            case HttpStatus.SC_NOT_FOUND:
                log.warn(String.format("Missing login for pairing key %s", token));
                cancel.verify();
                break;
            default:
                throw new DefaultHttpResponseExceptionMappingService().map(e);
        }
    } catch (IOException e) {
        throw new DefaultIOExceptionMappingService().map(e);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) DefaultHttpResponseExceptionMappingService(ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService) HostUrlProvider(ch.cyberduck.core.HostUrlProvider) HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) JsonPrimitive(com.google.gson.JsonPrimitive) LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) JsonObject(com.google.gson.JsonObject) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JsonParseException(com.google.gson.JsonParseException) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) LoginFailureException(ch.cyberduck.core.exception.LoginFailureException) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) Credentials(ch.cyberduck.core.Credentials)

Example 2 with LoginCanceledException

use of ch.cyberduck.core.exception.LoginCanceledException in project cyberduck by iterate-ch.

the class AbstractS3DirectSDSTest method setup.

@Before
public void setup() throws Exception {
    session = new SDSSession(new Host(new SDSProtocol(), "duck.dracoon.com", new Credentials(System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key"))), new DisabledX509TrustManager(), new DefaultX509KeyManager());
    session.enableMetrics();
    final LoginConnectionService connect = new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException {
            throw new LoginCanceledException();
        }
    }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    connect.check(session, new DisabledCancelCallback());
}
Also used : DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) LoginConnectionService(ch.cyberduck.core.LoginConnectionService) LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) Host(ch.cyberduck.core.Host) LoginOptions(ch.cyberduck.core.LoginOptions) DisabledCancelCallback(ch.cyberduck.core.DisabledCancelCallback) DisabledHostKeyCallback(ch.cyberduck.core.DisabledHostKeyCallback) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) Credentials(ch.cyberduck.core.Credentials) Before(org.junit.Before)

Example 3 with LoginCanceledException

use of ch.cyberduck.core.exception.LoginCanceledException in project cyberduck by iterate-ch.

the class AbstractSDSTest method setup.

@Before
public void setup() throws Exception {
    session = new SDSSession(new Host(new SDSProtocol(), "duck.dracoon.com", new Credentials(System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key"))), new DisabledX509TrustManager(), new DefaultX509KeyManager());
    session.enableMetrics();
    final LoginConnectionService connect = new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException {
            throw new LoginCanceledException();
        }
    }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    connect.check(session, new DisabledCancelCallback());
}
Also used : DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) LoginConnectionService(ch.cyberduck.core.LoginConnectionService) LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) Host(ch.cyberduck.core.Host) LoginOptions(ch.cyberduck.core.LoginOptions) DisabledCancelCallback(ch.cyberduck.core.DisabledCancelCallback) DisabledHostKeyCallback(ch.cyberduck.core.DisabledHostKeyCallback) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) Credentials(ch.cyberduck.core.Credentials) Before(org.junit.Before)

Example 4 with LoginCanceledException

use of ch.cyberduck.core.exception.LoginCanceledException in project cyberduck by iterate-ch.

the class DropboxPasswordShareUrlProviderTest method testShareFileDownloadPublic.

@Test
public void testShareFileDownloadPublic() throws Exception {
    final Path file = new DropboxTouchFeature(session).touch(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    final DropboxPasswordShareUrlProvider provider = new DropboxPasswordShareUrlProvider(session);
    final DescriptiveUrl url = provider.toDownloadUrl(file, null, new DisabledPasswordCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException {
            throw new LoginCanceledException();
        }
    });
    assertNotEquals(DescriptiveUrl.EMPTY, url);
    assertEquals(url, provider.toDownloadUrl(file, null, new DisabledPasswordCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException {
            throw new LoginCanceledException();
        }
    }));
    new DropboxDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) Host(ch.cyberduck.core.Host) LoginOptions(ch.cyberduck.core.LoginOptions) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) Credentials(ch.cyberduck.core.Credentials) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDropboxTest(ch.cyberduck.core.AbstractDropboxTest)

Example 5 with LoginCanceledException

use of ch.cyberduck.core.exception.LoginCanceledException in project cyberduck by iterate-ch.

the class DropboxPasswordShareUrlProviderTest method testShareDownloadFolderPublic.

@Test
public void testShareDownloadFolderPublic() throws Exception {
    final Path folder = new DropboxDirectoryFeature(session).mkdir(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    final DropboxPasswordShareUrlProvider provider = new DropboxPasswordShareUrlProvider(session);
    final DescriptiveUrl url = provider.toDownloadUrl(folder, null, new DisabledPasswordCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException {
            throw new LoginCanceledException();
        }
    });
    assertNotEquals(DescriptiveUrl.EMPTY, url);
    assertEquals(url, provider.toDownloadUrl(folder, null, new DisabledPasswordCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException {
            throw new LoginCanceledException();
        }
    }));
    new DropboxDeleteFeature(session).delete(Collections.singletonList(folder), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) Host(ch.cyberduck.core.Host) LoginOptions(ch.cyberduck.core.LoginOptions) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) Credentials(ch.cyberduck.core.Credentials) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDropboxTest(ch.cyberduck.core.AbstractDropboxTest)

Aggregations

LoginCanceledException (ch.cyberduck.core.exception.LoginCanceledException)51 LoginOptions (ch.cyberduck.core.LoginOptions)33 Credentials (ch.cyberduck.core.Credentials)30 Host (ch.cyberduck.core.Host)30 Test (org.junit.Test)25 IntegrationTest (ch.cyberduck.test.IntegrationTest)19 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)18 DisabledCancelCallback (ch.cyberduck.core.DisabledCancelCallback)14 DisabledHostKeyCallback (ch.cyberduck.core.DisabledHostKeyCallback)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)12 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)10 LoginConnectionService (ch.cyberduck.core.LoginConnectionService)9 DefaultX509KeyManager (ch.cyberduck.core.ssl.DefaultX509KeyManager)9 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)8 Local (ch.cyberduck.core.Local)8 Path (ch.cyberduck.core.Path)8 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)8 DisabledX509TrustManager (ch.cyberduck.core.ssl.DisabledX509TrustManager)7 IOException (java.io.IOException)7