Loading src/main/java/com/nextcloud/android/sso/AccountImporter.java +20 −4 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.util.Log; import android.widget.Toast; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountPermissionNotGrantedException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotInstalledException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException; import com.nextcloud.android.sso.exceptions.SSOException; Loading Loading @@ -184,7 +185,7 @@ public class AccountImporter { } else { requestAuthToken(fragment, data); } } catch (NextcloudFilesAppNotSupportedException e) { } catch (NextcloudFilesAppNotSupportedException | NextcloudFilesAppAccountPermissionNotGrantedException e) { UiExceptionManager.showDialogForException(context, e); } break; Loading Loading @@ -222,7 +223,19 @@ public class AccountImporter { throw SSOException.parseNextcloudCustomException(new Exception(exception)); } public static void requestAuthToken(Fragment fragment, Intent intent) throws NextcloudFilesAppNotSupportedException { public static void authenticateSingleSignAccount(Fragment fragment, SingleSignOnAccount account) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name); requestAuthToken(fragment, intent); } public static void authenticateSingleSignAccount(Activity activity, SingleSignOnAccount account) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name); requestAuthToken(activity, intent); } public static void requestAuthToken(Fragment fragment, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { Intent authIntent = buildRequestAuthTokenIntent(fragment.getContext(), intent); try { fragment.startActivityForResult(authIntent, REQUEST_AUTH_TOKEN_SSO); Loading @@ -231,7 +244,7 @@ public class AccountImporter { } } public static void requestAuthToken(Activity activity, Intent intent) throws NextcloudFilesAppNotSupportedException { public static void requestAuthToken(Activity activity, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { Intent authIntent = buildRequestAuthTokenIntent(activity, intent); try { activity.startActivityForResult(authIntent, REQUEST_AUTH_TOKEN_SSO); Loading @@ -240,9 +253,12 @@ public class AccountImporter { } } private static Intent buildRequestAuthTokenIntent(Context context, Intent intent) { private static Intent buildRequestAuthTokenIntent(Context context, Intent intent) throws NextcloudFilesAppAccountPermissionNotGrantedException { String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); Account account = AccountImporter.getAccountForName(context, accountName); if(account == null) { throw new NextcloudFilesAppAccountPermissionNotGrantedException(); } Intent authIntent = new Intent(); authIntent.setComponent(new ComponentName("com.nextcloud.client", "com.owncloud.android.ui.activity.SsoGrantPermissionActivity")); Loading src/main/java/com/nextcloud/android/sso/helper/SingleAccountHelper.java +12 −0 Original line number Diff line number Diff line Loading @@ -19,11 +19,15 @@ package com.nextcloud.android.sso.helper; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.support.v4.app.Fragment; import com.nextcloud.android.sso.AccountImporter; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountPermissionNotGrantedException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException; import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException; import com.nextcloud.android.sso.model.SingleSignOnAccount; Loading Loading @@ -52,4 +56,12 @@ public final class SingleAccountHelper { SharedPreferences mPrefs = AccountImporter.getSharedPreferences(context); mPrefs.edit().putString(PREF_CURRENT_ACCOUNT_STRING, accountName).commit(); } public static void reauthenticateCurrentAccount(Fragment fragment) throws NoCurrentAccountSelectedException, NextcloudFilesAppAccountNotFoundException, NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { AccountImporter.authenticateSingleSignAccount(fragment, getCurrentSingleSignOnAccount(fragment.getContext())); } public static void reauthenticateCurrentAccount(Activity activity) throws NoCurrentAccountSelectedException, NextcloudFilesAppAccountNotFoundException, NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { AccountImporter.authenticateSingleSignAccount(activity, getCurrentSingleSignOnAccount(activity)); } } Loading
src/main/java/com/nextcloud/android/sso/AccountImporter.java +20 −4 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.util.Log; import android.widget.Toast; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountPermissionNotGrantedException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotInstalledException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException; import com.nextcloud.android.sso.exceptions.SSOException; Loading Loading @@ -184,7 +185,7 @@ public class AccountImporter { } else { requestAuthToken(fragment, data); } } catch (NextcloudFilesAppNotSupportedException e) { } catch (NextcloudFilesAppNotSupportedException | NextcloudFilesAppAccountPermissionNotGrantedException e) { UiExceptionManager.showDialogForException(context, e); } break; Loading Loading @@ -222,7 +223,19 @@ public class AccountImporter { throw SSOException.parseNextcloudCustomException(new Exception(exception)); } public static void requestAuthToken(Fragment fragment, Intent intent) throws NextcloudFilesAppNotSupportedException { public static void authenticateSingleSignAccount(Fragment fragment, SingleSignOnAccount account) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name); requestAuthToken(fragment, intent); } public static void authenticateSingleSignAccount(Activity activity, SingleSignOnAccount account) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name); requestAuthToken(activity, intent); } public static void requestAuthToken(Fragment fragment, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { Intent authIntent = buildRequestAuthTokenIntent(fragment.getContext(), intent); try { fragment.startActivityForResult(authIntent, REQUEST_AUTH_TOKEN_SSO); Loading @@ -231,7 +244,7 @@ public class AccountImporter { } } public static void requestAuthToken(Activity activity, Intent intent) throws NextcloudFilesAppNotSupportedException { public static void requestAuthToken(Activity activity, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { Intent authIntent = buildRequestAuthTokenIntent(activity, intent); try { activity.startActivityForResult(authIntent, REQUEST_AUTH_TOKEN_SSO); Loading @@ -240,9 +253,12 @@ public class AccountImporter { } } private static Intent buildRequestAuthTokenIntent(Context context, Intent intent) { private static Intent buildRequestAuthTokenIntent(Context context, Intent intent) throws NextcloudFilesAppAccountPermissionNotGrantedException { String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); Account account = AccountImporter.getAccountForName(context, accountName); if(account == null) { throw new NextcloudFilesAppAccountPermissionNotGrantedException(); } Intent authIntent = new Intent(); authIntent.setComponent(new ComponentName("com.nextcloud.client", "com.owncloud.android.ui.activity.SsoGrantPermissionActivity")); Loading
src/main/java/com/nextcloud/android/sso/helper/SingleAccountHelper.java +12 −0 Original line number Diff line number Diff line Loading @@ -19,11 +19,15 @@ package com.nextcloud.android.sso.helper; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.support.v4.app.Fragment; import com.nextcloud.android.sso.AccountImporter; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountPermissionNotGrantedException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException; import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException; import com.nextcloud.android.sso.model.SingleSignOnAccount; Loading Loading @@ -52,4 +56,12 @@ public final class SingleAccountHelper { SharedPreferences mPrefs = AccountImporter.getSharedPreferences(context); mPrefs.edit().putString(PREF_CURRENT_ACCOUNT_STRING, accountName).commit(); } public static void reauthenticateCurrentAccount(Fragment fragment) throws NoCurrentAccountSelectedException, NextcloudFilesAppAccountNotFoundException, NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { AccountImporter.authenticateSingleSignAccount(fragment, getCurrentSingleSignOnAccount(fragment.getContext())); } public static void reauthenticateCurrentAccount(Activity activity) throws NoCurrentAccountSelectedException, NextcloudFilesAppAccountNotFoundException, NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { AccountImporter.authenticateSingleSignAccount(activity, getCurrentSingleSignOnAccount(activity)); } }