List of usage examples for android.accounts AccountManager getUserData
public String getUserData(final Account account, final String key)
From source file:com.owncloud.android.network.OwnCloudClientUtils.java
/** * Creates a WebdavClient setup for an ownCloud account * //from w w w .j a v a2 s . c o m * Do not call this method from the main thread. * * @param account The ownCloud account * @param appContext Android application context * @return A WebdavClient object ready to be used * @throws AuthenticatorException If the authenticator failed to get the authorization token for the account. * @throws OperationCanceledException If the authenticator operation was cancelled while getting the authorization token for the account. * @throws IOException If there was some I/O error while getting the authorization token for the account. * @throws AccountNotFoundException If 'account' is unknown for the AccountManager */ public static WebdavClient createOwnCloudClient(Account account, Context appContext) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException { //Log_OC.d(TAG, "Creating WebdavClient associated to " + account.name); Uri uri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account)); AccountManager am = AccountManager.get(appContext); boolean isOauth2 = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null; // TODO avoid calling to getUserData here boolean isSamlSso = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO) != null; WebdavClient client = createOwnCloudClient(uri, appContext, !isSamlSso); if (isOauth2) { String accessToken = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN, false); client.setBearerCredentials(accessToken); // TODO not assume that the access token is a bearer token } else if (isSamlSso) { // TODO avoid a call to getUserData here String accessToken = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE, false); client.setSsoSessionCookie(accessToken); } else { String username = account.name.substring(0, account.name.lastIndexOf('@')); //String password = am.getPassword(account); String password = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD, false); client.setBasicCredentials(username, password); } return client; }
From source file:eu.e43.impeller.Utils.java
public static Uri getHostUri(Context ctx, Account user, String... components) { AccountManager am = AccountManager.get(ctx); String host = am.getUserData(user, "host"); Uri.Builder b = new Uri.Builder(); b.scheme("https"); b.authority(host);//from ww w.ja va 2 s . co m for (String s : components) { b.appendPath(s); } return b.build(); }
From source file:eu.e43.impeller.Utils.java
public static Uri getUserUri(Context ctx, Account user, String... components) { AccountManager am = AccountManager.get(ctx); String username = am.getUserData(user, "username"); ArrayList<String> parts = new ArrayList<String>(); parts.add("api"); parts.add("user"); parts.add(username);/*from w w w . j a va 2 s . c o m*/ for (String s : components) parts.add(s); return getHostUri(ctx, user, parts.toArray(components)); }
From source file:com.owncloud.android.network.OwnCloudClientUtils.java
public static WebdavClient createOwnCloudClient(Account account, Context appContext, Activity currentActivity) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException { Uri uri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account)); AccountManager am = AccountManager.get(appContext); boolean isOauth2 = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null; // TODO avoid calling to getUserData here boolean isSamlSso = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO) != null; WebdavClient client = createOwnCloudClient(uri, appContext, !isSamlSso); if (isOauth2) { // TODO avoid a call to getUserData here AccountManagerFuture<Bundle> future = am.getAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN, null, currentActivity, null, null); Bundle result = future.getResult(); String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN); if (accessToken == null) throw new AuthenticatorException("WTF!"); client.setBearerCredentials(accessToken); // TODO not assume that the access token is a bearer token } else if (isSamlSso) { // TODO avoid a call to getUserData here AccountManagerFuture<Bundle> future = am.getAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE, null, currentActivity, null, null);/*from w w w .j a va 2 s . c om*/ Bundle result = future.getResult(); String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN); if (accessToken == null) throw new AuthenticatorException("WTF!"); client.setSsoSessionCookie(accessToken); } else { String username = account.name.substring(0, account.name.lastIndexOf('@')); //String password = am.getPassword(account); //String password = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD, false); AccountManagerFuture<Bundle> future = am.getAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD, null, currentActivity, null, null); Bundle result = future.getResult(); String password = result.getString(AccountManager.KEY_AUTHTOKEN); client.setBasicCredentials(username, password); } return client; }
From source file:ir.keloud.android.lib.common.accounts.AccountUtils.java
/** * Constructs full url to host and webdav resource basing on host version * /*from w ww .j av a2 s . c o m*/ * @deprecated To be removed in release 1.0. * * @param context * @param account * @return url or null on failure * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ @Deprecated public static String constructFullURLForAccount(Context context, Account account) throws AccountNotFoundException { AccountManager ama = AccountManager.get(context); String baseurl = ama.getUserData(account, Constants.KEY_OC_BASE_URL); String version = ama.getUserData(account, Constants.KEY_OC_VERSION); boolean supportsOAuth = (ama.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2) != null); boolean supportsSamlSso = (ama.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null); KeloudVersion ver = new KeloudVersion(version); String webdavpath = getWebdavPath(ver, supportsOAuth, supportsSamlSso); if (baseurl == null || webdavpath == null) throw new AccountNotFoundException(account, "Account not found", null); return baseurl + webdavpath; }
From source file:ir.keloud.android.lib.common.accounts.AccountUtils.java
/** * /*from ww w.j av a2 s .c o m*/ * @return * @throws IOException * @throws AuthenticatorException * @throws OperationCanceledException */ public static KeloudCredentials getCredentialsForAccount(Context context, Account account) throws OperationCanceledException, AuthenticatorException, IOException { KeloudCredentials credentials = null; AccountManager am = AccountManager.get(context); boolean isOauth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null; boolean isSamlSso = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; if (isOauth2) { String accessToken = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false); credentials = KeloudCredentialsFactory.newBearerCredentials(accessToken); } else if (isSamlSso) { String accessToken = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), false); credentials = KeloudCredentialsFactory.newSamlSsoCredentials(accessToken); } else { String username = account.name.substring(0, account.name.lastIndexOf('@')); String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), false); credentials = KeloudCredentialsFactory.newBasicCredentials(username, password); } return credentials; }
From source file:com.owncloud.android.lib.common.accounts.AccountUtils.java
/** * //from w w w .ja va2 s.co m * @return * @throws IOException * @throws AuthenticatorException * @throws OperationCanceledException */ public static OwnCloudCredentials getCredentialsForAccount(Context context, Account account) throws OperationCanceledException, AuthenticatorException, IOException { OwnCloudCredentials credentials = null; AccountManager am = AccountManager.get(context); boolean isOauth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null; boolean isSamlSso = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; if (isOauth2) { String accessToken = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false); credentials = OwnCloudCredentialsFactory.newBearerCredentials(accessToken); } else if (isSamlSso) { String accessToken = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), false); credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(accessToken); } else { String username = account.name.substring(0, account.name.lastIndexOf('@')); String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), false); credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password); } return credentials; }
From source file:org.andstatus.app.account.AccountData.java
public static AccountData fromAndroidAccount(MyContext myContext, Account androidAccount) { if (androidAccount == null) { throw new IllegalArgumentException(TAG + " account is null"); }/*from w w w . jav a 2 s . c o m*/ android.accounts.AccountManager am = AccountManager.get(myContext.context()); AccountData accountData = fromJsonString(am.getUserData(androidAccount, KEY_ACCOUNT), true); accountData.setDataBoolean(MyAccount.KEY_IS_SYNCABLE, ContentResolver.getIsSyncable(androidAccount, MyProvider.AUTHORITY) != 0); accountData.setDataBoolean(MyAccount.KEY_SYNC_AUTOMATICALLY, ContentResolver.getSyncAutomatically(androidAccount, MyProvider.AUTHORITY)); accountData.setDataLong(MyPreferences.KEY_SYNC_FREQUENCY_SECONDS, getSyncFrequencySeconds(androidAccount)); return accountData; }
From source file:com.cerema.cloud2.lib.common.accounts.AccountUtils.java
/** * Constructs full url to host and webdav resource basing on host version * //from w ww. java 2 s .c om * @deprecated To be removed in release 1.0. * * @param context * @param account * @return url or null on failure * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ @Deprecated public static String constructFullURLForAccount(Context context, Account account) throws AccountNotFoundException { AccountManager ama = AccountManager.get(context); String baseurl = ama.getUserData(account, Constants.KEY_OC_BASE_URL); String version = ama.getUserData(account, Constants.KEY_OC_VERSION); boolean supportsOAuth = (ama.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2) != null); boolean supportsSamlSso = (ama.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null); OwnCloudVersion ver = new OwnCloudVersion(version); String webdavpath = getWebdavPath(ver, supportsOAuth, supportsSamlSso); if (baseurl == null || webdavpath == null) throw new AccountNotFoundException(account, "Account not found", null); return baseurl + webdavpath; }
From source file:com.cerema.cloud2.lib.common.accounts.AccountUtils.java
/** * Extracts url server from the account//from w w w .java 2 s .c o m * @param context * @param account * @return url server or null on failure * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ public static String getBaseUrlForAccount(Context context, Account account) throws AccountNotFoundException { AccountManager ama = AccountManager.get(context.getApplicationContext()); String baseurl = ama.getUserData(account, Constants.KEY_OC_BASE_URL); if (baseurl == null) throw new AccountNotFoundException(account, "Account not found", null); return baseurl; }