version bump
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / authenticator / AccountAuthenticator.java
index 42df09f..be0b8e0 100644 (file)
@@ -1,3 +1,21 @@
+/* ownCloud Android client application\r
+ *   Copyright (C) 2012  Bartek Przybylski\r
+ *\r
+ *   This program is free software: you can redistribute it and/or modify\r
+ *   it under the terms of the GNU General Public License as published by\r
+ *   the Free Software Foundation, either version 3 of the License, or\r
+ *   (at your option) any later version.\r
+ *\r
+ *   This program is distributed in the hope that it will be useful,\r
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *   GNU General Public License for more details.\r
+ *\r
+ *   You should have received a copy of the GNU General Public License\r
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ */\r
+\r
 package eu.alefzero.owncloud.authenticator;\r
 \r
 import eu.alefzero.owncloud.ui.activity.AuthenticatorActivity;\r
@@ -8,11 +26,10 @@ import android.os.Bundle;
 import android.util.Log;\r
 \r
 public class AccountAuthenticator extends AbstractAccountAuthenticator {\r
-    public static final String OPTIONS_USERNAME = "username";\r
-    public static final String OPTIONS_PASSWORD = "password";\r
-    public static final String OPTIONS_FILE_LIST_SYNC_ENABLED = "filelist";\r
-    public static final String OPTIONS_PINNED_FILE_SYNC_ENABLED = "pinned";\r
-\r
+    /**\r
+     * Is used by android system to assign accounts to authenticators. Should be\r
+     * used by application and all extensions.\r
+     */\r
     public static final String ACCOUNT_TYPE = "owncloud";\r
     public static final String AUTH_TOKEN_TYPE = "org.owncloud";\r
 \r
@@ -20,9 +37,27 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
     public static final String KEY_REQUIRED_FEATURES = "requiredFeatures";\r
     public static final String KEY_LOGIN_OPTIONS = "loginOptions";\r
     public static final String KEY_ACCOUNT = "account";\r
+    /**\r
+     * Value under this key should handle path to webdav php script. Will be\r
+     * removed and usage should be replaced by combining\r
+     * {@link eu.alefzero.owncloud.authenticator.KEY_OC_BASE_URL} and\r
+     * {@link eu.alefzero.owncloud.utils.OwnCloudVersion}\r
+     * \r
+     * @deprecated\r
+     */\r
     public static final String KEY_OC_URL = "oc_url";\r
-    public static final String KEY_CONTACT_URL = "oc_contact_url";\r
+    /**\r
+     * Version should be 3 numbers separated by dot so it can be parsed by\r
+     * {@link eu.alefzero.owncloud.utils.OwnCloudVersion}\r
+     */\r
+    public static final String KEY_OC_VERSION = "oc_version";\r
+    /**\r
+     * Base url should point to owncloud installation without trailing / ie:\r
+     * http://server/path or https://owncloud.server\r
+     */\r
+    public static final String KEY_OC_BASE_URL = "oc_base_url";\r
 \r
+    private static final String TAG = "AccountAuthenticator";\r
     private Context mContext;\r
 \r
     public AccountAuthenticator(Context context) {\r
@@ -35,26 +70,27 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
      */\r
     @Override\r
     public Bundle addAccount(AccountAuthenticatorResponse response,\r
-                             String accountType, String authTokenType, String[] requiredFeatures,\r
-                             Bundle options) throws NetworkErrorException {\r
-        Log.i(getClass().getName(), "Adding account with type " + accountType +\r
-                " and auth token " + authTokenType);\r
+            String accountType, String authTokenType,\r
+            String[] requiredFeatures, Bundle options)\r
+            throws NetworkErrorException {\r
+        Log.i(TAG, "Adding account with type " + accountType\r
+                + " and auth token " + authTokenType);\r
         try {\r
             validateAccountType(accountType);\r
-            //validateAuthTokenType(authTokenType);\r
-            validateRequiredFeatures(requiredFeatures);\r
         } catch (AuthenticatorException e) {\r
+            Log.e(TAG, "Failed to validate account type " + accountType + ": "\r
+                    + e.getMessage());\r
             e.printStackTrace();\r
             return e.getFailureBundle();\r
         }\r
         final Intent intent = new Intent(mContext, AuthenticatorActivity.class);\r
-        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);\r
+        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,\r
+                response);\r
         intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType);\r
         intent.putExtra(KEY_REQUIRED_FEATURES, requiredFeatures);\r
         intent.putExtra(KEY_LOGIN_OPTIONS, options);\r
 \r
         setIntentFlags(intent);\r
