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);
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations