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

Commit eb323435 authored by David Luhmer's avatar David Luhmer
Browse files

Merge remote-tracking branch 'remotes/origin/master' into sso

# Conflicts:
#	src/main/java/com/nextcloud/android/sso/api/NextcloudAPI.java
parents e5ac8610 2b70d60b
Loading
Loading
Loading
Loading
+36 −39
Original line number Diff line number Diff line
/*
 * Nextcloud SingleSignOn
 *
 * @author David Luhmer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.nextcloud.android.sso;

import android.accounts.Account;
@@ -32,25 +51,6 @@ import static com.nextcloud.android.sso.Constants.NEXTCLOUD_SSO;
import static com.nextcloud.android.sso.Constants.NEXTCLOUD_SSO_EXCEPTION;
import static com.nextcloud.android.sso.Constants.SSO_SHARED_PREFERENCE;

/**
 *  Nextcloud SingleSignOn
 *
 *  @author David Luhmer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class AccountImporter {

    private static final String TAG = AccountImporter.class.getCanonicalName();
@@ -122,9 +122,11 @@ public class AccountImporter {
        }
    }

    public static SingleSignOnAccount getSingleSignOnAccount(Context context, final String accountName) throws NextcloudFilesAppAccountNotFoundException {
    public static SingleSignOnAccount getSingleSignOnAccount(Context context, final String accountName)
            throws NextcloudFilesAppAccountNotFoundException {
        SharedPreferences mPrefs = getSharedPreferences(context);
        String prefKey = getPrefKeyForAccount(accountName);

        if (mPrefs.contains(prefKey)) {
            try {
                return SingleSignOnAccount.fromString(mPrefs.getString(prefKey, null));
@@ -141,9 +143,6 @@ public class AccountImporter {
    public static SingleSignOnAccount extractSingleSignOnAccountFromResponse(Intent intent, Context context) {
        Bundle future = intent.getBundleExtra(NEXTCLOUD_SSO);

        //String auth_token = future.getString(AccountManager.KEY_AUTHTOKEN);
        //String auth_account_type = future.getString(AccountManager.KEY_ACCOUNT_TYPE);

        String accountName = future.getString(AccountManager.KEY_ACCOUNT_NAME);
        String username = future.getString(Constants.SSO_USERNAME);
        String token = future.getString(Constants.SSO_TOKEN);
@@ -155,27 +154,28 @@ public class AccountImporter {
        try {
            mPrefs.edit().putString(prefKey, SingleSignOnAccount.toString(ssoAccount)).apply();
        } catch (IOException e) {
            e.printStackTrace();
            Log.e(TAG, "SSO failed", e);
        }
        return ssoAccount;
    }




    public interface IAccountAccessGranted {
        void accountAccessGranted(SingleSignOnAccount singleSignOnAccount);
    }

    public static void onActivityResult(int requestCode, int resultCode, Intent data, Activity activity, IAccountAccessGranted callback) {
    public static void onActivityResult(int requestCode, int resultCode, Intent data, Activity activity,
                                        IAccountAccessGranted callback) {
        onActivityResult(requestCode, resultCode, data, activity, null, callback);
    }

    public static void onActivityResult(int requestCode, int resultCode, Intent data, Fragment fragment, IAccountAccessGranted callback) {
    public static void onActivityResult(int requestCode, int resultCode, Intent data, Fragment fragment,
                                        IAccountAccessGranted callback) {
        onActivityResult(requestCode, resultCode, data, null, fragment, callback);
    }

    private static void onActivityResult(int requestCode, int resultCode, Intent data, Activity activity, Fragment fragment, IAccountAccessGranted callback) {
    private static void onActivityResult(int requestCode, int resultCode, Intent data, Activity activity,
                                         Fragment fragment, IAccountAccessGranted callback) {
        Context context = (activity != null) ? activity : fragment.getContext();

        if (resultCode == RESULT_OK) {
@@ -220,7 +220,6 @@ public class AccountImporter {
        }
    }


    public static void handleFailedAuthRequest(Intent data) throws SSOException {
        String exception = data.getStringExtra(NEXTCLOUD_SSO_EXCEPTION);
        throw SSOException.parseNextcloudCustomException(new Exception(exception));
@@ -248,15 +247,13 @@ public class AccountImporter {
        String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
        Account account = AccountImporter.getAccountForName(context, accountName);
        Intent authIntent = new Intent();
        authIntent.setComponent(new ComponentName("com.nextcloud.client", "com.owncloud.android.ui.activity.SsoGrantPermissionActivity"));
        authIntent.setComponent(new ComponentName("com.nextcloud.client",
                "com.owncloud.android.ui.activity.SsoGrantPermissionActivity"));
        authIntent.putExtra(NEXTCLOUD_FILES_ACCOUNT, account);
        return authIntent;
    }





    public static SharedPreferences getSharedPreferences(Context context) {
        return context.getSharedPreferences(SSO_SHARED_PREFERENCE, Context.MODE_PRIVATE);
    }
+19 −0
Original line number Diff line number Diff line
/*
 * Nextcloud SingleSignOn
 *
 * @author David Luhmer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.nextcloud.android.sso;

public class Constants {
+30 −28
Original line number Diff line number Diff line
/*
 * Nextcloud SingleSignOn
 *
 * @author David Luhmer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.nextcloud.android.sso.api;

import android.content.ComponentName;
@@ -36,29 +55,11 @@ import io.reactivex.annotations.NonNull;

import static com.nextcloud.android.sso.exceptions.SSOException.parseNextcloudCustomException;

/**
 *  Nextcloud SingleSignOn
 *
 *  @author David Luhmer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class NextcloudAPI {

    public interface ApiConnectedListener {
        void onConnected();

        void onError(Exception ex);
    }

@@ -111,7 +112,8 @@ public class NextcloudAPI {

        try {
            Intent intentService = new Intent();
            intentService.setComponent(new ComponentName("com.nextcloud.client", "com.owncloud.android.services.AccountManagerService"));
            intentService.setComponent(new ComponentName("com.nextcloud.client",
                    "com.owncloud.android.services.AccountManagerService"));
            if (!mContext.bindService(intentService, mConnection, Context.BIND_AUTO_CREATE)) {
                Log.d(TAG, "Binding to AccountManagerService returned false");
                throw new IllegalStateException("Binding to AccountManagerService returned false");
@@ -213,6 +215,7 @@ public class NextcloudAPI {

    /**
     * The InputStreams needs to be closed after reading from it
     *
     * @param request
     * @return
     * @throws Exception or SSOException
@@ -241,11 +244,13 @@ public class NextcloudAPI {

    /**
     * DO NOT CALL THIS METHOD DIRECTLY - use "performNetworkRequest(...)" instead
     *
     * @param request
     * @return
     * @throws IOException
     */
    private ParcelFileDescriptor performAidlNetworkRequest(NextcloudRequest request) throws IOException, RemoteException {
    private ParcelFileDescriptor performAidlNetworkRequest(NextcloudRequest request)
            throws IOException, RemoteException {
        // Log.d(TAG, request.url);
        request.setAccountName(getAccountName());
        request.setToken(getAccountToken());
@@ -271,7 +276,6 @@ public class NextcloudAPI {
    }



    public static <T> T deserializeObjectAndCloseStream(InputStream is) throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(is);
        T result = (T) ois.readObject();
@@ -279,6 +283,4 @@ public class NextcloudAPI {
        ois.close();
        return result;
    }


}
+8 −8
Original line number Diff line number Diff line
package com.nextcloud.android.sso.exceptions;

import android.content.Context;

import com.nextcloud.android.sso.R;
import com.nextcloud.android.sso.model.ExceptionMessage;

/**
/*
 *  Nextcloud SingleSignOn
 *
 *  @author David Luhmer
@@ -24,6 +17,13 @@ import com.nextcloud.android.sso.model.ExceptionMessage;
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.nextcloud.android.sso.exceptions;

import android.content.Context;

import com.nextcloud.android.sso.R;
import com.nextcloud.android.sso.model.ExceptionMessage;

public class NextcloudFilesAppAccountPermissionNotGrantedException extends SSOException {

    @Override
+14 −14
Original line number Diff line number Diff line
package com.nextcloud.android.sso.exceptions;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.nextcloud.android.sso.Constants;
import com.nextcloud.android.sso.model.ExceptionMessage;

/**
/*
 *  Nextcloud SingleSignOn
 *
 *  @author David Luhmer
@@ -26,6 +17,15 @@ import com.nextcloud.android.sso.model.ExceptionMessage;
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.nextcloud.android.sso.exceptions;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.nextcloud.android.sso.Constants;
import com.nextcloud.android.sso.model.ExceptionMessage;

public class SSOException extends Exception {

    private static final String TAG = SSOException.class.getCanonicalName();
Loading