-        Log.i(getClass().getName(), intent.toString());\r
         final Bundle bundle = new Bundle();\r
         bundle.putParcelable(AccountManager.KEY_INTENT, intent);\r
         return bundle;\r
@@ -65,14 +101,18 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
      */\r
     @Override\r
     public Bundle confirmCredentials(AccountAuthenticatorResponse response,\r
-                                     Account account, Bundle options) throws NetworkErrorException {\r
+            Account account, Bundle options) throws NetworkErrorException {\r
         try {\r
             validateAccountType(account.type);\r
         } catch (AuthenticatorException e) {\r
+            Log.e(TAG, "Failed to validate account type " + account.type + ": "\r
+                    + e.getMessage());\r
+            e.printStackTrace();\r
             return e.getFailureBundle();\r
         }\r
         Intent intent = new Intent(mContext, AuthenticatorActivity.class);\r
-        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);\r
+        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,\r
+                response);\r
         intent.putExtra(KEY_ACCOUNT, account);\r
         intent.putExtra(KEY_LOGIN_OPTIONS, options);\r
 \r
@@ -85,20 +125,21 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
 \r
     @Override\r
     public Bundle editProperties(AccountAuthenticatorResponse response,\r
-                                 String accountType) {\r
-        throw new UnsupportedOperationException();\r
+            String accountType) {\r
+        return null;\r
     }\r
 \r
     @Override\r
     public Bundle getAuthToken(AccountAuthenticatorResponse response,\r
-                               Account account, String authTokenType, Bundle options)\r
+            Account account, String authTokenType, Bundle options)\r
             throws NetworkErrorException {\r
-        Log.i(getClass().getName(), "Getting authToken");\r
         try {\r
             validateAccountType(account.type);\r
             validateAuthTokenType(authTokenType);\r
         } catch (AuthenticatorException e) {\r
-            Log.w(getClass().getName(), "Validating failded in getAuthToken");\r
+            Log.e(TAG, "Failed to validate account type " + account.type + ": "\r
+                    + e.getMessage());\r
+            e.printStackTrace();\r
             return e.getFailureBundle();\r
         }\r
         final AccountManager am = AccountManager.get(mContext);\r
@@ -112,7 +153,8 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
         }\r
 \r
         final Intent intent = new Intent(mContext, AuthenticatorActivity.class);\r
-        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);\r
+        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,\r
+                response);\r
         intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType);\r
         intent.putExtra(KEY_LOGIN_OPTIONS, options);\r
         intent.putExtra(AuthenticatorActivity.PARAM_USERNAME, account.name);\r
@@ -129,7 +171,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
 \r
     @Override\r
     public Bundle hasFeatures(AccountAuthenticatorResponse response,\r
-                              Account account, String[] features) throws NetworkErrorException {\r
+            Account account, String[] features) throws NetworkErrorException {\r
         final Bundle result = new Bundle();\r
         result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);\r
         return result;\r
