X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/5781090e2be3fddcb47d2d7e504e859321eb2ede..bcc972d63d3ed1d76b51a8a03a27e809983dc756:/src/com/owncloud/android/authentication/AccountUtils.java?ds=inline diff --git a/src/com/owncloud/android/authentication/AccountUtils.java b/src/com/owncloud/android/authentication/AccountUtils.java index 591da010..33c7e6a9 100644 --- a/src/com/owncloud/android/authentication/AccountUtils.java +++ b/src/com/owncloud/android/authentication/AccountUtils.java @@ -18,11 +18,12 @@ package com.owncloud.android.authentication; -import com.owncloud.android.utils.OwnCloudVersion; +import com.owncloud.android.MainApp; +import com.owncloud.android.oc_framework.accounts.AccountTypeUtils; +import com.owncloud.android.oc_framework.utils.OwnCloudVersion; import android.accounts.Account; import android.accounts.AccountManager; -import android.accounts.AccountsException; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; @@ -32,6 +33,7 @@ public class AccountUtils { public static final String WEBDAV_PATH_2_0 = "/files/webdav.php"; public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; private static final String ODAV_PATH = "/remote.php/odav"; + private static final String SAML_SSO_PATH = "/remote.php/webdav"; public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php"; public static final String CARDDAV_PATH_4_0 = "/remote/carddav.php"; public static final String STATUS_PATH = "/status.php"; @@ -47,7 +49,7 @@ public class AccountUtils { */ public static Account getCurrentOwnCloudAccount(Context context) { Account[] ocAccounts = AccountManager.get(context).getAccountsByType( - AccountAuthenticator.ACCOUNT_TYPE); + MainApp.getAccountType()); Account defaultAccount = null; SharedPreferences appPreferences = PreferenceManager @@ -74,6 +76,20 @@ public class AccountUtils { } + public static boolean exists(Account account, Context context) { + Account[] ocAccounts = AccountManager.get(context).getAccountsByType( + MainApp.getAccountType()); + + if (account != null && account.name != null) { + for (Account ac : ocAccounts) { + if (ac.name.equals(account.name)) { + return true; + } + } + } + return false; + } + /** * Checks, whether or not there are any ownCloud accounts setup. @@ -83,7 +99,7 @@ public class AccountUtils { public static boolean accountsAreSetup(Context context) { AccountManager accMan = AccountManager.get(context); Account[] accounts = accMan - .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE); + .getAccountsByType(MainApp.getAccountType()); return accounts.length > 0; } @@ -92,7 +108,7 @@ public class AccountUtils { boolean result = false; if (accountName != null) { Account[] ocAccounts = AccountManager.get(context).getAccountsByType( - AccountAuthenticator.ACCOUNT_TYPE); + MainApp.getAccountType()); boolean found = false; for (Account account : ocAccounts) { found = (account.name.equals(accountName)); @@ -111,15 +127,21 @@ public class AccountUtils { } /** + * Returns the proper URL path to access the WebDAV interface of an ownCloud server, + * according to its version and the authorization method used. * - * @param version version of owncloud - * @return webdav path for given OC version, null if OC version unknown + * @param version Version of ownCloud server. + * @param authTokenType Authorization token type, matching some of the AUTH_TOKEN_TYPE_* constants in {@link AccountAuthenticator}. + * @return WebDAV path for given OC version and authorization method, null if OC version is unknown. */ - public static String getWebdavPath(OwnCloudVersion version, boolean supportsOAuth) { + public static String getWebdavPath(OwnCloudVersion version, String authTokenType) { if (version != null) { - if (supportsOAuth) { + if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(authTokenType)) { return ODAV_PATH; } + if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(authTokenType)) { + return SAML_SSO_PATH; + } if (version.compareTo(OwnCloudVersion.owncloud_v4) >= 0) return WEBDAV_PATH_4_0; if (version.compareTo(OwnCloudVersion.owncloud_v3) >= 0 @@ -131,43 +153,4 @@ public class AccountUtils { return null; } - /** - * Constructs full url to host and webdav resource basing on host version - * @param context - * @param account - * @return url or null on failure - * @throws AccountNotFoundException When 'account' is unknown for the AccountManager - */ - public static String constructFullURLForAccount(Context context, Account account) throws AccountNotFoundException { - AccountManager ama = AccountManager.get(context); - String baseurl = ama.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL); - String strver = ama.getUserData(account, AccountAuthenticator.KEY_OC_VERSION); - boolean supportsOAuth = (ama.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null); - OwnCloudVersion ver = new OwnCloudVersion(strver); - String webdavpath = getWebdavPath(ver, supportsOAuth); - - if (baseurl == null || webdavpath == null) - throw new AccountNotFoundException(account, "Account not found", null); - - return baseurl + webdavpath; - } - - - public static class AccountNotFoundException extends AccountsException { - - /** Generated - should be refreshed every time the class changes!! */ - private static final long serialVersionUID = -9013287181793186830L; - - private Account mFailedAccount; - - public AccountNotFoundException(Account failedAccount, String message, Throwable cause) { - super(message, cause); - mFailedAccount = failedAccount; - } - - public Account getFailedAccount() { - return mFailedAccount; - } - } - }