Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ae111ee authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Merge branch '2159-Fix_session_validation_issue_for_dav_requests' into 'main'

2159-Fix_session_validation_issue_for_dav_requests

See merge request !123
parents 118f9684 c4195d5e
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -224,7 +224,7 @@ dependencies {
    implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
    implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
    implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5' // remove after entire switch to lib v2
    implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5' // remove after entire switch to lib v2
    implementation 'com.google.code.gson:gson:2.10.1'
    implementation 'com.google.code.gson:gson:2.10.1'
    implementation("foundation.e:Nextcloud-Android-Library:1.0.8-u2.17-release") {
    implementation("foundation.e:Nextcloud-Android-Library:1.0.9-u2.17-release") {
        exclude group: 'com.gitlab.bitfireAT', module: 'dav4jvm'
        exclude group: 'com.gitlab.bitfireAT', module: 'dav4jvm'
        exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
        exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
        exclude group: 'com.squareup.okhttp3'
        exclude group: 'com.squareup.okhttp3'
+0 −6
Original line number Original line Diff line number Diff line
@@ -335,7 +335,6 @@ public class InputStreamBinder extends IInputStreamService.Stub {
                    new IllegalStateException("URL need to start with a /"));
                    new IllegalStateException("URL need to start with a /"));
        }
        }


        OwnCloudClientManagerFactory.setUserAgent(getUserAgent());
        final OwnCloudClientManager ownCloudClientManager = OwnCloudClientManagerFactory.getDefaultSingleton();
        final OwnCloudClientManager ownCloudClientManager = OwnCloudClientManagerFactory.getDefaultSingleton();
        final OwnCloudAccount ownCloudAccount = new OwnCloudAccount(account, context);
        final OwnCloudAccount ownCloudAccount = new OwnCloudAccount(account, context);
        final OwnCloudClient client = ownCloudClientManager.getClientFor(ownCloudAccount, context);
        final OwnCloudClient client = ownCloudClientManager.getClientFor(ownCloudAccount, context);
@@ -405,10 +404,6 @@ public class InputStreamBinder extends IInputStreamService.Stub {
        return path.contains("/index.php/apps/");
        return path.contains("/index.php/apps/");
    }
    }


    private static String getUserAgent() {
        return "AccountManager-SSO(" + BuildConfig.VERSION_NAME + ")";
    }

    private Response processRequestV2(final NextcloudRequest request, final InputStream requestBodyInputStream)
    private Response processRequestV2(final NextcloudRequest request, final InputStream requestBodyInputStream)
            throws UnsupportedOperationException,
            throws UnsupportedOperationException,
            com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException,
            com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException,
@@ -429,7 +424,6 @@ public class InputStreamBinder extends IInputStreamService.Stub {
                    new IllegalStateException("URL need to start with a /"));
                    new IllegalStateException("URL need to start with a /"));
        }
        }


        OwnCloudClientManagerFactory.setUserAgent(getUserAgent());
        final OwnCloudClientManager ownCloudClientManager = OwnCloudClientManagerFactory.getDefaultSingleton();
        final OwnCloudClientManager ownCloudClientManager = OwnCloudClientManagerFactory.getDefaultSingleton();
        final OwnCloudAccount ownCloudAccount = new OwnCloudAccount(account, context);
        final OwnCloudAccount ownCloudAccount = new OwnCloudAccount(account, context);
        final OwnCloudClient client = ownCloudClientManager.getClientFor(ownCloudAccount, context);
        final OwnCloudClient client = ownCloudClientManager.getClientFor(ownCloudAccount, context);
