|
@@ -1,6 +1,9 @@
|
|
|
-/* ownCloud Android client application
|
|
|
+/**
|
|
|
+ * ownCloud Android client application
|
|
|
+ *
|
|
|
+ * @author David A. Velasco
|
|
|
* Copyright (C) 2012 Bartek Przybylski
|
|
|
- * Copyright (C) 2012-2013 ownCloud Inc.
|
|
|
+ * Copyright (C) 2015 ownCloud Inc.
|
|
|
*
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
* it under the terms of the GNU General Public License version 2,
|
|
@@ -38,9 +41,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
|
|
* Controller class accessed from the system AccountManager, providing integration of ownCloud accounts with the Android system.
|
|
|
*
|
|
|
* TODO - better separation in operations for OAuth-capable and regular ownCloud accounts.
|
|
|
- * TODO - review completeness
|
|
|
- *
|
|
|
- * @author David A. Velasco
|
|
|
+ * TODO - review completeness
|
|
|
*/
|
|
|
public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
|
|
|
|
@@ -122,39 +123,39 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
|
|
return bundle;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * {@inheritDoc}
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Bundle confirmCredentials(AccountAuthenticatorResponse response,
|
|
|
- Account account, Bundle options) throws NetworkErrorException {
|
|
|
- try {
|
|
|
- validateAccountType(account.type);
|
|
|
- } catch (AuthenticatorException e) {
|
|
|
- Log_OC.e(TAG, "Failed to validate account type " + account.type + ": "
|
|
|
- + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- return e.getFailureBundle();
|
|
|
- }
|
|
|
- Intent intent = new Intent(mContext, AuthenticatorActivity.class);
|
|
|
- intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,
|
|
|
- response);
|
|
|
- intent.putExtra(KEY_ACCOUNT, account);
|
|
|
- intent.putExtra(KEY_LOGIN_OPTIONS, options);
|
|
|
-
|
|
|
- setIntentFlags(intent);
|
|
|
-
|
|
|
- Bundle resultBundle = new Bundle();
|
|
|
- resultBundle.putParcelable(AccountManager.KEY_INTENT, intent);
|
|
|
- return resultBundle;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Bundle editProperties(AccountAuthenticatorResponse response,
|
|
|
- String accountType) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Bundle confirmCredentials(AccountAuthenticatorResponse response,
|
|
|
+ Account account, Bundle options) throws NetworkErrorException {
|
|
|
+ try {
|
|
|
+ validateAccountType(account.type);
|
|
|
+ } catch (AuthenticatorException e) {
|
|
|
+ Log_OC.e(TAG, "Failed to validate account type " + account.type + ": "
|
|
|
+ + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ return e.getFailureBundle();
|
|
|
+ }
|
|
|
+ Intent intent = new Intent(mContext, AuthenticatorActivity.class);
|
|
|
+ intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,
|
|
|
+ response);
|
|
|
+ intent.putExtra(KEY_ACCOUNT, account);
|
|
|
+ intent.putExtra(KEY_LOGIN_OPTIONS, options);
|
|
|
+
|
|
|
+ setIntentFlags(intent);
|
|
|
+
|
|
|
+ Bundle resultBundle = new Bundle();
|
|
|
+ resultBundle.putParcelable(AccountManager.KEY_INTENT, intent);
|
|
|
+ return resultBundle;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Bundle editProperties(AccountAuthenticatorResponse response,
|
|
|
+ String accountType) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* {@inheritDoc}
|
|
|
*/
|
|
@@ -253,69 +254,69 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void validateAuthTokenType(String authTokenType)
|
|
|
- throws UnsupportedAuthTokenTypeException {
|
|
|
- if (!authTokenType.equals(MainApp.getAuthTokenType()) &&
|
|
|
- !authTokenType.equals(AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType())) &&
|
|
|
- !authTokenType.equals(AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType())) &&
|
|
|
+ private void validateAuthTokenType(String authTokenType)
|
|
|
+ throws UnsupportedAuthTokenTypeException {
|
|
|
+ if (!authTokenType.equals(MainApp.getAuthTokenType()) &&
|
|
|
+ !authTokenType.equals(AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType())) &&
|
|
|
+ !authTokenType.equals(AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType())) &&
|
|
|
!authTokenType.equals(AccountTypeUtils.getAuthTokenTypeRefreshToken(MainApp.getAccountType())) &&
|
|
|
- !authTokenType.equals(AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()))) {
|
|
|
- throw new UnsupportedAuthTokenTypeException();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static class AuthenticatorException extends Exception {
|
|
|
- private static final long serialVersionUID = 1L;
|
|
|
- private Bundle mFailureBundle;
|
|
|
-
|
|
|
- public AuthenticatorException(int code, String errorMsg) {
|
|
|
- mFailureBundle = new Bundle();
|
|
|
- mFailureBundle.putInt(AccountManager.KEY_ERROR_CODE, code);
|
|
|
- mFailureBundle
|
|
|
- .putString(AccountManager.KEY_ERROR_MESSAGE, errorMsg);
|
|
|
- }
|
|
|
-
|
|
|
- public Bundle getFailureBundle() {
|
|
|
- return mFailureBundle;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static class UnsupportedAccountTypeException extends
|
|
|
- AuthenticatorException {
|
|
|
- private static final long serialVersionUID = 1L;
|
|
|
-
|
|
|
- public UnsupportedAccountTypeException() {
|
|
|
- super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
|
|
|
- "Unsupported account type");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static class UnsupportedAuthTokenTypeException extends
|
|
|
- AuthenticatorException {
|
|
|
- private static final long serialVersionUID = 1L;
|
|
|
-
|
|
|
- public UnsupportedAuthTokenTypeException() {
|
|
|
- super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
|
|
|
- "Unsupported auth token type");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static class UnsupportedFeaturesException extends
|
|
|
- AuthenticatorException {
|
|
|
- public static final long serialVersionUID = 1L;
|
|
|
-
|
|
|
- public UnsupportedFeaturesException() {
|
|
|
- super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
|
|
|
- "Unsupported features");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static class AccessDeniedException extends AuthenticatorException {
|
|
|
- public AccessDeniedException(int code, String errorMsg) {
|
|
|
- super(AccountManager.ERROR_CODE_INVALID_RESPONSE, "Access Denied");
|
|
|
- }
|
|
|
-
|
|
|
- private static final long serialVersionUID = 1L;
|
|
|
-
|
|
|
- }
|
|
|
-}
|
|
|
+ !authTokenType.equals(AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()))) {
|
|
|
+ throw new UnsupportedAuthTokenTypeException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class AuthenticatorException extends Exception {
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+ private Bundle mFailureBundle;
|
|
|
+
|
|
|
+ public AuthenticatorException(int code, String errorMsg) {
|
|
|
+ mFailureBundle = new Bundle();
|
|
|
+ mFailureBundle.putInt(AccountManager.KEY_ERROR_CODE, code);
|
|
|
+ mFailureBundle
|
|
|
+ .putString(AccountManager.KEY_ERROR_MESSAGE, errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Bundle getFailureBundle() {
|
|
|
+ return mFailureBundle;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class UnsupportedAccountTypeException extends
|
|
|
+ AuthenticatorException {
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+
|
|
|
+ public UnsupportedAccountTypeException() {
|
|
|
+ super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
|
|
|
+ "Unsupported account type");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class UnsupportedAuthTokenTypeException extends
|
|
|
+ AuthenticatorException {
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+
|
|
|
+ public UnsupportedAuthTokenTypeException() {
|
|
|
+ super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
|
|
|
+ "Unsupported auth token type");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class UnsupportedFeaturesException extends
|
|
|
+ AuthenticatorException {
|
|
|
+ public static final long serialVersionUID = 1L;
|
|
|
+
|
|
|
+ public UnsupportedFeaturesException() {
|
|
|
+ super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
|
|
|
+ "Unsupported features");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class AccessDeniedException extends AuthenticatorException {
|
|
|
+ public AccessDeniedException(int code, String errorMsg) {
|
|
|
+ super(AccountManager.ERROR_CODE_INVALID_RESPONSE, "Access Denied");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|