Search in sources :

Example 6 with OwnCloudCredentials

use of com.owncloud.android.lib.common.OwnCloudCredentials in project android by owncloud.

the class AuthenticatorActivity method checkBasicAuthorization.

/**
     * Tests the credentials entered by the user performing a check of existence on 
     * the root folder of the ownCloud server.
     */
private void checkBasicAuthorization() {
    /// get basic credentials entered by user
    String username = mUsernameInput.getText().toString().trim();
    String password = mPasswordInput.getText().toString();
    /// be gentle with the user
    LoadingDialog dialog = LoadingDialog.newInstance(R.string.auth_trying_to_login, true);
    dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);
    /// validate credentials accessing the root folder
    OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password, (mServerInfo != null && mServerInfo.mVersion != null && mServerInfo.mVersion.isPreemptiveAuthenticationPreferred()));
    accessRootFolder(credentials);
}
Also used : LoadingDialog(com.owncloud.android.ui.dialog.LoadingDialog) OwnCloudCredentials(com.owncloud.android.lib.common.OwnCloudCredentials)

Example 7 with OwnCloudCredentials

use of com.owncloud.android.lib.common.OwnCloudCredentials in project android by owncloud.

the class AuthenticatorActivity method onGetOAuthAccessTokenFinish.

/**
     * Processes the result of the request for and access token send 
     * to an OAuth authorization server.
     * 
     * @param result        Result of the operation.
     */
private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) {
    mWaitingForOpId = Long.MAX_VALUE;
    dismissDialog(WAIT_DIALOG_TAG);
    if (result.isSuccess()) {
        /// be gentle with the user
        LoadingDialog dialog = LoadingDialog.newInstance(R.string.auth_trying_to_login, true);
        dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);
        /// time to test the retrieved access token on the ownCloud server
        @SuppressWarnings("unchecked") Map<String, String> tokens = (Map<String, String>) (result.getData().get(0));
        mAuthToken = tokens.get(OAuth2Constants.KEY_ACCESS_TOKEN);
        Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);
        /// validate token accessing to root folder / getting session
        OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBearerCredentials(mAuthToken);
        accessRootFolder(credentials);
    } else {
        updateAuthStatusIconAndText(result);
        showAuthStatus();
        Log_OC.d(TAG, "Access failed: " + result.getLogMessage());
    }
}
Also used : LoadingDialog(com.owncloud.android.ui.dialog.LoadingDialog) Map(java.util.Map) OwnCloudCredentials(com.owncloud.android.lib.common.OwnCloudCredentials)

Example 8 with OwnCloudCredentials

use of com.owncloud.android.lib.common.OwnCloudCredentials in project android by owncloud.

the class FileActivity method requestCredentialsUpdate.

/**
     * Invalidates the credentials stored for the given OC account and requests new credentials to the user,
     * navigating to {@link AuthenticatorActivity}
     *
     * @param context   Android Context needed to access the {@link AccountManager}. Received as a parameter
     *                  to make the method accessible to {@link android.content.BroadcastReceiver}s.
     * @param account   Stored OC account to request credentials update for. If null, current account will
     *                  be used.
     */
protected void requestCredentialsUpdate(Context context, Account account) {
    try {
        /// step 1 - invalidate credentials of current account
        if (account == null) {
            account = getAccount();
        }
        OwnCloudClient client;
        OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
        client = (OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(ocAccount));
        if (client != null) {
            OwnCloudCredentials cred = client.getCredentials();
            if (cred != null) {
                AccountManager am = AccountManager.get(context);
                if (cred.authTokenExpires()) {
                    am.invalidateAuthToken(account.type, cred.getAuthToken());
                } else {
                    am.clearPassword(account);
                }
            }
        }
        /// step 2 - request credentials to user
        Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
        updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, account);
        updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
        updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        startActivityForResult(updateAccountCredentials, REQUEST_CODE__UPDATE_CREDENTIALS);
    } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
        showSnackMessage(getString(R.string.auth_account_does_not_exist));
    }
}
Also used : AccountUtils(com.owncloud.android.authentication.AccountUtils) AccountManager(android.accounts.AccountManager) Intent(android.content.Intent) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) OwnCloudCredentials(com.owncloud.android.lib.common.OwnCloudCredentials)