+2 −6
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ import at.bitfire.davdroid.settings.AccountSettings
import at.bitfire.davdroid.settings.Settings
import at.bitfire.davdroid.settings.Settings
import at.bitfire.davdroid.settings.SettingsManager
import at.bitfire.davdroid.settings.SettingsManager
import at.bitfire.davdroid.syncadapter.AccountUtils
import at.bitfire.davdroid.syncadapter.AccountUtils
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
import dagger.hilt.EntryPoint
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.android.EntryPointAccessors
@@ -325,12 +326,7 @@ class HttpClient private constructor(




    object UserAgentInterceptor: Interceptor {
    object UserAgentInterceptor: Interceptor {

        val userAgent = OwnCloudClientManagerFactory.getNextCloudUserAgent()
        // use Locale.ROOT because numbers may be encoded as non-ASCII characters in other locales
        private val userAgentDateFormat = SimpleDateFormat("yyyy/MM/dd", Locale.ROOT)
        private val userAgentDate = userAgentDateFormat.format(Date(BuildConfig.buildTime))
        val userAgent = "${BuildConfig.userAgent}/${BuildConfig.VERSION_NAME} ($userAgentDate; dav4jvm; " +
                "okhttp/${OkHttp.VERSION}) Android/${Build.VERSION.RELEASE}"


        init {
        init {
            Logger.log.info("Will set \"User-Agent: $userAgent\" for further requests")
            Logger.log.info("Will set \"User-Agent: $userAgent\" for further requests")
+16 −0
Original line number Original line Diff line number Diff line
@@ -635,4 +635,20 @@ class AccountSettings(
                Constants.DEFAULT_CONTACTS_SYNC_INTERVAL
                Constants.DEFAULT_CONTACTS_SYNC_INTERVAL
            else -> Constants.DEFAULT_CALENDAR_SYNC_INTERVAL
            else -> Constants.DEFAULT_CALENDAR_SYNC_INTERVAL
        }
        }

    fun containsPersistentCookie(): Boolean {
        return !accountManager.getUserData(
            account,
            NCAccountUtils.Constants.KEY_OKHTTP_COOKIES
        ).isNullOrBlank()
    }

    fun clearCookie() {
        accountManager.setUserData(account, COOKIE_KEY, null)
        accountManager.setUserData(
            account,
            NCAccountUtils.Constants.KEY_COOKIES,
            null
        )
    }
}
}
+9 −1
Original line number Original line Diff line number Diff line
@@ -851,9 +851,15 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
                syncResult.stats.numIoExceptions++
                syncResult.stats.numIoExceptions++
            }
            }
            is UnauthorizedException -> {
            is UnauthorizedException -> {
                Logger.log.log(Level.SEVERE, "Not authorized anymore", e)
                message = context.getString(R.string.sync_error_authentication_failed)
                message = context.getString(R.string.sync_error_authentication_failed)
                syncResult.stats.numAuthExceptions++
                syncResult.stats.numAuthExceptions++

                // persistent session cookie is present. Probably the session is outDated. no need to show the notification
                if (accountSettings.containsPersistentCookie()) {
                    Logger.log.log(Level.FINE, "Authorization error. Session outDated")
                    return
                }

                if (account.type.toLowerCase(Locale.getDefault()).contains("google")) {
                if (account.type.toLowerCase(Locale.getDefault()).contains("google")) {
                    /* TODO Investigate deeper why this exception sometimes happens
                    /* TODO Investigate deeper why this exception sometimes happens
                     * https://gitlab.e.foundation/e/backlog/-/issues/3430
                     * https://gitlab.e.foundation/e/backlog/-/issues/3430
@@ -861,6 +867,8 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
                    Logger.log.log(Level.WARNING, "Authorization error. Do not notify the user")
                    Logger.log.log(Level.WARNING, "Authorization error. Do not notify the user")
                    return
                    return
                }
                }

                Logger.log.log(Level.SEVERE, "Not authorized anymore", e)
            }
            }
            is HttpException, is DavException -> {
            is HttpException, is DavException -> {
                Logger.log.log(Level.SEVERE, "HTTP/DAV exception", e)
                Logger.log.log(Level.SEVERE, "HTTP/DAV exception", e)
Loading