Search in sources :

Example 1 with Credentials

use of ch.cyberduck.core.Credentials in project cyberduck by iterate-ch.

the class BoxSession method login.

@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
    authorizationService.setTokens(authorizationService.authorize(host, prompt, cancel, OAuth2AuthorizationService.FlowType.AuthorizationCode));
    try {
        final Credentials credentials = host.getCredentials();
        credentials.setUsername(new UsersApi(new BoxApiClient(client)).getUsersMe(Collections.emptyList()).getLogin());
        credentials.setSaved(true);
    } catch (ApiException e) {
        throw new BoxExceptionMappingService(fileid).map(e);
    }
}
Also used : UsersApi(ch.cyberduck.core.box.io.swagger.client.api.UsersApi) Credentials(ch.cyberduck.core.Credentials) ApiException(ch.cyberduck.core.box.io.swagger.client.ApiException)

Example 2 with Credentials

use of ch.cyberduck.core.Credentials 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 3 with Credentials

use of ch.cyberduck.core.Credentials in project cyberduck by iterate-ch.

the class AbstractBrickTest method setup.

@Before
public void setup() throws Exception {
    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new BrickProtocol())));
    final Profile profile = new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/Brick.cyberduckprofile"));
    final Host host = new Host(profile, "mountainduck.files.com", new Credentials(System.getProperties().getProperty("brick.user"), System.getProperties().getProperty("brick.password")));
    session = new BrickSession(host, new DefaultX509TrustManager(), new DefaultX509KeyManager());
    final LoginConnectionService login = new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) {
            fail(reason);
            return null;
        }
    }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    login.check(session, new DisabledCancelCallback());
}
Also used : DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) LoginConnectionService(ch.cyberduck.core.LoginConnectionService) Host(ch.cyberduck.core.Host) ProfilePlistReader(ch.cyberduck.core.serializer.impl.dd.ProfilePlistReader) Profile(ch.cyberduck.core.Profile) ProtocolFactory(ch.cyberduck.core.ProtocolFactory) 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) DefaultX509TrustManager(ch.cyberduck.core.ssl.DefaultX509TrustManager) Before(org.junit.Before)

Example 4 with Credentials

use of ch.cyberduck.core.Credentials in project cyberduck by iterate-ch.

the class AbtractBoxTest method setup.

@Before
public void setup() throws Exception {
    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new BoxProtocol())));
    final Profile profile = new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/Box.cyberduckprofile"));
    final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials("cyberduck"));
    session = new BoxSession(host, new DefaultX509TrustManager(), new DefaultX509KeyManager());
    final LoginConnectionService login = new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) {
            fail(reason);
            return null;
        }
    }, new DisabledHostKeyCallback(), new TestPasswordStore(), new DisabledProgressListener());
    login.check(session, new DisabledCancelCallback());
}
Also used : DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) LoginConnectionService(ch.cyberduck.core.LoginConnectionService) Host(ch.cyberduck.core.Host) ProfilePlistReader(ch.cyberduck.core.serializer.impl.dd.ProfilePlistReader) Profile(ch.cyberduck.core.Profile) ProtocolFactory(ch.cyberduck.core.ProtocolFactory) 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) Credentials(ch.cyberduck.core.Credentials) DefaultX509TrustManager(ch.cyberduck.core.ssl.DefaultX509TrustManager) Before(org.junit.Before)

Example 5 with Credentials

use of ch.cyberduck.core.Credentials in project cyberduck by iterate-ch.

the class CallbackProxyAuthenticationStrategy method authSucceeded.

@Override
public void authSucceeded(final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final Credentials credentials = clientContext.getAttribute(PROXY_CREDENTIALS_INPUT_ID, Credentials.class);
    if (null != credentials) {
        clientContext.removeAttribute(PROXY_CREDENTIALS_INPUT_ID);
        if (log.isInfoEnabled()) {
            log.info(String.format("Save passphrase for proxy %s", authhost));
        }
        keychain.addCredentials(authhost.toURI(), credentials.getUsername(), credentials.getPassword());
    }
    super.authSucceeded(authhost, authScheme, context);
}
Also used : HttpClientContext(org.apache.http.client.protocol.HttpClientContext) NTCredentials(org.apache.http.auth.NTCredentials) Credentials(ch.cyberduck.core.Credentials)

Aggregations

Credentials (ch.cyberduck.core.Credentials)252 Host (ch.cyberduck.core.Host)201 Test (org.junit.Test)189 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)165 IntegrationTest (ch.cyberduck.test.IntegrationTest)156 Path (ch.cyberduck.core.Path)138 DisabledCancelCallback (ch.cyberduck.core.DisabledCancelCallback)137 DisabledHostKeyCallback (ch.cyberduck.core.DisabledHostKeyCallback)134 DefaultX509KeyManager (ch.cyberduck.core.ssl.DefaultX509KeyManager)103 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)95 LoginOptions (ch.cyberduck.core.LoginOptions)92 DisabledX509TrustManager (ch.cyberduck.core.ssl.DisabledX509TrustManager)84 Delete (ch.cyberduck.core.features.Delete)76 Local (ch.cyberduck.core.Local)60 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)56 ProtocolFactory (ch.cyberduck.core.ProtocolFactory)55 ProfilePlistReader (ch.cyberduck.core.serializer.impl.dd.ProfilePlistReader)55 Scheme (ch.cyberduck.core.Scheme)52 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)51 Profile (ch.cyberduck.core.Profile)50