X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/dc8c32fb3f7033d6fdfa7e1b64eaa77884da678a..890bf7fa51135aa24e07ab8d02c002b22a66716a:/src/eu/alefzero/owncloud/authenticator/AccountAuthenticator.java diff --git a/src/eu/alefzero/owncloud/authenticator/AccountAuthenticator.java b/src/eu/alefzero/owncloud/authenticator/AccountAuthenticator.java index b688a2d2..be0b8e00 100644 --- a/src/eu/alefzero/owncloud/authenticator/AccountAuthenticator.java +++ b/src/eu/alefzero/owncloud/authenticator/AccountAuthenticator.java @@ -1,3 +1,21 @@ +/* ownCloud Android client application + * Copyright (C) 2012 Bartek Przybylski + * + * 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 . + * + */ + package eu.alefzero.owncloud.authenticator; import eu.alefzero.owncloud.ui.activity.AuthenticatorActivity; @@ -8,11 +26,10 @@ import android.os.Bundle; import android.util.Log; public class AccountAuthenticator extends AbstractAccountAuthenticator { - public static final String OPTIONS_USERNAME = "username"; - public static final String OPTIONS_PASSWORD = "password"; - public static final String OPTIONS_FILE_LIST_SYNC_ENABLED = "filelist"; - public static final String OPTIONS_PINNED_FILE_SYNC_ENABLED = "pinned"; - + /** + * Is used by android system to assign accounts to authenticators. Should be + * used by application and all extensions. + */ public static final String ACCOUNT_TYPE = "owncloud"; public static final String AUTH_TOKEN_TYPE = "org.owncloud"; @@ -20,9 +37,27 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { public static final String KEY_REQUIRED_FEATURES = "requiredFeatures"; public static final String KEY_LOGIN_OPTIONS = "loginOptions"; public static final String KEY_ACCOUNT = "account"; + /** + * Value under this key should handle path to webdav php script. Will be + * removed and usage should be replaced by combining + * {@link eu.alefzero.owncloud.authenticator.KEY_OC_BASE_URL} and + * {@link eu.alefzero.owncloud.utils.OwnCloudVersion} + * + * @deprecated + */ public static final String KEY_OC_URL = "oc_url"; - public static final String KEY_CONTACT_URL = "oc_contact_url"; + /** + * Version should be 3 numbers separated by dot so it can be parsed by + * {@link eu.alefzero.owncloud.utils.OwnCloudVersion} + */ + public static final String KEY_OC_VERSION = "oc_version"; + /** + * Base url should point to owncloud installation without trailing / ie: + * http://server/path or https://owncloud.server + */ + public static final String KEY_OC_BASE_URL = "oc_base_url"; + private static final String TAG = "AccountAuthenticator"; private Context mContext; public AccountAuthenticator(Context context) { @@ -35,26 +70,27 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { */ @Override public Bundle addAccount(AccountAuthenticatorResponse response, - String accountType, String authTokenType, String[] requiredFeatures, - Bundle options) throws NetworkErrorException { - Log.i(getClass().getName(), "Adding account with type " + accountType + - " and auth token " + authTokenType); + String accountType, String authTokenType, + String[] requiredFeatures, Bundle options) + throws NetworkErrorException { + Log.i(TAG, "Adding account with type " + accountType + + " and auth token " + authTokenType); try { validateAccountType(accountType); - //validateAuthTokenType(authTokenType); - validateRequiredFeatures(requiredFeatures); } catch (AuthenticatorException e) { + Log.e(TAG, "Failed to validate account type " + accountType + ": " + + e.getMessage()); e.printStackTrace(); return e.getFailureBundle(); } final Intent intent = new Intent(mContext, AuthenticatorActivity.class); - intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); + intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, + response); intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType); intent.putExtra(KEY_REQUIRED_FEATURES, requiredFeatures); intent.putExtra(KEY_LOGIN_OPTIONS, options); setIntentFlags(intent); - Log.i(getClass().getName(), intent.toString()); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; @@ -65,14 +101,18 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { */ @Override public Bundle confirmCredentials(AccountAuthenticatorResponse response, - Account account, Bundle options) throws NetworkErrorException { + Account account, Bundle options) throws NetworkErrorException { try { validateAccountType(account.type); } catch (AuthenticatorException e) { + Log.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(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, + response); intent.putExtra(KEY_ACCOUNT, account); intent.putExtra(KEY_LOGIN_OPTIONS, options); @@ -85,20 +125,21 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { @Override public Bundle editProperties(AccountAuthenticatorResponse response, - String accountType) { - throw new UnsupportedOperationException(); + String accountType) { + return null; } @Override public Bundle getAuthToken(AccountAuthenticatorResponse response, - Account account, String authTokenType, Bundle options) + Account account, String authTokenType, Bundle options) throws NetworkErrorException { - Log.i(getClass().getName(), "Getting authToken"); try { validateAccountType(account.type); validateAuthTokenType(authTokenType); } catch (AuthenticatorException e) { - Log.w(getClass().getName(), "Validating failded in getAuthToken"); + Log.e(TAG, "Failed to validate account type " + account.type + ": " + + e.getMessage()); + e.printStackTrace(); return e.getFailureBundle(); } final AccountManager am = AccountManager.get(mContext); @@ -112,7 +153,8 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { } final Intent intent = new Intent(mContext, AuthenticatorActivity.class); - intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); + intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, + response); intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType); intent.putExtra(KEY_LOGIN_OPTIONS, options); intent.putExtra(AuthenticatorActivity.PARAM_USERNAME, account.name); @@ -129,7 +171,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { @Override public Bundle hasFeatures(AccountAuthenticatorResponse response, - Account account, String[] features) throws NetworkErrorException { + Account account, String[] features) throws NetworkErrorException { final Bundle result = new Bundle(); result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false); return result; @@ -137,10 +179,11 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { @Override public Bundle updateCredentials(AccountAuthenticatorResponse response, - Account account, String authTokenType, Bundle options) + Account account, String authTokenType, Bundle options) throws NetworkErrorException { final Intent intent = new Intent(mContext, AuthenticatorActivity.class); - intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); + intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, + response); intent.putExtra(KEY_ACCOUNT, account); intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType); intent.putExtra(KEY_LOGIN_OPTIONS, options); @@ -152,8 +195,9 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { } @Override - public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, - Account account) throws NetworkErrorException { + public Bundle getAccountRemovalAllowed( + AccountAuthenticatorResponse response, Account account) + throws NetworkErrorException { return super.getAccountRemovalAllowed(response, account); } @@ -165,26 +209,20 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { intent.addFlags(Intent.FLAG_FROM_BACKGROUND); } - private void validateAccountType(String type) throws UnsupportedAccountTypeException { + private void validateAccountType(String type) + throws UnsupportedAccountTypeException { if (!type.equals(ACCOUNT_TYPE)) { throw new UnsupportedAccountTypeException(); } } - private void validateAuthTokenType(String authTokenType) throws UnsupportedAuthTokenTypeException { + private void validateAuthTokenType(String authTokenType) + throws UnsupportedAuthTokenTypeException { if (!authTokenType.equals(AUTH_TOKEN_TYPE)) { throw new UnsupportedAuthTokenTypeException(); } } - private void validateRequiredFeatures(String[] requiredFeatures) throws UnsupportedFeaturesException { - // TODO - } - - private void validateCreaditials(String username, String password, String path) throws AccessDeniedException { - - } - public static class AuthenticatorException extends Exception { private static final long serialVersionUID = 1L; private Bundle mFailureBundle; @@ -192,7 +230,8 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { public AuthenticatorException(int code, String errorMsg) { mFailureBundle = new Bundle(); mFailureBundle.putInt(AccountManager.KEY_ERROR_CODE, code); - mFailureBundle.putString(AccountManager.KEY_ERROR_MESSAGE, errorMsg); + mFailureBundle + .putString(AccountManager.KEY_ERROR_MESSAGE, errorMsg); } public Bundle getFailureBundle() { @@ -200,27 +239,33 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { } } - public static class UnsupportedAccountTypeException extends AuthenticatorException { + public static class UnsupportedAccountTypeException extends + AuthenticatorException { private static final long serialVersionUID = 1L; public UnsupportedAccountTypeException() { - super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, "Unsupported account type"); + super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, + "Unsupported account type"); } } - public static class UnsupportedAuthTokenTypeException extends AuthenticatorException { + public static class UnsupportedAuthTokenTypeException extends + AuthenticatorException { private static final long serialVersionUID = 1L; public UnsupportedAuthTokenTypeException() { - super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, "Unsupported auth token type"); + super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, + "Unsupported auth token type"); } } - public static class UnsupportedFeaturesException extends AuthenticatorException { + public static class UnsupportedFeaturesException extends + AuthenticatorException { public static final long serialVersionUID = 1L; public UnsupportedFeaturesException() { - super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, "Unsupported features"); + super(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, + "Unsupported features"); } }