List of usage examples for android.accounts AccountManager KEY_USERDATA
String KEY_USERDATA
To view the source code for android.accounts AccountManager KEY_USERDATA.
Click Source Link
From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java
@Override public String promote(final Activity activity, String inAuthority, final String token) { final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority; final AccountManager am = AccountManager.get(activity); // Bundle options = new Bundle(); // if (token != null) { // options.putString(Constants.PROMOTION_TOKEN, token); // }/* www. jav a2s. c o m*/ final Account a = new Account(Constants.getAccountName(activity), Constants.getAccountType(activity)); final String userDataString = am.getUserData(a, AccountManager.KEY_USERDATA); invalidateToken(activity, authority); am.getAuthToken(new Account(Constants.getAccountName(activity), Constants.getAccountType(activity)), authority, null, null, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> result) { Bundle bundle = null; try { bundle = result.getResult(); Intent launch = (Intent) bundle.get(AccountManager.KEY_INTENT); if (launch != null) { launch.putExtra(Constants.KEY_AUTHORITY, authority); launch.putExtra(Constants.PROMOTION_TOKEN, token); launch.putExtra(Constants.OLD_DATA, userDataString); activity.startActivityForResult(launch, SC_AUTH_ACTIVITY_REQUEST_CODE); } else if (bundle.getString(AccountManager.KEY_AUTHTOKEN) != null) { // am.setAuthToken(a, authority, bundle.getString(AccountManager.KEY_AUTHTOKEN)); // am.addAccountExplicitly(a, null, null); // no token acquired } else { storeAnonymousToken(token, authority, am, a); } } catch (Exception e) { // revert the invalidated token storeAnonymousToken(token, authority, am, a); return; } } }, null); return null; }
From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java
@Override public UserData readUserData(Context ctx, String inAuthority) { AccountManager am = AccountManager.get(ctx); Account account = new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx)); // final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority; // String token = am.peekAuthToken(account, authority); // if (token == null) return null; String userDataString = am.getUserData(account, AccountManager.KEY_USERDATA); if (userDataString == null) return null; try {//from ww w . ja v a 2s . com return UserData.valueOf(new JSONObject(userDataString)); } catch (JSONException e) { return null; } }
From source file:org.xwiki.android.authenticator.auth.AuthenticatorActivity.java
public void finishLogin(Intent intent) { Log.d(TAG, "> finishLogin"); //before add new account, clear old account data. clearOldAccount();//from www. j a va 2 s . c o m //get values String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String accountPassword = intent.getStringExtra(PARAM_USER_PASS); String accountServer = intent.getStringExtra(PARAM_USER_SERVER); // Creating the account on the device and setting the auth token we got // (Not setting the auth token will cause another call to the server to authenticate the user) Log.d(TAG, "finishLogin > addAccountExplicitly" + " " + intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE)); final Account account = new Account(accountName, Constants.ACCOUNT_TYPE); mAccountManager.addAccountExplicitly(account, accountPassword, null); mAccountManager.setUserData(account, AccountManager.KEY_USERDATA, accountName); mAccountManager.setUserData(account, AccountManager.KEY_PASSWORD, accountPassword); mAccountManager.setUserData(account, AuthenticatorActivity.PARAM_USER_SERVER, accountServer); //grant permission if adding user from the third-party app (UID,PackageName); String packaName = getIntent().getStringExtra(PARAM_APP_PACKAGENAME); int uid = getIntent().getIntExtra(PARAM_APP_UID, 0); Log.d(TAG, packaName + ", " + getPackageName()); //only if adding account from the third-party apps exclude android.uid.system, this will execute to grant permission and set token if (!packaName.contains("android.uid.system")) { AppContext.addAuthorizedApp(uid, packaName); String authToken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN); if (!TextUtils.isEmpty(authToken)) { String authTokenType = getIntent().getStringExtra(KEY_AUTH_TOKEN_TYPE); mAccountManager.setAuthToken(account, authTokenType, authToken); } } //return value to AccountManager Intent intentReturn = new Intent(); intentReturn.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); intentReturn.putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName); setAccountAuthenticatorResult(intentReturn.getExtras()); setResult(RESULT_OK, intentReturn); Log.d(TAG, ">" + "finish return"); // in SettingSyncViewFlipper this activity finish; }
From source file:com.owncloud.android.authentication.AuthenticatorActivity.java
/** * Creates a new account through the Account Authenticator that started this * activity.//w w w . j a v a 2s . c om * * This makes the account permanent. * * TODO Decide how to name the OAuth accounts */ private boolean createAccount() { // / create and save new ownCloud account boolean isOAuth = AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mAuthTokenType); boolean isSaml = AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mAuthTokenType); Uri uri = Uri.parse(mHostBaseUrl); String username = mUsernameInput.getText().toString().trim(); username = username + "@" + location; if (isSaml) { username = getUserNameForSamlSso(); } else if (isOAuth) { username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong(); } String accountName = username + "@" + uri.getHost(); if (uri.getPort() >= 0) { accountName += ":" + uri.getPort(); } mAccount = new Account(accountName, AccountAuthenticator.ACCOUNT_TYPE); if (AccountUtils.exists(mAccount, getApplicationContext())) { // fail - not a new account, but an existing one; disallow RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW); updateAuthStatusIconAndText(result); showAuthStatus(); Log_OC.d(TAG, result.getLogMessage()); return false; } else { if (isOAuth || isSaml) { mAccountMgr.addAccountExplicitly(mAccount, "", null); // with // external // authorizations, // the // password // is // never // input // in the // app } else { mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null); } // / add the new account as default in preferences, if there is none // already Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this); if (defaultAccount == null) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); editor.putString("select_oc_account", accountName); editor.commit(); } // / prepare result to return to the Authenticator // TODO check again what the Authenticator makes with it; probably // has the same effect as addAccountExplicitly, but it's not well // done final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountAuthenticator.ACCOUNT_TYPE); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mAccount.name); /* * if (!isOAuth) intent.putExtra(AccountManager.KEY_AUTHTOKEN, * AccountAuthenticator.ACCOUNT_TYPE); */ intent.putExtra(AccountManager.KEY_USERDATA, username); if (isOAuth || isSaml) { mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken); } // / add user data to the new account; TODO probably can be done in // the last parameter addAccountExplicitly, or in KEY_USERDATA mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION, mDiscoveredVersion.toString()); mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL, mHostBaseUrl); if (isSaml) { mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); } else if (isOAuth) { mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_SUPPORTS_OAUTH2, "TRUE"); } setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); // / immediately request for the synchronization of the new account Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(mAccount, AccountAuthenticator.AUTHORITY, bundle); syncAccount(); // Bundle bundle = new Bundle(); // bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); // ContentResolver.requestSync(mAccount, // AccountAuthenticator.AUTHORITY, bundle); return true; } }
From source file:com.digitalarx.android.authentication.AuthenticatorActivity.java
/** * Creates a new account through the Account Authenticator that started this activity. * // w w w . java2 s . c o m * This makes the account permanent. * * TODO Decide how to name the OAuth accounts */ private boolean createAccount() { /// create and save new ownCloud account boolean isOAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()) .equals(mAuthTokenType); boolean isSaml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()) .equals(mAuthTokenType); Uri uri = Uri.parse(mServerInfo.mBaseUrl); String username = mUsernameInput.getText().toString().trim(); if (isOAuth) { username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong(); } String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.buildAccountName(uri, username); Account newAccount = new Account(accountName, MainApp.getAccountType()); if (AccountUtils.exists(newAccount, getApplicationContext())) { // fail - not a new account, but an existing one; disallow RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW); updateAuthStatusIconAndText(result); showAuthStatus(); Log_OC.d(TAG, result.getLogMessage()); return false; } else { mAccount = newAccount; if (isOAuth || isSaml) { mAccountMgr.addAccountExplicitly(mAccount, "", null); // with external authorizations, the password is never input in the app } else { mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null); } /// add the new account as default in preferences, if there is none already Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this); if (defaultAccount == null) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); editor.putString("select_oc_account", accountName); editor.commit(); } /// prepare result to return to the Authenticator // TODO check again what the Authenticator makes with it; probably has the same effect as addAccountExplicitly, but it's not well done final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType()); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mAccount.name); /*if (!isOAuth) intent.putExtra(AccountManager.KEY_AUTHTOKEN, MainApp.getAccountType()); */ intent.putExtra(AccountManager.KEY_USERDATA, username); if (isOAuth || isSaml) { mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken); } /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion()); mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl); if (isSaml) { mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); } else if (isOAuth) { mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE"); } setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); return true; } }
From source file:com.synox.android.authentication.AuthenticatorActivity.java
/** * Creates a new account through the Account Authenticator that started this activity. * //from ww w .j a v a 2s . c o m * This makes the account permanent. * * TODO Decide how to name the OAuth accounts */ private boolean createAccount(RemoteOperationResult authResult) { /// create and save new ownCloud account boolean isOAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()) .equals(mAuthTokenType); boolean isSaml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()) .equals(mAuthTokenType); String lastPermanentLocation = authResult.getLastPermanentLocation(); if (lastPermanentLocation != null) { mServerInfo.mBaseUrl = AccountUtils.trimWebdavSuffix(lastPermanentLocation); } Uri uri = Uri.parse(mServerInfo.mBaseUrl); String username = mUsernameInput.getText().toString().trim(); if (isOAuth) { username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong(); } String accountName = com.synox.android.lib.common.accounts.AccountUtils.buildAccountName(uri, username); Account newAccount = new Account(accountName, MainApp.getAccountType()); if (AccountUtils.exists(newAccount, getApplicationContext())) { // fail - not a new account, but an existing one; disallow RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW); updateAuthStatusIconAndText(result); showAuthStatus(); Log_OC.d(TAG, result.getLogMessage()); return false; } else { mAccount = newAccount; if (isOAuth || isSaml) { // with external authorizations, the password is never input in the app mAccountMgr.addAccountExplicitly(mAccount, "", null); } else { mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null); } // include account version with the new account mAccountMgr.setUserData(mAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(AccountUtils.ACCOUNT_VERSION)); /// add the new account as default in preferences, if there is none already Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this); if (defaultAccount == null) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); editor.putString("select_oc_account", accountName); editor.commit(); } /// prepare result to return to the Authenticator // TODO check again what the Authenticator makes with it; probably has the same // effect as addAccountExplicitly, but it's not well done final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType()); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mAccount.name); intent.putExtra(AccountManager.KEY_USERDATA, username); if (isOAuth || isSaml) { mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken); } /// add user data to the new account; TODO probably can be done in the last parameter // addAccountExplicitly, or in KEY_USERDATA mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion()); mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl); if (isSaml) { mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); } else if (isOAuth) { mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE"); } setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); return true; } }
From source file:com.cerema.cloud2.authentication.AuthenticatorActivity.java
/** * Creates a new account through the Account Authenticator that started this activity. * /* w w w . j a va2 s.com*/ * This makes the account permanent. * * TODO Decide how to name the OAuth accounts */ private boolean createAccount(RemoteOperationResult authResult) { /// create and save new ownCloud account boolean isOAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()) .equals(mAuthTokenType); boolean isSaml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()) .equals(mAuthTokenType); String lastPermanentLocation = authResult.getLastPermanentLocation(); if (lastPermanentLocation != null) { mServerInfo.mBaseUrl = AccountUtils.trimWebdavSuffix(lastPermanentLocation); } Uri uri = Uri.parse(mServerInfo.mBaseUrl); String username = mUsernameInput.getText().toString().trim(); if (isOAuth) { username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong(); } String accountName = com.cerema.cloud2.lib.common.accounts.AccountUtils.buildAccountName(uri, username); Account newAccount = new Account(accountName, MainApp.getAccountType()); if (AccountUtils.exists(newAccount, getApplicationContext())) { // fail - not a new account, but an existing one; disallow RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW); updateAuthStatusIconAndText(result); showAuthStatus(); Log_OC.d(TAG, result.getLogMessage()); return false; } else { mAccount = newAccount; if (isOAuth || isSaml) { // with external authorizations, the password is never input in the app mAccountMgr.addAccountExplicitly(mAccount, "", null); } else { mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null); } // include account version with the new account mAccountMgr.setUserData(mAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(AccountUtils.ACCOUNT_VERSION)); /// add the new account as default in preferences, if there is none already Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this); if (defaultAccount == null) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); editor.putString("select_oc_account", accountName); editor.commit(); } /// prepare result to return to the Authenticator // TODO check again what the Authenticator makes with it; probably has the same // effect as addAccountExplicitly, but it's not well done final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType()); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mAccount.name); intent.putExtra(AccountManager.KEY_USERDATA, username); if (isOAuth || isSaml) { mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken); } /// add user data to the new account; TODO probably can be done in the last parameter // addAccountExplicitly, or in KEY_USERDATA mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion()); mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl); if (isSaml) { mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); } else if (isOAuth) { mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE"); } setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); return true; } }