List of usage examples for android.accounts AccountManager getPassword
public String getPassword(final Account account)
From source file:com.hyrt.cnp.account.AccountAuthenticator.java
@Override public Bundle getAuthToken(final AccountAuthenticatorResponse response, final Account account, final String authTokenType, final Bundle options) throws NetworkErrorException { Log.d(TAG, "Retrieving OAuth2 token"); final Bundle bundle = new Bundle(); if (!ACCOUNT_TYPE.equals(authTokenType)) return bundle; AccountManager am = AccountManager.get(context); String password = am.getPassword(account); if (TextUtils.isEmpty(password)) { bundle.putParcelable(KEY_INTENT, createLoginIntent(response)); return bundle; }//from ww w.jav a2 s . com MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); params.set("username", account.name); params.set("password", password); User.UserModel userModel = null; try { userModel = getCustomRestTemplate().postForObject("http://api.chinaxueqian.com/account/login", params, User.UserModel.class); } catch (Exception e) { e.printStackTrace(); } if (userModel == null || userModel.getData() == null || TextUtils.isEmpty(userModel.getData().getToken())) bundle.putParcelable(KEY_INTENT, createLoginIntent(response)); else { bundle.putString(KEY_ACCOUNT_NAME, account.name); bundle.putString(KEY_ACCOUNT_TYPE, ACCOUNT_TYPE); bundle.putString(KEY_AUTHTOKEN, userModel.getData().getToken() + "&uuid=" + userModel.getData().getUuid() + "&sid=" + userModel.getData().getNursery_id()); am.clearPassword(account); } return bundle; }
From source file:com.glandorf1.joe.wsprnetviewer.app.sync.WsprNetViewerSyncAdapter.java
/** * Create a new dummy account for the sync adapter * * @param context The application context *//* w ww. jav a 2 s .c o m*/ public static Account getSyncAccount(Context context) { // Get an instance of the Android account manager AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account // app_name = WsprNetViewer // sync_account_type = wsprnetviewer.joe.glandorf1.com Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist if (null == accountManager.getPassword(newAccount)) { // Add the account and account type, no password or user data // If successful, return the Account object, otherwise report an error. boolean ret = accountManager.addAccountExplicitly(newAccount, "", null); if (!ret) { return null; } // If you don't set android:syncable="true" in // in your <provider> element in the manifest, // then call context.setIsSyncable(account, AUTHORITY, 1) // here. onAccountCreated(newAccount, context); } return newAccount; }
From source file:com.clearcenter.mobile_demo.mdAuthenticator.java
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) throws NetworkErrorException { Log.v(TAG, "getAuthToken()"); // If the caller requested an authToken type we don't support, then // return an error if (!authTokenType.equals(mdConstants.AUTHTOKEN_TYPE)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; }/*from w w w. j a v a2s .com*/ // Extract the username and password from the Account Manager, and ask // the server for an appropriate AuthToken. final AccountManager am = AccountManager.get(ctx); final String password = am.getPassword(account); final String hostname = am.getUserData(account, "hostname"); final String username = am.getUserData(account, "username"); if (password != null) { try { mdSSLUtil.DisableSecurity(); final String authToken = mdRest.Login(hostname, username, null, password); if (!TextUtils.isEmpty(authToken)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, mdConstants.ACCOUNT_TYPE); result.putString(AccountManager.KEY_AUTHTOKEN, authToken); return result; } } catch (JSONException e) { Log.e(TAG, "JSONException", e); } catch (GeneralSecurityException e) { Log.e(TAG, "GeneralSecurityException", e); } } Log.v(TAG, "Asking for password again..."); // If we get here, then we couldn't access the user's password - so we // need to re-prompt them for their credentials. We do that by creating // an intent to display our mdAuthenticatorActivity panel. final Intent intent = new Intent(ctx, mdAuthenticatorActivity.class); intent.putExtra(mdAuthenticatorActivity.PARAM_NICKNAME, account.name); intent.putExtra(mdAuthenticatorActivity.PARAM_USERNAME, username); intent.putExtra(mdAuthenticatorActivity.PARAM_HOSTNAME, hostname); intent.putExtra(mdAuthenticatorActivity.PARAM_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(mdAuthenticatorActivity.PARAM_CONFIRM_CREDENTIALS, true); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:com.manning.androidhacks.hack023.authenticator.Authenticator.java
@Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { if (!authTokenType.equals(AuthenticatorActivity.PARAM_AUTHTOKEN_TYPE)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; }//from w w w. ja v a2s .com final AccountManager am = AccountManager.get(mContext); final String password = am.getPassword(account); if (password != null) { boolean verified = false; String loginResponse = null; try { loginResponse = LoginServiceImpl.sendCredentials(account.name, password); verified = LoginServiceImpl.hasLoggedIn(loginResponse); } catch (AndroidHacksException e) { verified = false; } if (verified) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, AuthenticatorActivity.PARAM_ACCOUNT_TYPE); return result; } } // Password is missing or incorrect final Intent intent = new Intent(mContext, AuthenticatorActivity.class); intent.putExtra(AuthenticatorActivity.PARAM_USER, account.name); intent.putExtra(AuthenticatorActivity.PARAM_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java
/** * Helper method to get the fake account to be used with SyncAdapter, or make a new one if the * fake account doesn't exist yet.//from w ww.j a va 2 s.com * * @param context * The context used to access the account service * @return a fake account. */ public static Account getSyncAccount(Context context) { // Get an instance of the Android account manager AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist if (null == accountManager.getPassword(newAccount)) { // Add the account and account type, no password or user data // If successful, return the Account object, otherwise report an error. if (!accountManager.addAccountExplicitly(newAccount, "", null)) { return null; } // If you don't set android:syncable="true" in your <provider> element in the manifest, // then call context.setIsSyncable(account, AUTHORITY, 1) here. onAccountCreated(newAccount, context); } return newAccount; }
From source file:edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticator.java
/** * {@inheritDoc}/*from ww w. j a v a2 s . c om*/ */ @Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) { if (!authTokenType.equals(getAuthTokenType())) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; } final AccountManager am = AccountManager.get(mContext); final String password = am.getPassword(account); if (password != null) { final Bundle accountData = onlineConfirmPassword(account, password); if (accountData != null) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, getAccountType()); result.putString(AccountManager.KEY_AUTHTOKEN, password); return result; } } // the password was missing or incorrect, return an Intent to an // Activity that will prompt the user for the password. final Intent intent = getAuthenticator(mContext); intent.putExtra(AbsLocastAuthenticatorActivity.EXTRA_USERNAME, account.name); intent.putExtra(AbsLocastAuthenticatorActivity.EXTRA_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:edu.mit.mobile.android.locast.accounts.Authenticator.java
/** * {@inheritDoc}/*from ww w .j av a 2 s . co m*/ */ @Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) { if (!authTokenType.equals(AuthenticationService.AUTHTOKEN_TYPE)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; } final AccountManager am = AccountManager.get(mContext); final String password = am.getPassword(account); if (password != null) { final Bundle accountData = onlineConfirmPassword(account, password); if (accountData != null) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, AuthenticationService.ACCOUNT_TYPE); result.putString(AccountManager.KEY_AUTHTOKEN, password); return result; } } // the password was missing or incorrect, return an Intent to an // Activity that will prompt the user for the password. final Intent intent = new Intent(mContext, AuthenticatorActivity.class); intent.putExtra(AuthenticatorActivity.EXTRA_USERNAME, account.name); intent.putExtra(AuthenticatorActivity.EXTRA_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:com.nextgis.maplib.map.LayerFactory.java
public Connection getConnectionFromAccount(Context context, String accountName) { final AccountManager accountManager = AccountManager.get(context); for (Account account : accountManager.getAccountsByType(NGW_ACCOUNT_TYPE)) { if (account.name.equals(accountName)) { String url = accountManager.getUserData(account, "url"); String password = accountManager.getPassword(account); String login = accountManager.getUserData(account, "login"); return new Connection(accountName, login, password, url); }/*from w w w .j ava 2s. co m*/ } return null; }