android:onClick="onRefreshClick"\r
android:text="@string/auth_check_server"\r
android:visibility="gone" />\r
- \r
+ <TextView\r
+ android:id="@+id/auth_message"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:layout_gravity="fill_horizontal"\r
+ android:text="@string/auth_expired_basic_auth_toast" \r
+ android:visibility="gone"\r
+ android:layout_marginBottom="10dp"/>\r
<FrameLayout \r
android:id="@+id/hostUrlFrame"\r
android:layout_width="match_parent"\r
android:onClick="onRefreshClick"\r
android:text="@string/auth_check_server"\r
android:visibility="gone" />\r
+ \r
+ <TextView\r
+ android:id="@+id/auth_message"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:layout_gravity="fill_horizontal"\r
+ android:text="@string/auth_expired_basic_auth_toast"\r
+ android:visibility="gone"\r
+ android:layout_marginBottom="10dp" />\r
\r
<FrameLayout \r
android:id="@+id/hostUrlFrame"\r
<string name="auth_not_found">Ruta errónea</string>
<string name="auth_internal">Error interno en el servidor, código %1$d</string>
<string name="auth_wtf_reenter_URL">Estado inesperado; por favor, introduzca la URL del servidor de nuevo</string>
- <string name="auth_expired_oauth_token_toast">Su autorización ha expirado.\nPor favor, autorice de nuevo</string>
+ <string name="auth_expired_oauth_token_toast">Su autorización ha expirado. Por favor, autorice de nuevo</string>
<string name="auth_expired_basic_auth_toast">Por favor, introduzca la contraseña actual.</string>
<string name="crashlog_message">La aplicación finalizó inesperadamente. ¿Desea enviar un reporte de error?</string>
<string name="crashlog_send_report">Enviar reporte</string>
<string name="auth_not_configured_title">Malformed server configuration</string>
<string name="auth_not_configured_message">It seems that your server instance is not correctly configured. Contact your administrator for more details.</string>
<string name="auth_account_not_new">An account for the same user and server already exists in the device</string>
+ <string name="auth_account_not_the_same">The entered user does not match the user of this account</string>
<string name="auth_unknown_error_title">Unknown error occurred!</string>
<string name="auth_unknown_error_message">An unknown error occurred. Please contact support and include logs from your device.</string>
<string name="auth_unknown_host_title">Couldn\'t find host</string>
<string name="auth_not_found">Wrong path given</string>
<string name="auth_internal">Internal server error, code %1$d</string>
<string name="auth_wtf_reenter_URL">Unexpected state; please, enter the server URL again</string>
- <string name="auth_expired_oauth_token_toast">Your authorization expired.\nPlease, authorize again</string>
+ <string name="auth_expired_oauth_token_toast">Your authorization expired. Please, authorize again</string>
<string name="auth_expired_basic_auth_toast">Please, enter the current password</string>
+ <string name="auth_expired_saml_sso_token_toast">Your session expired. Please connect again</string>
<string name="auth_connecting_auth_server">Connecting to authentication server…</string>
<string name="auth_follow_auth_server">Follow instructions above to get authenticated</string>
<string name="auth_unsupported_auth_method">The server does not support this authentication method</string>
\r
package com.owncloud.android.authentication;\r
\r
-import java.net.URLDecoder;\r
-\r
import android.accounts.Account;\r
import android.accounts.AccountManager;\r
import android.app.AlertDialog;\r
import android.widget.EditText;\r
import android.widget.TextView;\r
import android.widget.TextView.OnEditorActionListener;\r
-import android.widget.Toast;\r
\r
import com.actionbarsherlock.app.SherlockDialogFragment;\r
import com.owncloud.android.Log_OC;\r
public static final String EXTRA_ACTION = "ACTION";\r
public static final String EXTRA_ENFORCED_UPDATE = "ENFORCE_UPDATE";\r
\r
+ private static final String KEY_AUTH_MESSAGE_VISIBILITY = "AUTH_MESSAGE_VISIBILITY";\r
+ private static final String KEY_AUTH_MESSAGE_TEXT = "AUTH_MESSAGE_TEXT";\r
private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT";\r
private static final String KEY_OC_VERSION = "OC_VERSION";\r
private static final String KEY_ACCOUNT = "ACCOUNT";\r
private String mHostBaseUrl;\r
private OwnCloudVersion mDiscoveredVersion;\r
\r
- private int mServerStatusText, mServerStatusIcon;\r
+ private String mAuthMessageText;\r
+ private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon;\r
private boolean mServerIsChecked, mServerIsValid, mIsSslConn;\r
private int mAuthStatusText, mAuthStatusIcon; \r
private TextView mAuthStatusLayout;\r
private byte mAction;\r
private Account mAccount;\r
\r
+ private TextView mAuthMessage;\r
+ \r
private EditText mHostUrlInput;\r
private boolean mHostUrlInputEnabled;\r
private View mRefreshButton;\r
\r
/// set view and get references to view elements\r
setContentView(R.layout.account_setup);\r
+ mAuthMessage = (TextView) findViewById(R.id.auth_message);\r
mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);\r
mHostUrlInput.setText(getString(R.string.server_url)); // valid although R.string.server_url is an empty string\r
mUsernameInput = (EditText) findViewById(R.id.account_username);\r
if (savedInstanceState == null) {\r
mResumed = false;\r
/// connection state and info\r
+ mAuthMessageVisibility = View.GONE;\r
mServerStatusText = mServerStatusIcon = 0;\r
mServerIsValid = false;\r
mServerIsChecked = false;\r
}\r
mHostBaseUrl = normalizeUrl(mAccountMgr.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL));\r
mHostUrlInput.setText(mHostBaseUrl);\r
+ String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
+ mUsernameInput.setText(userName);\r
}\r
initAuthorizationMethod(); // checks intent and setup.xml to determine mCurrentAuthorizationMethod\r
mJustCreated = true;\r
} else {\r
mResumed = true;\r
/// connection state and info\r
+ mAuthMessageVisibility = savedInstanceState.getInt(KEY_AUTH_MESSAGE_VISIBILITY);\r
+ mAuthMessageText = savedInstanceState.getString(KEY_AUTH_MESSAGE_TEXT);\r
mServerIsValid = savedInstanceState.getBoolean(KEY_SERVER_VALID);\r
mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED);\r
mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT);\r
\r
}\r
\r
+ if (mAuthMessageVisibility== View.VISIBLE) {\r
+ showAuthMessage(mAuthMessageText);\r
+ }\r
+ else {\r
+ hideAuthMessage();\r
+ }\r
adaptViewAccordingToAuthenticationMethod();\r
showServerStatus();\r
showAuthStatus();\r
super.onSaveInstanceState(outState);\r
\r
/// connection state and info\r
+ outState.putInt(KEY_AUTH_MESSAGE_VISIBILITY, mAuthMessage.getVisibility());\r
+ outState.putString(KEY_AUTH_MESSAGE_TEXT, mAuthMessage.getText().toString());\r
outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText);\r
outState.putInt(KEY_SERVER_STATUS_ICON, mServerStatusIcon);\r
outState.putBoolean(KEY_SERVER_VALID, mServerIsValid);\r
protected void onResume() {\r
super.onResume();\r
if (mAction == ACTION_UPDATE_TOKEN && mJustCreated && getIntent().getBooleanExtra(EXTRA_ENFORCED_UPDATE, false)) {\r
- if (mOAuth2Check.isChecked())\r
- Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show();\r
- else\r
- Toast.makeText(this, R.string.auth_expired_basic_auth_toast, Toast.LENGTH_LONG).show();\r
+ if (AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mAuthTokenType)) {\r
+ //Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show();\r
+ showAuthMessage(getString(R.string.auth_expired_oauth_token_toast));\r
+ } else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mAuthTokenType)) {\r
+ //Toast.makeText(this, R.string.auth_expired_saml_sso_token_toast, Toast.LENGTH_LONG).show();\r
+ showAuthMessage(getString(R.string.auth_expired_saml_sso_token_toast));\r
+ } else {\r
+ //Toast.makeText(this, R.string.auth_expired_basic_auth_toast, Toast.LENGTH_LONG).show();\r
+ showAuthMessage(getString(R.string.auth_expired_basic_auth_toast));\r
+ }\r
}\r
\r
if (mNewCapturedUriFromOAuth2Redirection != null) {\r
} catch (IllegalArgumentException e) {\r
// NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens\r
}\r
- \r
- //if (result.isTemporalRedirection() || result.isIdPRedirection()) {\r
- if (result.isIdPRedirection()) {\r
+
+ //if (result.isTemporalRedirection() && result.isIdPRedirection()) {\r
+ if (result.isIdPRedirection()) {
String url = result.getRedirectedLocation();\r
String targetUrl = mHostBaseUrl + AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType);\r
\r
case ACCOUNT_NOT_NEW:\r
mAuthStatusText = R.string.auth_account_not_new;\r
break;\r
+ case ACCOUNT_NOT_THE_SAME:\r
+ mAuthStatusText = R.string.auth_account_not_the_same;\r
+ break;\r
case UNHANDLED_HTTP_CODE:\r
case UNKNOWN_ERROR:\r
mAuthStatusText = R.string.auth_unknown_error_title;\r
if (result.isSuccess()) {\r
Log_OC.d(TAG, "Successful access - time to save the account");\r
\r
- boolean success = true;\r
+ boolean success = false;\r
if (mAction == ACTION_CREATE) {\r
success = createAccount();\r
\r
} else {\r
- updateToken();\r
+ success = updateToken();\r
}\r
\r
if (success) {\r
* Sets the proper response to get that the Account Authenticator that started this activity saves \r
* a new authorization token for mAccount.\r
*/\r
- private void updateToken() {\r
+ private boolean updateToken() {\r
Bundle response = new Bundle();\r
response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);\r
response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);\r
mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);\r
\r
} else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mAuthTokenType)) {\r
+ String username = getUserNameForSamlSso();\r
+ if (!mUsernameInput.getText().toString().equals(username)) {\r
+ // fail - not a new account, but an existing one; disallow\r
+ RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME); \r
+ updateAuthStatusIconAndText(result);\r
+ showAuthStatus();\r
+ Log_OC.d(TAG, result.getLogMessage());\r
+ \r
+ return false;\r
+ }\r
+ \r
response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);\r
// the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention\r
mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);\r
mAccountMgr.setPassword(mAccount, mPasswordInput.getText().toString());\r
}\r
setAccountAuthenticatorResult(response);\r
+ \r
+ return true;\r
}\r
\r
\r
Log_OC.d(TAG, result.getLogMessage());\r
return false;\r
\r
- \r
} else {\r
\r
if (isOAuth || isSaml) {\r
Bundle bundle = new Bundle();\r
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
ContentResolver.requestSync(mAccount, AccountAuthenticator.AUTHORITY, bundle);\r
+ syncAccount();\r
+// Bundle bundle = new Bundle();\r
+// bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
+// ContentResolver.requestSync(mAccount, AccountAuthenticator.AUTHORITY, bundle);\r
return true;\r
}\r
}\r
\r
if (sessionCookie != null && sessionCookie.length() > 0) {\r
mAuthToken = sessionCookie;\r
- boolean success = true;\r
+ boolean success = false;\r
if (mAction == ACTION_CREATE) {\r
success = createAccount();\r
\r
} else {\r
- updateToken();\r
+ success = updateToken();\r
}\r
if (success) {\r
finish();\r
\r
}\r
\r
+ /** Show auth_message \r
+ * \r
+ * @param message\r
+ */\r
+ private void showAuthMessage(String message) {\r
+ mAuthMessage.setVisibility(View.VISIBLE);\r
+ mAuthMessage.setText(message);\r
+ }\r
+ \r
+ private void hideAuthMessage() {\r
+ mAuthMessage.setVisibility(View.GONE);\r
+ }\r
\r
private void syncAccount(){\r
/// immediately request for the synchronization of the new account\r
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import com.owncloud.android.authentication.AccountAuthenticator;
import com.owncloud.android.authentication.AuthenticatorActivity;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
int contentId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_content : R.string.downloader_download_failed_content;
Notification finalNotification = new Notification(R.drawable.icon, getString(tickerId), System.currentTimeMillis());
finalNotification.flags |= Notification.FLAG_AUTO_CANCEL;
- boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED);
+ boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED ||
+ // (downloadResult.isTemporalRedirection() && downloadResult.isIdPRedirection()
+ (downloadResult.isIdPRedirection()
+ && AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mDownloadClient.getAuthTokenType())));
if (needsToUpdateCredentials) {
// let the user update credentials with one click
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
mUploadClient.exhaustResponse(propfind.getResponseBodyAsStream());
}
- result = new RemoteOperationResult(isMultiStatus, status);
+ result = new RemoteOperationResult(isMultiStatus, status, propfind.getResponseHeaders());
Log_OC.i(TAG, "Update: synchronizing properties for uploaded " + mCurrentUpload.getRemotePath() + ": "
+ result.getLogMessage());
Notification finalNotification = new Notification(R.drawable.icon,
getString(R.string.uploader_upload_failed_ticker), System.currentTimeMillis());
finalNotification.flags |= Notification.FLAG_AUTO_CANCEL;
- if (uploadResult.getCode() == ResultCode.UNAUTHORIZED) {
+ String content = null;
+
+ boolean needsToUpdateCredentials = (uploadResult.getCode() == ResultCode.UNAUTHORIZED ||
+ //(uploadResult.isTemporalRedirection() && uploadResult.isIdPRedirection() &&
+ (uploadResult.isIdPRedirection() &&
+ AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mUploadClient.getAuthTokenType())));
+ if (needsToUpdateCredentials) {
// let the user update credentials with one click
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, upload.getAccount());
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
finalNotification.contentIntent = PendingIntent.getActivity(this, (int)System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT);
+ content = String.format(getString(R.string.uploader_upload_failed_content_single), upload.getFileName());
+ finalNotification.setLatestEventInfo(getApplicationContext(),
+ getString(R.string.uploader_upload_failed_ticker), content, finalNotification.contentIntent);
mUploadClient = null; // grant that future retries on the same account will get the fresh credentials
} else {
// TODO put something smart in the contentIntent below
- finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);
- }
+ // finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);
+ //}
- String content = null;
- if (uploadResult.getCode() == ResultCode.LOCAL_STORAGE_FULL
- || uploadResult.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) {
- // TODO we need a class to provide error messages for the users
- // from a RemoteOperationResult and a RemoteOperation
- content = String.format(getString(R.string.error__upload__local_file_not_copied), upload.getFileName(),
- getString(R.string.app_name));
- } else if (uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED) {
- content = getString(R.string.failed_upload_quota_exceeded_text);
- } else {
- content = String
- .format(getString(R.string.uploader_upload_failed_content_single), upload.getFileName());
- }
+ if (uploadResult.getCode() == ResultCode.LOCAL_STORAGE_FULL
+ || uploadResult.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) {
+ // TODO we need a class to provide error messages for the users
+ // from a RemoteOperationResult and a RemoteOperation
+ content = String.format(getString(R.string.error__upload__local_file_not_copied), upload.getFileName(),
+ getString(R.string.app_name));
+ } else if (uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED) {
+ content = getString(R.string.failed_upload_quota_exceeded_text);
+ } else {
+ content = String
+ .format(getString(R.string.uploader_upload_failed_content_single), upload.getFileName());
+ }
- // we add only for instant-uploads the InstantUploadActivity and the
- // db entry
- Intent detailUploadIntent = null;
- if (upload.isInstant() && InstantUploadActivity.IS_ENABLED) {
- detailUploadIntent = new Intent(this, InstantUploadActivity.class);
- detailUploadIntent.putExtra(FileUploader.KEY_ACCOUNT, upload.getAccount());
- } else {
- detailUploadIntent = new Intent(this, FailedUploadActivity.class);
- detailUploadIntent.putExtra(FailedUploadActivity.MESSAGE, content);
- }
- finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(),
- (int) System.currentTimeMillis(), detailUploadIntent, PendingIntent.FLAG_UPDATE_CURRENT
- | PendingIntent.FLAG_ONE_SHOT);
-
- if (upload.isInstant()) {
- DbHandler db = null;
- try {
- db = new DbHandler(this.getBaseContext());
- String message = uploadResult.getLogMessage() + " errorCode: " + uploadResult.getCode();
- Log_OC.e(TAG, message + " Http-Code: " + uploadResult.getHttpCode());
- if (uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED) {
- message = getString(R.string.failed_upload_quota_exceeded_text);
- }
- if (db.updateFileState(upload.getOriginalStoragePath(), DbHandler.UPLOAD_STATUS_UPLOAD_FAILED,
- message) == 0) {
- db.putFileForLater(upload.getOriginalStoragePath(), upload.getAccount().name, message);
- }
- } finally {
- if (db != null) {
- db.close();
+ // we add only for instant-uploads the InstantUploadActivity and the
+ // db entry
+ Intent detailUploadIntent = null;
+ if (upload.isInstant() && InstantUploadActivity.IS_ENABLED) {
+ detailUploadIntent = new Intent(this, InstantUploadActivity.class);
+ detailUploadIntent.putExtra(FileUploader.KEY_ACCOUNT, upload.getAccount());
+ } else {
+ detailUploadIntent = new Intent(this, FailedUploadActivity.class);
+ detailUploadIntent.putExtra(FailedUploadActivity.MESSAGE, content);
+ }
+ finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(),
+ (int) System.currentTimeMillis(), detailUploadIntent, PendingIntent.FLAG_UPDATE_CURRENT
+ | PendingIntent.FLAG_ONE_SHOT);
+
+ if (upload.isInstant()) {
+ DbHandler db = null;
+ try {
+ db = new DbHandler(this.getBaseContext());
+ String message = uploadResult.getLogMessage() + " errorCode: " + uploadResult.getCode();
+ Log_OC.e(TAG, message + " Http-Code: " + uploadResult.getHttpCode());
+ if (uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED) {
+ message = getString(R.string.failed_upload_quota_exceeded_text);
+ }
+ if (db.updateFileState(upload.getOriginalStoragePath(), DbHandler.UPLOAD_STATUS_UPLOAD_FAILED,
+ message) == 0) {
+ db.putFileForLater(upload.getOriginalStoragePath(), upload.getAccount().name, message);
+ }
+ } finally {
+ if (db != null) {
+ db.close();
+ }
}
}
}
finalNotification.setLatestEventInfo(getApplicationContext(),
getString(R.string.uploader_upload_failed_ticker), content, finalNotification.contentIntent);
-
+
mNotificationManager.notify(R.string.uploader_upload_failed_ticker, finalNotification);
}
import javax.net.ssl.TrustManager;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
import org.apache.http.conn.ssl.X509HostnameVerifier;
//Log_OC.d(TAG, "Creating WebdavClient associated to " + account.name);
Uri uri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account));
- WebdavClient client = createOwnCloudClient(uri, appContext, true);
AccountManager am = AccountManager.get(appContext);
- if (am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null) { // TODO avoid a call to getUserData here
+ boolean isOauth2 = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null; // TODO avoid calling to getUserData here
+ boolean isSamlSso = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO) != null;
+ WebdavClient client = createOwnCloudClient(uri, appContext, !isSamlSso);
+ if (isOauth2) {
String accessToken = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN, false);
client.setBearerCredentials(accessToken); // TODO not assume that the access token is a bearer token
- } else if (am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO) != null) { // TODO avoid a call to getUserData here
+ } else if (isSamlSso) { // TODO avoid a call to getUserData here
String accessToken = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE, false);
client.setSsoSessionCookie(accessToken);
public static WebdavClient createOwnCloudClient (Account account, Context appContext, Activity currentActivity) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {
Uri uri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account));
- WebdavClient client = createOwnCloudClient(uri, appContext, true);
AccountManager am = AccountManager.get(appContext);
- if (am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null) { // TODO avoid a call to getUserData here
+ boolean isOauth2 = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null; // TODO avoid calling to getUserData here
+ boolean isSamlSso = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO) != null;
+ WebdavClient client = createOwnCloudClient(uri, appContext, !isSamlSso);
+
+ if (isOauth2) { // TODO avoid a call to getUserData here
AccountManagerFuture<Bundle> future = am.getAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN, null, currentActivity, null, null);
Bundle result = future.getResult();
String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
if (accessToken == null) throw new AuthenticatorException("WTF!");
client.setBearerCredentials(accessToken); // TODO not assume that the access token is a bearer token
- } else if (am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO) != null) { // TODO avoid a call to getUserData here
+ } else if (isSamlSso) { // TODO avoid a call to getUserData here
AccountManagerFuture<Bundle> future = am.getAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE, null, currentActivity, null, null);
Bundle result = future.getResult();
String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
String uriPrefix = client.getBaseUri() + WebdavUtils.encodePath(getRemotePath()) + "-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ;
long chunkCount = (long) Math.ceil((double)file.length() / CHUNK_SIZE);
for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) {
+ if (mPutMethod != null) {
+ mPutMethod.releaseConnection(); // let the connection available for other methods
+ }
mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex);
mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER);
((ChunkFromFileChannelRequestEntity)mEntity).setOffset(offset);
mStorageManager.saveFile(newDir);
}
- result = new RemoteOperationResult(mkcol.succeeded(), status);
+ result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
client.exhaustResponse(mkcol.getResponseBodyAsStream());
private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
private long mModificationTimestamp = 0;
+ private GetMethod mGet;
public DownloadFileOperation(Account account, OCFile file) {
if (!moved)
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_MOVED);
else
- result = new RemoteOperationResult(isSuccess(status), status);
+ result = new RemoteOperationResult(isSuccess(status), status, (mGet != null ? mGet.getResponseHeaders() : null));
Log_OC.i(TAG, "Download of " + mFile.getRemotePath() + " to " + getSavePath() + ": " + result.getLogMessage());
} catch (Exception e) {
protected int downloadFile(WebdavClient client, File targetFile) throws HttpException, IOException, OperationCancelledException {
int status = -1;
boolean savedFile = false;
- GetMethod get = new GetMethod(client.getBaseUri() + WebdavUtils.encodePath(mFile.getRemotePath()));
+ mGet = new GetMethod(client.getBaseUri() + WebdavUtils.encodePath(mFile.getRemotePath()));
Iterator<OnDatatransferProgressListener> it = null;
FileOutputStream fos = null;
try {
- status = client.executeMethod(get);
+ status = client.executeMethod(mGet);
if (isSuccess(status)) {
targetFile.createNewFile();
- BufferedInputStream bis = new BufferedInputStream(get.getResponseBodyAsStream());
+ BufferedInputStream bis = new BufferedInputStream(mGet.getResponseBodyAsStream());
fos = new FileOutputStream(targetFile);
long transferred = 0;
while ((readResult = bis.read(bytes)) != -1) {
synchronized(mCancellationRequested) {
if (mCancellationRequested.get()) {
- get.abort();
+ mGet.abort();
throw new OperationCancelledException();
}
}
}
}
savedFile = true;
- Header modificationTime = get.getResponseHeader("Last-Modified");
+ Header modificationTime = mGet.getResponseHeader("Last-Modified");
if (modificationTime != null) {
Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue());
mModificationTimestamp = (d != null) ? d.getTime() : 0;
}
} else {
- client.exhaustResponse(get.getResponseBodyAsStream());
+ client.exhaustResponse(mGet.getResponseBodyAsStream());
}
} finally {
if (!savedFile && targetFile.exists()) {
targetFile.delete();
}
- get.releaseConnection(); // let the connection available for other methods
+ mGet.releaseConnection(); // let the connection available for other methods
}
return status;
}
result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR);
} else {
- result = new RemoteOperationResult(true, status);
+ result = new RemoteOperationResult(true, status, postMethod.getResponseHeaders());
}
} else {
client.exhaustResponse(postMethod.getResponseBodyAsStream());
- result = new RemoteOperationResult(false, status);
+ result = new RemoteOperationResult(false, status, postMethod.getResponseHeaders());
}
}
}
} else {
- mLatestResult = new RemoteOperationResult(false, status);
+ mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders());
}
} catch (JSONException e) {
result = run(mClient);
repeat = false;
- if (mCallerActivity != null && mAccount != null && mContext != null && !result.isSuccess() && result.getCode() == ResultCode.UNAUTHORIZED) {
- /// fail due to lack of authorization in an operation performed in foreground
- AccountManager am = AccountManager.get(mContext);
+ if (mCallerActivity != null && mAccount != null && mContext != null && !result.isSuccess() &&
+// (result.getCode() == ResultCode.UNAUTHORIZED || (result.isTemporalRedirection() && result.isIdPRedirection()))) {
+ (result.getCode() == ResultCode.UNAUTHORIZED || result.isIdPRedirection())) {
+ /// possible fail due to lack of authorization in an operation performed in foreground
Credentials cred = mClient.getCredentials();
- if (cred instanceof BearerCredentials) {
- am.invalidateAuthToken(AccountAuthenticator.ACCOUNT_TYPE, ((BearerCredentials)cred).getAccessToken());
- } else {
- am.clearPassword(mAccount);
+ String ssoSessionCookie = mClient.getSsoSessionCookie();
+ if (cred != null || ssoSessionCookie != null) {
+ /// confirmed : unauthorized operation
+ AccountManager am = AccountManager.get(mContext);
+ boolean bearerAuthorization = (cred != null && cred instanceof BearerCredentials);
+ boolean samlBasedSsoAuthorization = (cred == null && ssoSessionCookie != null);
+ if (bearerAuthorization) {
+ am.invalidateAuthToken(AccountAuthenticator.ACCOUNT_TYPE, ((BearerCredentials)cred).getAccessToken());
+ } else if (samlBasedSsoAuthorization ) {
+ am.invalidateAuthToken(AccountAuthenticator.ACCOUNT_TYPE, ssoSessionCookie);
+ } else {
+ am.clearPassword(mAccount);
+ }
+ mClient = null;
+ repeat = true; // when repeated, the creation of a new OwnCloudClient after erasing the saved credentials will trigger the login activity
+ result = null;
}
- mClient = null;
- repeat = true; // when repeated, the creation of a new OwnCloudClient after erasing the saved credentials will trigger the login activity
- result = null;
}
} while (repeat);
public class RemoteOperationResult implements Serializable {
/** Generated - should be refreshed every time the class changes!! */
- private static final long serialVersionUID = 3267227833178885664L;
+ private static final long serialVersionUID = -4415103901492836870L;
private static final String TAG = "RemoteOperationResult";
QUOTA_EXCEEDED,
ACCOUNT_NOT_FOUND,
ACCOUNT_EXCEPTION,
- ACCOUNT_NOT_NEW
+ ACCOUNT_NOT_NEW,
+ ACCOUNT_NOT_THE_SAME
}
private boolean mSuccess = false;
mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || code == ResultCode.OK_NO_SSL);
}
- public RemoteOperationResult(boolean success, int httpCode) {
+ private RemoteOperationResult(boolean success, int httpCode) {
mSuccess = success;
mHttpCode = httpCode;
} else if (mCode == ResultCode.ACCOUNT_NOT_NEW) {
return "Account already existing when creating a new one";
+
+ } else if (mCode == ResultCode.ACCOUNT_NOT_THE_SAME) {
+ return "Authenticated with a different account than the one updating";
}
return "Operation finished with HTTP status code " + mHttpCode + " (" + (isSuccess() ? "success" : "fail") + ")";
}
}
delete.getResponseBodyAsString(); // exhaust the response, although not interesting
- result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), status);
+ result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), status, delete.getResponseHeaders());
Log_OC.i(TAG, "Remove " + mFileToRemove.getRemotePath() + ": " + result.getLogMessage());
} catch (Exception e) {
}
move.getResponseBodyAsString(); // exhaust response, although not interesting
- result = new RemoteOperationResult(move.succeeded(), status);
+ result = new RemoteOperationResult(move.succeeded(), status, move.getResponseHeaders());
Log_OC.i(TAG, "Rename " + mFile.getRemotePath() + " to " + mNewRemotePath + ": " + result.getLogMessage());
} catch (Exception e) {
} else {
client.exhaustResponse(propfind.getResponseBodyAsStream());
- result = new RemoteOperationResult(false, status);
+ result = new RemoteOperationResult(false, status, propfind.getResponseHeaders());
}
}
result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job
} else {
- result = new RemoteOperationResult(true, status);
- Header hCookie = query.getResponseHeader("Cookie");
- if (hCookie != null) {
- Log_OC.e(TAG, "PROPFIND cookie: " + hCookie.getValue());
- } else {
- Log_OC.e(TAG, "PROPFIND NO COOKIE");
- }
+ result = new RemoteOperationResult(true, status, query.getResponseHeaders());
}
} else {
- result = new RemoteOperationResult(false, status);
+ result = new RemoteOperationResult(false, status, query.getResponseHeaders());
}
int status = client.executeMethod(get);
if (status != HttpStatus.SC_OK) {
client.exhaustResponse(get.getResponseBodyAsStream());
- result = new RemoteOperationResult(false, status);
+ result = new RemoteOperationResult(false, status, get.getResponseHeaders());
} else {
String response = get.getResponseBodyAsString();
}
}
- result = new RemoteOperationResult(isSuccess(status), status);
+ result = new RemoteOperationResult(isSuccess(status), status, (mPutMethod != null ? mPutMethod.getResponseHeaders() : null));
} catch (Exception e) {
// TODO something cleaner with cancellations
import com.owncloud.android.Log_OC;
import com.owncloud.android.R;
+import com.owncloud.android.authentication.AccountAuthenticator;
import com.owncloud.android.authentication.AuthenticatorActivity;
import com.owncloud.android.datamodel.DataStorageManager;
import com.owncloud.android.datamodel.FileDataStorageManager;
sendStickyBroadcast(true, remotePath, null);
} else {
- if (result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED) {
+ if (result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED ||
+ // (result.isTemporalRedirection() && result.isIdPRedirection() &&
+ ( result.isIdPRedirection() &&
+ AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(getClient().getAuthTokenType()))) {
mSyncResult.stats.numAuthExceptions++;
} else if (result.getException() instanceof DavException) {
private void notifyFailedSynchronization() {
Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_fail_ticker), System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
- boolean needsToUpdateCredentials = (mLastFailedResult != null && mLastFailedResult.getCode() == ResultCode.UNAUTHORIZED);
+ boolean needsToUpdateCredentials = (mLastFailedResult != null &&
+ ( mLastFailedResult.getCode() == ResultCode.UNAUTHORIZED ||
+ // (mLastFailedResult.isTemporalRedirection() && mLastFailedResult.isIdPRedirection() &&
+ ( mLastFailedResult.isIdPRedirection() &&
+ AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(getClient().getAuthTokenType()))
+ )
+ );
// TODO put something smart in the contentIntent below for all the possible errors
notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);
if (needsToUpdateCredentials) {
super.onCreate(savedInstanceState);
CookieSyncManager.createInstance(getActivity());
-
+
if (savedInstanceState == null) {
mInitialUrl = getArguments().getString(ARG_INITIAL_URL);
mTargetUrl = getArguments().getString(ARG_TARGET_URL);
import com.owncloud.android.Log_OC;
+import com.owncloud.android.authentication.AccountAuthenticator;
import com.owncloud.android.network.BearerAuthScheme;
import com.owncloud.android.network.BearerCredentials;
private Credentials mCredentials;
private boolean mFollowRedirects;
private String mSsoSessionCookie;
+ private String mAuthTokenType;
final private static String TAG = "WebdavClient";
public static final String USER_AGENT = "Android-ownCloud";
getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
mFollowRedirects = true;
mSsoSessionCookie = null;
+ mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD;
}
public void setBearerCredentials(String accessToken) {
mCredentials = new BearerCredentials(accessToken);
getState().setCredentials(AuthScope.ANY, mCredentials);
mSsoSessionCookie = null;
+ mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN;
}
public void setBasicCredentials(String username, String password) {
mCredentials = new UsernamePasswordCredentials(username, password);
getState().setCredentials(AuthScope.ANY, mCredentials);
mSsoSessionCookie = null;
+ mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD;
}
public void setSsoSessionCookie(String accessToken) {
getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
mSsoSessionCookie = accessToken;
mCredentials = null;
+ mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE;
}
public final Credentials getCredentials() {\r
return mCredentials;\r
}
+
+ public final String getSsoSessionCookie() {
+ return mSsoSessionCookie;
+ }
public void setFollowRedirects(boolean followRedirects) {
mFollowRedirects = followRedirects;
}
+ public String getAuthTokenType() {
+ return mAuthTokenType;
+ }
+
}