From: David A. Velasco Date: Mon, 12 Aug 2013 11:21:01 +0000 (+0200) Subject: Merge branch 'saml_based_federated_single_sign_on' into saml_based_federated_single_s... X-Git-Tag: oc-android-1.4.6~17^2~24 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/830bb7c85303e8725203d083940e4bfc568a405f?ds=inline;hp=-c Merge branch 'saml_based_federated_single_sign_on' into saml_based_federated_single_sign_on_expired --- 830bb7c85303e8725203d083940e4bfc568a405f diff --combined src/com/owncloud/android/authentication/AuthenticatorActivity.java index 0f7328ae,0e8ba48c..a21205ae --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@@ -229,12 -229,8 +229,11 @@@ implements OnRemoteOperationListener, } mHostBaseUrl = normalizeUrl(mAccountMgr.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL)); mHostUrlInput.setText(mHostBaseUrl); + String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@')); + mUsernameInput.setText(userName); + mAccountNameInput.setText(userName); } initAuthorizationMethod(); // checks intent and setup.xml to determine mCurrentAuthorizationMethod - mOAuth2Check.setChecked(mCurrentAuthTokenType == AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN); mJustCreated = true; if (mAction == ACTION_UPDATE_TOKEN || !mHostUrlInputEnabled) { @@@ -266,6 -262,9 +265,9 @@@ mCurrentAuthTokenType = savedInstanceState.getString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE); if (mCurrentAuthTokenType == null) { mCurrentAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD; + + } else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) { + restoreWebView(savedInstanceState); } // check if server check was interrupted by a configuration change @@@ -290,15 -289,13 +292,15 @@@ mUsernameInput.setEnabled(false); mUsernameInput.setFocusable(false); mOAuth2Check.setVisibility(View.GONE); + mAccountNameInput.setEnabled(false); + mAccountNameInput.setFocusable(false); } //if (mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled) showRefreshButton(); if (mServerIsChecked && !mServerIsValid && refreshButtonEnabled) showRefreshButton(); mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes - if (mCurrentAuthTokenType == AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE || + if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType) || !AUTH_OPTIONAL.equals(getString(R.string.auth_method_oauth2))) { mOAuth2Check.setVisibility(View.GONE); } @@@ -342,7 -339,7 +344,7 @@@ private void initWebView() { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); - //cookieManager.removeSessionCookie(); + cookieManager.removeAllCookie(); mWebViewClient = new SsoWebViewClient(mHandler, this); mSsoWebView.setWebViewClient(mWebViewClient); @@@ -354,6 -351,25 +356,25 @@@ webSettings.setUserAgentString(WebdavClient.USER_AGENT); } + @SuppressLint("SetJavaScriptEnabled") + private void restoreWebView(Bundle savedInstanceState) { + mSsoWebView.restoreState(savedInstanceState); + + CookieManager cookieManager = CookieManager.getInstance(); + Log_OC.e(TAG, "Accept Cookie: " + cookieManager.acceptCookie()); + + mWebViewClient = new SsoWebViewClient(mHandler, this); + mSsoWebView.setWebViewClient(mWebViewClient); + mWebViewClient.setTargetUrl(mHostBaseUrl + AccountUtils.getWebdavPath(mDiscoveredVersion, mCurrentAuthTokenType)); + + WebSettings webSettings = mSsoWebView.getSettings(); + webSettings.setJavaScriptEnabled(true); // at least this one is not being kept by WebView#restoreState + webSettings.setBuiltInZoomControls(true); + webSettings.setLoadWithOverviewMode(false); + webSettings.setSavePassword(false); + webSettings.setUserAgentString(WebdavClient.USER_AGENT); + } + private void initAuthorizationMethod() { boolean oAuthRequired = false; boolean samlWebSsoRequired = false; @@@ -383,6 -399,16 +404,16 @@@ } } + if (mAccount != null) { + String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@')); + mUsernameInput.setText(userName); + } + + if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) { + initWebView(); + } + mOAuth2Check.setChecked(AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mCurrentAuthTokenType)); + } /** @@@ -419,6 -445,9 +450,9 @@@ outState.putParcelable(KEY_ACCOUNT, mAccount); } outState.putString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE, mCurrentAuthTokenType); + if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) { + mSsoWebView.saveState(outState); + } // refresh button enabled outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE)); @@@ -451,15 -480,10 +485,15 @@@ protected void onResume() { super.onResume(); if (mAction == ACTION_UPDATE_TOKEN && mJustCreated && getIntent().getBooleanExtra(EXTRA_ENFORCED_UPDATE, false)) { - if (mOAuth2Check.isChecked()) + if (AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mCurrentAuthTokenType)) { Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show(); - else + + } else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) { + Toast.makeText(this, R.string.auth_expired_saml_sso_token_toast, Toast.LENGTH_LONG).show(); + + } else { Toast.makeText(this, R.string.auth_expired_basic_auth_toast, Toast.LENGTH_LONG).show(); + } } if (mNewCapturedUriFromOAuth2Redirection != null) { @@@ -1424,7 -1448,6 +1458,6 @@@ mPasswordInput.setVisibility(View.GONE); mAccountNameInput.setVisibility(View.VISIBLE); mSsoWebView.setVisibility(View.VISIBLE); - initWebView(); } else { // basic HTTP authorization