Search in sources :

Example 16 with AuthenticatorException

use of android.accounts.AuthenticatorException in project robolectric by robolectric.

the class ShadowAccountManager method getAuthToken.

private Bundle getAuthToken(Account account, String authTokenType) throws OperationCanceledException, IOException, AuthenticatorException {
    Bundle result = new Bundle();
    String authToken = blockingGetAuthToken(account, authTokenType, false);
    result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
    result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
    result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
    if (authToken != null) {
        return result;
    }
    if (!authenticators.containsKey(account.type)) {
        throw new AuthenticatorException("No authenticator specified for " + account.type);
    }
    Intent resultIntent = new Intent();
    result.putParcelable(AccountManager.KEY_INTENT, resultIntent);
    return result;
}
Also used : Bundle(android.os.Bundle) AuthenticatorException(android.accounts.AuthenticatorException) Intent(android.content.Intent)

Example 17 with AuthenticatorException

use of android.accounts.AuthenticatorException in project Android-AccountChooser by frakbot.

the class ChooseTypeAndAccountActivity method run.

@Override
public void run(final AccountManagerFuture<Bundle> accountManagerFuture) {
    try {
        final Bundle accountManagerResult = accountManagerFuture.getResult();
        final Intent intent = (Intent) accountManagerResult.getParcelable(AccountManager.KEY_INTENT);
        if (intent != null) {
            mPendingRequest = REQUEST_ADD_ACCOUNT;
            mExistingAccounts = AccountManager.get(this).getAccounts();
            intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivityForResult(intent, REQUEST_ADD_ACCOUNT);
            return;
        }
    } catch (OperationCanceledException e) {
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    } catch (IOException e) {
    } catch (AuthenticatorException e) {
    }
    Bundle bundle = new Bundle();
    bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error communicating with server");
    setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
    finish();
}
Also used : Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) Intent(android.content.Intent) IOException(java.io.IOException)

Example 18 with AuthenticatorException

use of android.accounts.AuthenticatorException in project TaEmCasa by Dionen.

the class AndroidAuthenticatorTest method failedGetAuthToken.

@Test(expected = AuthFailureError.class)
public void failedGetAuthToken() throws Exception {
    when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture);
    when(mFuture.getResult()).thenThrow(new AuthenticatorException("sadness!"));
    mAuthenticator.getAuthToken();
}
Also used : AuthenticatorException(android.accounts.AuthenticatorException) Test(org.junit.Test)

Example 19 with AuthenticatorException

use of android.accounts.AuthenticatorException in project android by nextcloud.

the class PushUtils method pushRegistrationToServer.