Example 9 with OwnCloudCredentials

use of com.owncloud.android.lib.common.OwnCloudCredentials in project android by nextcloud.

the class FileActivity method requestCredentialsUpdate.

/**
 * Invalidates the credentials stored for the given OC account and requests new credentials to the user,
 * navigating to {@link AuthenticatorActivity}
 *
 * @param context   Android Context needed to access the {@link AccountManager}. Received as a parameter
 *                  to make the method accessible to {@link android.content.BroadcastReceiver}s.
 * @param account   Stored OC account to request credentials update for. If null, current account will
 *                  be used.
 */
protected void requestCredentialsUpdate(Context context, Account account) {
    try {
        // / step 1 - invalidate credentials of current account
        if (account == null) {
            account = getAccount();
        }
        OwnCloudClient client;
        OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
        client = (OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(ocAccount));
        if (client != null) {
            OwnCloudCredentials cred = client.getCredentials();
            if (cred != null) {
                AccountManager am = AccountManager.get(context);
                if (cred.authTokenExpires()) {
                    am.invalidateAuthToken(account.type, cred.getAuthToken());
                } else {
                    am.clearPassword(account);
                }
            }
        }
        // / step 2 - request credentials to user
        Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
        updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, account);
        updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
        updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        startActivityForResult(updateAccountCredentials, REQUEST_CODE__UPDATE_CREDENTIALS);
    } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
        DisplayUtils.showSnackMessage(this, R.string.auth_account_does_not_exist);
    }
}
Also used : AccountManager(android.accounts.AccountManager) Intent(android.content.Intent) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) OwnCloudCredentials(com.owncloud.android.lib.common.OwnCloudCredentials)

Example 10 with OwnCloudCredentials

use of com.owncloud.android.lib.common.OwnCloudCredentials in project android by nextcloud.

the class AuthenticatorActivity method checkBasicAuthorization.

/**
 * Tests the credentials entered by the user performing a check of existence on
 * the root folder of the ownCloud server.
 */
private void checkBasicAuthorization(@Nullable String webViewUsername, @Nullable String webViewPassword) {
    // / get basic credentials entered by user
    String username;
    String password;
    if (!webViewLoginMethod) {
        username = mUsernameInput.getText().toString().trim();
        password = mPasswordInput.getText().toString();
    } else {
        username = webViewUsername;
        password = webViewPassword;
    }
    // / be gentle with the user
    IndeterminateProgressDialog dialog = IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);
    dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);
    // / validate credentials accessing the root folder
    OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);
    accessRootFolder(credentials);
}
Also used : IndeterminateProgressDialog(com.owncloud.android.ui.dialog.IndeterminateProgressDialog) OwnCloudCredentials(com.owncloud.android.lib.common.OwnCloudCredentials)

Aggregations

OwnCloudCredentials (com.owncloud.android.lib.common.OwnCloudCredentials)10 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)4 AccountManager (android.accounts.AccountManager)2 Intent (android.content.Intent)2 Uri (android.net.Uri)2 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)2 RedirectionPath (com.owncloud.android.lib.common.network.RedirectionPath)2 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)2 ExistenceCheckRemoteOperation (com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation)2 GetRemoteUserInfoOperation (com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation)2 IndeterminateProgressDialog (com.owncloud.android.ui.dialog.IndeterminateProgressDialog)2 LoadingDialog (com.owncloud.android.ui.dialog.LoadingDialog)2 Map (java.util.Map)2 AccountUtils (com.owncloud.android.authentication.AccountUtils)1 OwnCloudVersion (com.owncloud.android.lib.resources.status.OwnCloudVersion)1 HashMap (java.util.HashMap)1