Loading src/com/owncloud/android/lib/common/DynamicSessionManager.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -5,6 +5,7 @@ import android.accounts.OperationCanceledException; import android.content.Context; import android.content.Context; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import java.io.IOException; import java.io.IOException; Loading Loading @@ -35,7 +36,16 @@ public class DynamicSessionManager implements OwnCloudClientManager { throws AccountUtils.AccountNotFoundException, throws AccountUtils.AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException { OperationCanceledException, AuthenticatorException, IOException { OwnCloudVersion ownCloudVersion = null; if (account.getSavedAccount() != null) { ownCloudVersion = AccountUtils.getServerVersionForAccount(account.getSavedAccount(), context); } if (ownCloudVersion != null && ownCloudVersion.isPreemptiveAuthenticationPreferred()) { return mSingleSessionManager.getClientFor(account, context, useNextcloudUserAgent); return mSingleSessionManager.getClientFor(account, context, useNextcloudUserAgent); } else { return mSimpleFactoryManager.getClientFor(account, context, useNextcloudUserAgent); } } } @Override @Override Loading src/com/owncloud/android/lib/common/OwnCloudClient.java +13 −7 Original line number Original line Diff line number Diff line Loading @@ -282,7 +282,9 @@ public class OwnCloudClient extends HttpClient { if (destination != null) { if (destination != null) { int suffixIndex = locationStr.lastIndexOf( int suffixIndex = locationStr.lastIndexOf( (mCredentials instanceof OwnCloudBearerCredentials) ? (mCredentials instanceof OwnCloudBearerCredentials) ? AccountUtils.ODAV_PATH : AccountUtils.WEBDAV_PATH_4_0); AccountUtils.ODAV_PATH : AccountUtils.WEBDAV_PATH_4_0 ); String redirectionBase = locationStr.substring(0, suffixIndex); String redirectionBase = locationStr.substring(0, suffixIndex); String destinationStr = destination.getValue(); String destinationStr = destination.getValue(); Loading Loading @@ -343,13 +345,17 @@ public class OwnCloudClient extends HttpClient { } } } } public Uri getNewWebdavUri() { public Uri getNewWebdavUri(boolean filesUri) { if (mCredentials instanceof OwnCloudBearerCredentials) { if (mCredentials instanceof OwnCloudBearerCredentials) { return Uri.parse(mBaseUri + AccountUtils.ODAV_PATH); return Uri.parse(mBaseUri + AccountUtils.ODAV_PATH); } else { if (filesUri) { return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_4_0); } else { } else { return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_9_0); return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_9_0); } } } } } /** /** * Sets the root URI to the ownCloud server. * Sets the root URI to the ownCloud server. Loading src/com/owncloud/android/lib/common/OwnCloudClientFactory.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -114,7 +114,7 @@ public class OwnCloudClientFactory { OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext); OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext); OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials( OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials( username, password); username, password, (version != null && version.isPreemptiveAuthenticationPreferred())); client.setCredentials(credentials); client.setCredentials(credentials); } } Loading Loading @@ -188,8 +188,9 @@ public class OwnCloudClientFactory { Bundle result = future.getResult(); Bundle result = future.getResult(); String password = result.getString(AccountManager.KEY_AUTHTOKEN); String password = result.getString(AccountManager.KEY_AUTHTOKEN); OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext); OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials( OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials( username, password); username, password, (version != null && version.isPreemptiveAuthenticationPreferred())); client.setCredentials(credentials); client.setCredentials(credentials); } } Loading src/com/owncloud/android/lib/common/OwnCloudCredentialsFactory.java +4 −0 Original line number Original line Diff line number Diff line Loading @@ -34,6 +34,10 @@ public class OwnCloudCredentialsFactory { return new OwnCloudBasicCredentials(username, password); return new OwnCloudBasicCredentials(username, password); } } public static OwnCloudCredentials newBasicCredentials(String username, String password, boolean preemptiveMode) { return new OwnCloudBasicCredentials(username, password, preemptiveMode); } public static OwnCloudCredentials newBearerCredentials(String authToken) { public static OwnCloudCredentials newBearerCredentials(String authToken) { return new OwnCloudBearerCredentials(authToken); return new OwnCloudBearerCredentials(authToken); } } Loading src/com/owncloud/android/lib/common/accounts/AccountUtils.java +62 −30 Original line number Original line Diff line number Diff line Loading @@ -47,21 +47,27 @@ public class AccountUtils { private static final String TAG = AccountUtils.class.getSimpleName(); private static final String TAG = AccountUtils.class.getSimpleName(); public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php"; public static final String WEBDAV_PATH_2_0 = "/files/webdav.php"; public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; public static final String WEBDAV_PATH_9_0 = "/remote.php/dav"; public static final String WEBDAV_PATH_9_0 = "/remote.php/dav"; public static final String ODAV_PATH = "/remote.php/odav"; public static final String ODAV_PATH = "/remote.php/odav"; private static final String SAML_SSO_PATH = "/remote.php/webdav"; 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"; public static final String STATUS_PATH = "/status.php"; /** /** * Returns the proper URL path to access the WebDAV interface of an ownCloud server, * Returns the proper URL path to access the WebDAV interface of an ownCloud server, * according to its authorization method used. * according to its version and the authorization method used. * * * @param version Version of ownCloud server. * @param supportsOAuth If true, access with OAuth 2 authorization is considered. * @param supportsOAuth If true, access with OAuth 2 authorization is considered. * @param supportsSamlSso If true, and supportsOAuth is false, access with SAML-based single-sign-on is considered. * @param supportsSamlSso If true, and supportsOAuth is false, access with SAML-based single-sign-on is considered. * @return default WebDAV path, if no OAuth/Samal * @return WebDAV path for given OC version, null if OC version unknown */ */ public static String getWebdavPath(boolean supportsOAuth, boolean supportsSamlSso) { public static String getWebdavPath(OwnCloudVersion version, boolean supportsOAuth, boolean supportsSamlSso) { if (version != null) { if (supportsOAuth) { if (supportsOAuth) { return ODAV_PATH; return ODAV_PATH; } } Loading @@ -69,7 +75,15 @@ public class AccountUtils { return SAML_SSO_PATH; return SAML_SSO_PATH; } } if (version.compareTo(OwnCloudVersion.owncloud_v4) >= 0) return WEBDAV_PATH_4_0; return WEBDAV_PATH_4_0; if (version.compareTo(OwnCloudVersion.owncloud_v3) >= 0 || version.compareTo(OwnCloudVersion.owncloud_v2) >= 0) return WEBDAV_PATH_2_0; if (version.compareTo(OwnCloudVersion.owncloud_v1) >= 0) return WEBDAV_PATH_1_2; } return null; } } /** /** Loading @@ -89,7 +103,8 @@ public class AccountUtils { String version = ama.getUserData(account, Constants.KEY_OC_VERSION); String version = ama.getUserData(account, Constants.KEY_OC_VERSION); boolean supportsOAuth = (ama.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2) != null); boolean supportsOAuth = (ama.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2) != null); boolean supportsSamlSso = (ama.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null); boolean supportsSamlSso = (ama.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null); String webdavpath = getWebdavPath(supportsOAuth, supportsSamlSso); OwnCloudVersion ver = new OwnCloudVersion(version); String webdavpath = getWebdavPath(ver, supportsOAuth, supportsSamlSso); if (baseurl == null || webdavpath == null) if (baseurl == null || webdavpath == null) throw new AccountNotFoundException(account, "Account not found", null); throw new AccountNotFoundException(account, "Account not found", null); Loading Loading @@ -192,27 +207,44 @@ public class AccountUtils { AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; String username = AccountUtils.getUsernameForAccount(account); String username = AccountUtils.getUsernameForAccount(account); String ocVersion = am.getUserData(account, Constants.KEY_OC_VERSION); OwnCloudVersion version; if (ocVersion == null) { // set to oldest supported version version = OwnCloudVersion.nextcloud_10; } else { version = new OwnCloudVersion(ocVersion); } if (isOauth2) { if (isOauth2) { String accessToken = am.blockingGetAuthToken(account, String accessToken = am.blockingGetAuthToken( AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false); account, AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false); credentials = OwnCloudCredentialsFactory.newBearerCredentials(accessToken); credentials = OwnCloudCredentialsFactory.newBearerCredentials(accessToken); } else if (isSamlSso) { } else if (isSamlSso) { String accessToken = am.blockingGetAuthToken(account, String accessToken = am.blockingGetAuthToken( AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), false); account, AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), false); credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken); credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken); } else { } else { String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), String password = am.blockingGetAuthToken( account, AccountTypeUtils.getAuthTokenTypePass(account.type), false); false); credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password); credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password, version.isPreemptiveAuthenticationPreferred()); } } return credentials; return credentials; } } Loading Loading
src/com/owncloud/android/lib/common/DynamicSessionManager.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -5,6 +5,7 @@ import android.accounts.OperationCanceledException; import android.content.Context; import android.content.Context; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import java.io.IOException; import java.io.IOException; Loading Loading @@ -35,7 +36,16 @@ public class DynamicSessionManager implements OwnCloudClientManager { throws AccountUtils.AccountNotFoundException, throws AccountUtils.AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException { OperationCanceledException, AuthenticatorException, IOException { OwnCloudVersion ownCloudVersion = null; if (account.getSavedAccount() != null) { ownCloudVersion = AccountUtils.getServerVersionForAccount(account.getSavedAccount(), context); } if (ownCloudVersion != null && ownCloudVersion.isPreemptiveAuthenticationPreferred()) { return mSingleSessionManager.getClientFor(account, context, useNextcloudUserAgent); return mSingleSessionManager.getClientFor(account, context, useNextcloudUserAgent); } else { return mSimpleFactoryManager.getClientFor(account, context, useNextcloudUserAgent); } } } @Override @Override Loading
src/com/owncloud/android/lib/common/OwnCloudClient.java +13 −7 Original line number Original line Diff line number Diff line Loading @@ -282,7 +282,9 @@ public class OwnCloudClient extends HttpClient { if (destination != null) { if (destination != null) { int suffixIndex = locationStr.lastIndexOf( int suffixIndex = locationStr.lastIndexOf( (mCredentials instanceof OwnCloudBearerCredentials) ? (mCredentials instanceof OwnCloudBearerCredentials) ? AccountUtils.ODAV_PATH : AccountUtils.WEBDAV_PATH_4_0); AccountUtils.ODAV_PATH : AccountUtils.WEBDAV_PATH_4_0 ); String redirectionBase = locationStr.substring(0, suffixIndex); String redirectionBase = locationStr.substring(0, suffixIndex); String destinationStr = destination.getValue(); String destinationStr = destination.getValue(); Loading Loading @@ -343,13 +345,17 @@ public class OwnCloudClient extends HttpClient { } } } } public Uri getNewWebdavUri() { public Uri getNewWebdavUri(boolean filesUri) { if (mCredentials instanceof OwnCloudBearerCredentials) { if (mCredentials instanceof OwnCloudBearerCredentials) { return Uri.parse(mBaseUri + AccountUtils.ODAV_PATH); return Uri.parse(mBaseUri + AccountUtils.ODAV_PATH); } else { if (filesUri) { return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_4_0); } else { } else { return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_9_0); return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_9_0); } } } } } /** /** * Sets the root URI to the ownCloud server. * Sets the root URI to the ownCloud server. Loading
src/com/owncloud/android/lib/common/OwnCloudClientFactory.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -114,7 +114,7 @@ public class OwnCloudClientFactory { OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext); OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext); OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials( OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials( username, password); username, password, (version != null && version.isPreemptiveAuthenticationPreferred())); client.setCredentials(credentials); client.setCredentials(credentials); } } Loading Loading @@ -188,8 +188,9 @@ public class OwnCloudClientFactory { Bundle result = future.getResult(); Bundle result = future.getResult(); String password = result.getString(AccountManager.KEY_AUTHTOKEN); String password = result.getString(AccountManager.KEY_AUTHTOKEN); OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext); OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials( OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials( username, password); username, password, (version != null && version.isPreemptiveAuthenticationPreferred())); client.setCredentials(credentials); client.setCredentials(credentials); } } Loading
src/com/owncloud/android/lib/common/OwnCloudCredentialsFactory.java +4 −0 Original line number Original line Diff line number Diff line Loading @@ -34,6 +34,10 @@ public class OwnCloudCredentialsFactory { return new OwnCloudBasicCredentials(username, password); return new OwnCloudBasicCredentials(username, password); } } public static OwnCloudCredentials newBasicCredentials(String username, String password, boolean preemptiveMode) { return new OwnCloudBasicCredentials(username, password, preemptiveMode); } public static OwnCloudCredentials newBearerCredentials(String authToken) { public static OwnCloudCredentials newBearerCredentials(String authToken) { return new OwnCloudBearerCredentials(authToken); return new OwnCloudBearerCredentials(authToken); } } Loading
src/com/owncloud/android/lib/common/accounts/AccountUtils.java +62 −30 Original line number Original line Diff line number Diff line Loading @@ -47,21 +47,27 @@ public class AccountUtils { private static final String TAG = AccountUtils.class.getSimpleName(); private static final String TAG = AccountUtils.class.getSimpleName(); public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php"; public static final String WEBDAV_PATH_2_0 = "/files/webdav.php"; public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; public static final String WEBDAV_PATH_9_0 = "/remote.php/dav"; public static final String WEBDAV_PATH_9_0 = "/remote.php/dav"; public static final String ODAV_PATH = "/remote.php/odav"; public static final String ODAV_PATH = "/remote.php/odav"; private static final String SAML_SSO_PATH = "/remote.php/webdav"; 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"; public static final String STATUS_PATH = "/status.php"; /** /** * Returns the proper URL path to access the WebDAV interface of an ownCloud server, * Returns the proper URL path to access the WebDAV interface of an ownCloud server, * according to its authorization method used. * according to its version and the authorization method used. * * * @param version Version of ownCloud server. * @param supportsOAuth If true, access with OAuth 2 authorization is considered. * @param supportsOAuth If true, access with OAuth 2 authorization is considered. * @param supportsSamlSso If true, and supportsOAuth is false, access with SAML-based single-sign-on is considered. * @param supportsSamlSso If true, and supportsOAuth is false, access with SAML-based single-sign-on is considered. * @return default WebDAV path, if no OAuth/Samal * @return WebDAV path for given OC version, null if OC version unknown */ */ public static String getWebdavPath(boolean supportsOAuth, boolean supportsSamlSso) { public static String getWebdavPath(OwnCloudVersion version, boolean supportsOAuth, boolean supportsSamlSso) { if (version != null) { if (supportsOAuth) { if (supportsOAuth) { return ODAV_PATH; return ODAV_PATH; } } Loading @@ -69,7 +75,15 @@ public class AccountUtils { return SAML_SSO_PATH; return SAML_SSO_PATH; } } if (version.compareTo(OwnCloudVersion.owncloud_v4) >= 0) return WEBDAV_PATH_4_0; return WEBDAV_PATH_4_0; if (version.compareTo(OwnCloudVersion.owncloud_v3) >= 0 || version.compareTo(OwnCloudVersion.owncloud_v2) >= 0) return WEBDAV_PATH_2_0; if (version.compareTo(OwnCloudVersion.owncloud_v1) >= 0) return WEBDAV_PATH_1_2; } return null; } } /** /** Loading @@ -89,7 +103,8 @@ public class AccountUtils { String version = ama.getUserData(account, Constants.KEY_OC_VERSION); String version = ama.getUserData(account, Constants.KEY_OC_VERSION); boolean supportsOAuth = (ama.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2) != null); boolean supportsOAuth = (ama.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2) != null); boolean supportsSamlSso = (ama.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null); boolean supportsSamlSso = (ama.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null); String webdavpath = getWebdavPath(supportsOAuth, supportsSamlSso); OwnCloudVersion ver = new OwnCloudVersion(version); String webdavpath = getWebdavPath(ver, supportsOAuth, supportsSamlSso); if (baseurl == null || webdavpath == null) if (baseurl == null || webdavpath == null) throw new AccountNotFoundException(account, "Account not found", null); throw new AccountNotFoundException(account, "Account not found", null); Loading Loading @@ -192,27 +207,44 @@ public class AccountUtils { AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; String username = AccountUtils.getUsernameForAccount(account); String username = AccountUtils.getUsernameForAccount(account); String ocVersion = am.getUserData(account, Constants.KEY_OC_VERSION); OwnCloudVersion version; if (ocVersion == null) { // set to oldest supported version version = OwnCloudVersion.nextcloud_10; } else { version = new OwnCloudVersion(ocVersion); } if (isOauth2) { if (isOauth2) { String accessToken = am.blockingGetAuthToken(account, String accessToken = am.blockingGetAuthToken( AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false); account, AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false); credentials = OwnCloudCredentialsFactory.newBearerCredentials(accessToken); credentials = OwnCloudCredentialsFactory.newBearerCredentials(accessToken); } else if (isSamlSso) { } else if (isSamlSso) { String accessToken = am.blockingGetAuthToken(account, String accessToken = am.blockingGetAuthToken( AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), false); account, AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), false); credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken); credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken); } else { } else { String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), String password = am.blockingGetAuthToken( account, AccountTypeUtils.getAuthTokenTypePass(account.type), false); false); credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password); credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password, version.isPreemptiveAuthenticationPreferred()); } } return credentials; return credentials; } } Loading