@Override
    public void login(final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
        try {
            final String accountId = host.getCredentials().getUsername();
            final String applicationKey = host.getCredentials().getPassword();
            // Save tokens for 401 error response when expired
            final B2AuthorizeAccountResponse response = client.authenticate(accountId, applicationKey);
            // When present, access is restricted to one bucket
            if(StringUtils.isNotBlank(response.getBucketId())) {
                final PathAttributes attributes = new PathAttributes();
                attributes.setVersionId(response.getBucketId());
                listService.withBucket(new Path(PathNormalizer.normalize(response.getBucketName()), EnumSet.of(Path.Type.directory, Path.Type.volume), attributes));
            }
            retryHandler.setTokens(accountId, applicationKey, response.getAuthorizationToken());
            if(new HostPreferences(host).getBoolean("b2.upload.largeobject.auto")) {
                final int recommendedPartSize = response.getRecommendedPartSize();
                if(log.isDebugEnabled()) {
                    log.debug(String.format("Set large upload part size to %d", recommendedPartSize));
                }
                host.setProperty("b2.upload.largeobject.size", String.valueOf(recommendedPartSize));
                host.setProperty("b2.copy.largeobject.size", String.valueOf(recommendedPartSize));
                final int absoluteMinimumPartSize = response.getAbsoluteMinimumPartSize();
                if(log.isDebugEnabled()) {
                    log.debug(String.format("Set large upload minimum part size to %d", absoluteMinimumPartSize));
                }
                host.setProperty("b2.upload.largeobject.size.minimum", String.valueOf(absoluteMinimumPartSize));
            }
        }
        catch(B2ApiException e) {
            throw new B2ExceptionMappingService(fileid).map(e);
        }
        catch(IOException e) {
            throw new DefaultIOExceptionMappingService().map(e);
        }
    }
@Test(expected = LoginFailureException.class)
    public void testLoginFailure() throws Exception {
        final Host host = new Host(new ProfilePlistReader(new ProtocolFactory(Collections.singleton(new B2Protocol()))).read(
                this.getClass().getResourceAsStream("/B2.cyberduckprofile")), new Credentials(
                System.getProperties().getProperty("b2.user"), "s"
        ));
        final B2Session session = new B2Session(host, new DefaultX509TrustManager(), new DefaultX509KeyManager());
        session.open(new DisabledProxyFinder(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
        session.login(new DisabledLoginCallback(), new DisabledCancelCallback());
    }