X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/c535af9942b8785e8b553d7024753a71c48e4c56..e65985bd33956fd20547e6cf4c6cb6875eb57171:/src/com/owncloud/android/authentication/AuthenticatorActivity.java diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 513db34a..c07b0026 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -18,6 +18,8 @@ package com.owncloud.android.authentication; +import java.util.concurrent.ExecutionException; + import android.accounts.Account; import android.accounts.AccountManager; import android.app.AlertDialog; @@ -29,6 +31,7 @@ import android.content.SharedPreferences; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; @@ -64,6 +67,7 @@ import com.owncloud.android.oc_framework.operations.RemoteOperation; import com.owncloud.android.oc_framework.operations.RemoteOperationResult; import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.oc_framework.operations.remote.ExistenceCheckRemoteOperation; +import com.owncloud.android.oc_framework.operations.remote.GetUserNameRemoteOperation; import com.owncloud.android.ui.dialog.SamlWebViewDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; @@ -102,8 +106,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT"; private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON"; private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED"; - - private static final String KEY_OC_USERNAME_EQUALS = "oc_username="; private static final String AUTH_ON = "on"; private static final String AUTH_OFF = "off"; @@ -794,8 +796,9 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } } } - - + + + private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperation operation, RemoteOperationResult result) { try { dismissDialog(DIALOG_LOGIN_PROGRESS); @@ -1177,7 +1180,11 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken); } else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) { - String username = getUserNameForSamlSso(); + + String username= getUserNameForSaml(); + if (username == null) + return false; + if (!mUsernameInput.getText().toString().equals(username)) { // fail - not a new account, but an existing one; disallow RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME); @@ -1217,8 +1224,10 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList Uri uri = Uri.parse(mHostBaseUrl); String username = mUsernameInput.getText().toString().trim(); if (isSaml) { - username = getUserNameForSamlSso(); - + username = getUserNameForSaml(); + if (username == null) + return false; + } else if (isOAuth) { username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong(); } @@ -1279,20 +1288,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } } - - private String getUserNameForSamlSso() { - if (mAuthToken != null) { - String [] cookies = mAuthToken.split(";"); - for (int i=0; i{ + + @Override + protected String doInBackground(Void... params) { + + GetUserNameRemoteOperation getUserOperation = new GetUserNameRemoteOperation(mHostBaseUrl, mAuthToken); + WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl), getApplicationContext(), true); + RemoteOperationResult result = getUserOperation.execute(client); + + return result.getUserName(); + } + + } + + /** + * Get the user name form OCS-API + * @return username + */ + private String getUserNameForSaml(){ + + GetUserNameTask getUserTask = new GetUserNameTask(); + String username = null; + try { + username = getUserTask.execute().get(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + + return username; + } }