use of ch.cyberduck.core.exception.ResolveFailedException in project cyberduck by iterate-ch.
the class S3Session method login.
@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
if (Scheme.isURL(host.getProtocol().getContext())) {
try {
final Credentials temporary = new AWSSessionCredentialsRetriever(trust, key, this, host.getProtocol().getContext()).get();
client.setProviderCredentials(new AWSSessionCredentials(temporary.getUsername(), temporary.getPassword(), temporary.getToken()));
} catch (ConnectionTimeoutException | ConnectionRefusedException | ResolveFailedException | NotfoundException | InteroperabilityException e) {
log.warn(String.format("Failure to retrieve session credentials from . %s", e.getMessage()));
throw new LoginFailureException(e.getDetail(false), e);
}
} else {
final Credentials credentials;
// Only for AWS
if (isAwsHostname(host.getHostname())) {
// Try auto-configure
credentials = new STSCredentialsConfigurator(new ThreadLocalHostnameDelegatingTrustManager(trust, host.getHostname()), key, prompt).configure(host);
} else {
credentials = host.getCredentials();
}
if (StringUtils.isNotBlank(credentials.getToken())) {
client.setProviderCredentials(credentials.isAnonymousLogin() ? null : new AWSSessionCredentials(credentials.getUsername(), credentials.getPassword(), credentials.getToken()));
} else {
client.setProviderCredentials(credentials.isAnonymousLogin() ? null : new AWSCredentials(credentials.getUsername(), credentials.getPassword()));
}
}
if (host.getCredentials().isPassed()) {
log.warn(String.format("Skip verifying credentials with previous successful authentication event for %s", this));
return;
}
try {
final Location.Name location = new S3PathStyleFallbackAdapter<>(this, new BackgroundExceptionCallable<Location.Name>() {
@Override
public Location.Name call() throws BackgroundException {
return new S3LocationFeature(S3Session.this, client.getRegionEndpointCache()).getLocation(new DelegatingHomeFeature(new DefaultPathHomeFeature(host)).find());
}
}).call();
if (log.isDebugEnabled()) {
log.debug(String.format("Retrieved region %s", location));
}
if (!Location.unknown.equals(location)) {
client.getConfiguration().setProperty("storage-service.default-region", location.getIdentifier());
}
} catch (AccessDeniedException | InteroperabilityException e) {
log.warn(String.format("Failure %s querying region", e));
final Path home = new DefaultHomeFinderService(this).find();
if (log.isDebugEnabled()) {
log.debug(String.format("Retrieved %s", home));
}
}
}
use of ch.cyberduck.core.exception.ResolveFailedException in project cyberduck by iterate-ch.
the class Resolver method resolve.
/**
* This method is blocking until the hostname has been resolved or the lookup has been canceled using #cancel
*
* @return The resolved IP address for this hostname
* @throws ResolveFailedException If the hostname cannot be resolved
* @throws ResolveCanceledException If the lookup has been interrupted
*/
public InetAddress resolve(final String hostname, final CancelCallback callback) throws ResolveFailedException, ResolveCanceledException {
final CountDownLatch signal = new CountDownLatch(1);
final AtomicReference<InetAddress> resolved = new AtomicReference<>();
final AtomicReference<UnknownHostException> failure = new AtomicReference<>();
final Thread resolver = threadFactory.newThread(new Runnable() {
@Override
public void run() {
try {
final InetAddress[] allByName = InetAddress.getAllByName(hostname);
Arrays.stream(allByName).findFirst().ifPresent(resolved::set);
if (preferIPv6) {
Arrays.stream(allByName).filter(inetAddress -> inetAddress instanceof Inet6Address).findFirst().ifPresent(resolved::set);
}
if (log.isInfoEnabled()) {
log.info(String.format("Resolved %s to %s", hostname, resolved.get().getHostAddress()));
}
} catch (UnknownHostException e) {
log.warn(String.format("Failed resolving %s", hostname));
failure.set(e);
} finally {
signal.countDown();
}
}
});
resolver.start();
log.debug(String.format("Waiting for resolving of %s", hostname));
// Wait for #run to finish
while (!Uninterruptibles.awaitUninterruptibly(signal, 500, TimeUnit.MILLISECONDS)) {
try {
callback.verify();
} catch (ConnectionCanceledException c) {
throw new ResolveCanceledException(MessageFormat.format(LocaleFactory.localizedString("DNS lookup for {0} failed", "Error"), hostname), c);
}
}
try {
callback.verify();
} catch (ConnectionCanceledException c) {
throw new ResolveCanceledException(MessageFormat.format(LocaleFactory.localizedString("DNS lookup for {0} failed", "Error"), hostname), c);
}
if (null == resolved.get()) {
if (null == failure.get()) {
log.warn(String.format("Canceled resolving %s", hostname));
throw new ResolveCanceledException(MessageFormat.format(LocaleFactory.localizedString("DNS lookup for {0} failed", "Error"), hostname));
}
throw new ResolveFailedException(MessageFormat.format(LocaleFactory.localizedString("DNS lookup for {0} failed", "Error"), hostname), failure.get());
}
return resolved.get();
}
use of ch.cyberduck.core.exception.ResolveFailedException in project cyberduck by iterate-ch.
the class LoginConnectionService method connect.
@Override
public void connect(final Session<?> session, final CancelCallback cancel) throws BackgroundException {
if (session.isConnected()) {
this.close(session);
}
final Host bookmark = session.getHost();
// Try to resolve the hostname first
final String hostname = HostnameConfiguratorFactory.get(bookmark.getProtocol()).getHostname(bookmark.getHostname());
listener.message(MessageFormat.format(LocaleFactory.localizedString("Resolving {0}", "Status"), hostname));
final Proxy proxy = this.proxy.find(new ProxyHostUrlProvider().get(bookmark));
if (proxy == Proxy.DIRECT) {
// Only try to resolve target hostname if direct connection
if (null == JumpHostConfiguratorFactory.get(bookmark.getProtocol()).getJumphost(bookmark.getHostname())) {
// Do not attempt to resolve hostname that may only be reachable in internal network from jump host
try {
resolver.resolve(hostname, cancel);
} catch (ResolveFailedException e) {
log.warn(String.format("DNS resolver failed for %s", hostname));
throw e;
}
}
}
listener.message(MessageFormat.format(LocaleFactory.localizedString("Opening {0} connection to {1}", "Status"), bookmark.getProtocol().getName(), hostname));
// The IP address could successfully be determined
session.open(proxy, key, prompt, cancel);
listener.message(MessageFormat.format(LocaleFactory.localizedString("{0} connection opened", "Status"), bookmark.getProtocol().getName()));
// Update last accessed timestamp
bookmark.setTimestamp(new Date());
// Warning about insecure connection prior authenticating
if (session.alert(prompt)) {
// Warning if credentials are sent plaintext.
prompt.warn(bookmark, MessageFormat.format(LocaleFactory.localizedString("Unsecured {0} connection", "Credentials"), bookmark.getProtocol().getName()), MessageFormat.format("{0} {1}.", MessageFormat.format(LocaleFactory.localizedString("{0} will be sent in plaintext.", "Credentials"), bookmark.getProtocol().getPasswordPlaceholder()), LocaleFactory.localizedString("Please contact your web hosting service provider for assistance", "Support")), LocaleFactory.localizedString("Continue", "Credentials"), LocaleFactory.localizedString("Disconnect", "Credentials"), String.format("connection.unsecure.%s", bookmark.getHostname()));
}
// Login
try {
this.authenticate(proxy, session, cancel);
} catch (BackgroundException e) {
this.close(session);
throw e;
}
}
Aggregations