public static void pushRegistrationToServer(final UserAccountManager accountManager, final String token) {
    arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());
    if (!TextUtils.isEmpty(MainApp.getAppContext().getResources().getString(R.string.push_server_url)) && !TextUtils.isEmpty(token)) {
        PushUtils.generateRsa2048KeyPair();
        String pushTokenHash = PushUtils.generateSHA512Hash(token).toLowerCase(Locale.ROOT);
        PublicKey devicePublicKey = (PublicKey) PushUtils.readKeyFromFile(true);
        if (devicePublicKey != null) {
            byte[] publicKeyBytes = Base64.encode(devicePublicKey.getEncoded(), Base64.NO_WRAP);
            String publicKey = new String(publicKeyBytes);
            publicKey = publicKey.replaceAll("(.{64})", "$1\n");
            publicKey = "-----BEGIN PUBLIC KEY-----\n" + publicKey + "\n-----END PUBLIC KEY-----\n";
            Context context = MainApp.getAppContext();
            String providerValue;
            PushConfigurationState accountPushData;
            Gson gson = new Gson();
            for (Account account : accountManager.getAccounts()) {
                providerValue = arbitraryDataProvider.getValue(account.name, KEY_PUSH);
                if (!TextUtils.isEmpty(providerValue)) {
                    accountPushData = gson.fromJson(providerValue, PushConfigurationState.class);
                } else {
                    accountPushData = null;
                }
                if (accountPushData != null && !accountPushData.getPushToken().equals(token) && !accountPushData.isShouldBeDeleted() || TextUtils.isEmpty(providerValue)) {
                    try {
                        OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
                        OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context);
                        RemoteOperationResult remoteOperationResult = new RegisterAccountDeviceForNotificationsOperation(pushTokenHash, publicKey, context.getResources().getString(R.string.push_server_url)).execute(client);
                        if (remoteOperationResult.isSuccess()) {
                            PushResponse pushResponse = remoteOperationResult.getPushResponseData();
                            RemoteOperationResult resultProxy = new RegisterAccountDeviceForProxyOperation(context.getResources().getString(R.string.push_server_url), token, pushResponse.getDeviceIdentifier(), pushResponse.getSignature(), pushResponse.getPublicKey(), MainApp.getUserAgent()).run();
                            if (resultProxy.isSuccess()) {
                                PushConfigurationState pushArbitraryData = new PushConfigurationState(token, pushResponse.getDeviceIdentifier(), pushResponse.getSignature(), pushResponse.getPublicKey(), false);
                                arbitraryDataProvider.storeOrUpdateKeyValue(account.name, KEY_PUSH, gson.toJson(pushArbitraryData));
                            }
                        } else if (remoteOperationResult.getCode() == RemoteOperationResult.ResultCode.ACCOUNT_USES_STANDARD_PASSWORD) {
                            arbitraryDataProvider.storeOrUpdateKeyValue(account.name, UserAccountManager.ACCOUNT_USES_STANDARD_PASSWORD, "true");
                        }
                    } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
                        Log_OC.d(TAG, "Failed to find an account");
                    } catch (AuthenticatorException e) {
                        Log_OC.d(TAG, "Failed via AuthenticatorException");
                    } catch (IOException e) {
                        Log_OC.d(TAG, "Failed via IOException");
                    } catch (OperationCanceledException e) {
                        Log_OC.d(TAG, "Failed via OperationCanceledException");
                    }
                } else if (accountPushData != null && accountPushData.isShouldBeDeleted()) {
                    deleteRegistrationForAccount(account);
                }
            }
        }
    }
}
Also used : Context(android.content.Context) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) PublicKey(java.security.PublicKey) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OperationCanceledException(android.accounts.OperationCanceledException) RegisterAccountDeviceForNotificationsOperation(com.owncloud.android.lib.resources.notifications.RegisterAccountDeviceForNotificationsOperation) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Gson(com.google.gson.Gson) AuthenticatorException(android.accounts.AuthenticatorException) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) IOException(java.io.IOException) RegisterAccountDeviceForProxyOperation(com.owncloud.android.lib.resources.notifications.RegisterAccountDeviceForProxyOperation) PushConfigurationState(com.owncloud.android.datamodel.PushConfigurationState) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient) PushResponse(com.owncloud.android.lib.resources.notifications.models.PushResponse)

Example 20 with AuthenticatorException

use of android.accounts.AuthenticatorException in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ProtectedAccountView method asyncCheckPassword.

private void asyncCheckPassword() {
    final String login = mLogin.getText().toString();
    final String password = mPassword.getText().toString();
    Account account = findIntendedAccount(login);
    if (account == null) {
        postOnCheckPasswordResult(false);
        return;
    }
    getProgressDialog().show();
    Bundle options = new Bundle();
    options.putString(AccountManager.KEY_PASSWORD, password);
    AccountManager.get(mContext).confirmCredentialsAsUser(account, options, null, /* activity */
    new AccountManagerCallback<Bundle>() {

        public void run(AccountManagerFuture<Bundle> future) {
            try {
                final Bundle result = future.getResult();
                final boolean verified = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
                postOnCheckPasswordResult(verified);
            } catch (OperationCanceledException e) {
                postOnCheckPasswordResult(false);
            } catch (IOException e) {
                postOnCheckPasswordResult(false);
            } catch (AuthenticatorException e) {
                postOnCheckPasswordResult(false);
            } finally {
                mLogin.post(new Runnable() {

                    public void run() {
                        getProgressDialog().hide();
                    }
                });
            }
        }
    }, null, /* handler */
    new UserHandle(ActivityManager.getCurrentUser()));
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) UserHandle(android.os.UserHandle) AuthenticatorException(android.accounts.AuthenticatorException) IOException(java.io.IOException)

Aggregations

AuthenticatorException (android.accounts.AuthenticatorException)28 OperationCanceledException (android.accounts.OperationCanceledException)22 IOException (java.io.IOException)22 Bundle (android.os.Bundle)15 Account (android.accounts.Account)13 Intent (android.content.Intent)7 AccountManager (android.accounts.AccountManager)6 Context (android.content.Context)5 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)5 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)4 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)4 Test (org.junit.Test)4 Gson (com.google.gson.Gson)3 User (com.nextcloud.client.account.User)3 AccountUtils (com.owncloud.android.authentication.AccountUtils)3 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)3 PushConfigurationState (com.owncloud.android.datamodel.PushConfigurationState)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 UserHandle (android.os.UserHandle)2 GoogleHeaders (com.google.api.client.googleapis.GoogleHeaders)2