@@ -137,10 +179,11 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
 \r
     @Override\r
     public Bundle updateCredentials(AccountAuthenticatorResponse response,\r
-                                    Account account, String authTokenType, Bundle options)\r
+            Account account, String authTokenType, Bundle options)\r
             throws NetworkErrorException {\r
         final Intent intent = new Intent(mContext, AuthenticatorActivity.class);\r
-        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);\r
+        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,\r
+                response);\r
         intent.putExtra(KEY_ACCOUNT, account);\r
         intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType);\r
         intent.putExtra(KEY_LOGIN_OPTIONS, options);\r
@@ -152,8 +195,9 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
     }\r
 \r
     @Override\r
-    public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response,\r
-                                           Account account) throws NetworkErrorException {\r
+    public Bundle getAccountRemovalAllowed(\r
+            AccountAuthenticatorResponse response, Account account)\r
+            throws NetworkErrorException {\r
         return super.getAccountRemovalAllowed(response, account);\r
     }\r
 \r
@@ -165,25 +209,20 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
         intent.addFlags(Intent.FLAG_FROM_BACKGROUND);\r
     }\r
 \r
-    private void validateAccountType(String type) throws UnsupportedAccountTypeException {\r
+    private void validateAccountType(String type)\r
+            throws UnsupportedAccountTypeException {\r
         if (!type.equals(ACCOUNT_TYPE)) {\r
             throw new UnsupportedAccountTypeException();\r
         }\r
     }\r
 \r
-    private void validateAuthTokenType(String authTokenType) throws UnsupportedAuthTokenTypeException {\r
+    private void validateAuthTokenType(String authTokenType)\r
+            throws UnsupportedAuthTokenTypeException {\r
         if (!authTokenType.equals(AUTH_TOKEN_TYPE)) {\r
             throw new UnsupportedAuthTokenTypeException();\r
         }\r
     }\r
 \r
-    private void validateRequiredFeatures(String[] requiredFeatures) throws UnsupportedFeaturesException {\r
-    }\r
-\r
-    private void validateCreaditials(String username, String password, String path) throws AccessDeniedException {\r
-\r
-    }\r
-\r
     public static class AuthenticatorException extends Exception {\r
         private static final long serialVersionUID = 1L;\r
         private Bundle mFailureBundle;\r
@@ -191,7 +230,8 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
         public AuthenticatorException(int code, String errorMsg) {\r
             mFailureBundle = new Bundle();\r
             mFailureBundle.putInt(AccountManager.KEY_ERROR_CODE, code);\r
-            mFailureBundle.putString(AccountManager.KEY_ERROR_MESSAGE, errorMsg);\r
+            mFailureBundle\r
+                    .putString(AccountManager.KEY_ERROR_MESSAGE, errorMsg);\r
         }\r
 \r
         public Bundle getFailureBundle() {\r
@@ -199,27 +239,33 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
         }\r
     }\r
 \r
-    public static class UnsupportedAccountTypeException extends AuthenticatorException {\r
+    public static class UnsupportedAccountTypeException extends\r
+            AuthenticatorException {\r
         private static final long serialVersionUID = 1L;\r
 \r
         public UnsupportedAccountTypeException() {\r
-            super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, "Unsupported account type");\r
+            super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,\r
+                    "Unsupported account type");\r
         }\r
     }\r
 \r
-    public static class UnsupportedAuthTokenTypeException extends AuthenticatorException {\r
+    public static class UnsupportedAuthTokenTypeException extends\r
+            AuthenticatorException {\r
         private static final long serialVersionUID = 1L;\r
 \r
         public UnsupportedAuthTokenTypeException() {\r
-            super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, "Unsupported auth token type");\r
+            super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,\r
+                    "Unsupported auth token type");\r
         }\r
     }\r
 \r
-    public static class UnsupportedFeaturesException extends AuthenticatorException {\r
+    public static class UnsupportedFeaturesException extends\r
+            AuthenticatorException {\r
         public static final long serialVersionUID = 1L;\r
 \r
         public UnsupportedFeaturesException() {\r
-            super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, "Unsupported features");\r
+            super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,\r
+                    "Unsupported features");\r
         }\r
     }\r
 \r