X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/23a1ea68e0362d8169a15c49e470fb3137692780..2d36f5a564a7b2ad43e1d67ffb37eb207adbb65a:/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 a21205ae..a768821a 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -18,24 +18,8 @@ package com.owncloud.android.authentication; -import com.owncloud.android.Log_OC; -import com.owncloud.android.ui.dialog.SslValidatorDialog; -import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; -import com.owncloud.android.utils.OwnCloudVersion; -import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener; -import com.owncloud.android.network.OwnCloudClientUtils; -import com.owncloud.android.operations.OwnCloudServerCheckOperation; -import com.owncloud.android.operations.ExistenceCheckOperation; -import com.owncloud.android.operations.OAuth2GetAccessToken; -import com.owncloud.android.operations.OnRemoteOperationListener; -import com.owncloud.android.operations.RemoteOperation; -import com.owncloud.android.operations.RemoteOperationResult; -import com.owncloud.android.operations.RemoteOperationResult.ResultCode; - import android.accounts.Account; -import android.accounts.AccountAuthenticatorActivity; import android.accounts.AccountManager; -import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; @@ -59,17 +43,28 @@ import android.view.View.OnFocusChangeListener; import android.view.View.OnTouchListener; import android.view.Window; import android.view.inputmethod.EditorInfo; -import android.webkit.CookieManager; -import android.webkit.WebSettings; -import android.webkit.WebView; +import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; -import android.widget.Button; import android.widget.TextView; -import android.widget.Toast; import android.widget.TextView.OnEditorActionListener; +import android.widget.Toast; +import com.owncloud.android.Log_OC; import com.owncloud.android.R; +import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener; +import com.owncloud.android.network.OwnCloudClientUtils; +import com.owncloud.android.operations.ExistenceCheckOperation; +import com.owncloud.android.operations.OAuth2GetAccessToken; +import com.owncloud.android.operations.OnRemoteOperationListener; +import com.owncloud.android.operations.OwnCloudServerCheckOperation; +import com.owncloud.android.operations.RemoteOperation; +import com.owncloud.android.operations.RemoteOperationResult; +import com.owncloud.android.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.ui.dialog.SamlWebViewDialog; +import com.owncloud.android.ui.dialog.SslValidatorDialog; +import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; +import com.owncloud.android.utils.OwnCloudVersion; import eu.alefzero.webdav.WebdavClient; @@ -80,7 +75,7 @@ import eu.alefzero.webdav.WebdavClient; * @author David A. Velasco */ public class AuthenticatorActivity extends AccountAuthenticatorActivity -implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener, OnEditorActionListener, SsoWebViewClientListener { +implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener, OnEditorActionListener, SsoWebViewClientListener{ private static final String TAG = AuthenticatorActivity.class.getSimpleName(); @@ -90,6 +85,8 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList public static final String EXTRA_ACTION = "ACTION"; public static final String EXTRA_ENFORCED_UPDATE = "ENFORCE_UPDATE"; + private static final String KEY_AUTH_MESSAGE_VISIBILITY = "AUTH_MESSAGE_VISIBILITY"; + private static final String KEY_AUTH_MESSAGE_TEXT = "AUTH_MESSAGE_TEXT"; private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT"; private static final String KEY_OC_VERSION = "OC_VERSION"; private static final String KEY_ACCOUNT = "ACCOUNT"; @@ -116,10 +113,13 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList public static final byte ACTION_CREATE = 0; public static final byte ACTION_UPDATE_TOKEN = 1; + private static final String TAG_SAML_DIALOG = "samlWebViewDialog"; + private String mHostBaseUrl; private OwnCloudVersion mDiscoveredVersion; - private int mServerStatusText, mServerStatusIcon; + private String mAuthMessageText; + private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon; private boolean mServerIsChecked, mServerIsValid, mIsSslConn; private int mAuthStatusText, mAuthStatusIcon; private TextView mAuthStatusLayout; @@ -137,6 +137,8 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList private byte mAction; private Account mAccount; + private TextView mAuthMessage; + private EditText mHostUrlInput; private boolean mHostUrlInputEnabled; private View mRefreshButton; @@ -152,8 +154,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList private TextView mOAuthTokenEndpointText; private TextView mAccountNameInput; - private WebView mSsoWebView; - private SsoWebViewClient mWebViewClient; + private SamlWebViewDialog mSamlDialog; private View mOkButton; @@ -172,6 +173,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList /// set view and get references to view elements setContentView(R.layout.account_setup); + mAuthMessage = (TextView) findViewById(R.id.auth_message); mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput); mHostUrlInput.setText(getString(R.string.server_url)); // valid although R.string.server_url is an empty string mUsernameInput = (EditText) findViewById(R.id.account_username); @@ -180,7 +182,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mOAuthTokenEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_2); mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check); mAccountNameInput = (EditText) findViewById(R.id.account_name); - mSsoWebView = (WebView) findViewById(R.id.web_sso_view); mOkButton = findViewById(R.id.buttonOK); mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text); @@ -214,6 +215,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList if (savedInstanceState == null) { /// connection state and info + mAuthMessageVisibility = View.GONE; mServerStatusText = mServerStatusIcon = 0; mServerIsValid = false; mServerIsChecked = false; @@ -242,6 +244,8 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } else { /// connection state and info + mAuthMessageVisibility = savedInstanceState.getInt(KEY_AUTH_MESSAGE_VISIBILITY); + mAuthMessageText = savedInstanceState.getString(KEY_AUTH_MESSAGE_TEXT); mServerIsValid = savedInstanceState.getBoolean(KEY_SERVER_VALID); mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED); mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT); @@ -266,8 +270,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList 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 @@ -281,6 +283,12 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } + if (mAuthMessageVisibility== View.VISIBLE) { + showAuthMessage(mAuthMessageText); + } + else { + hideAuthMessage(); + } adaptViewAccordingToAuthenticationMethod(); showServerStatus(); showAuthStatus(); @@ -340,40 +348,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } - @SuppressLint("SetJavaScriptEnabled") - private void initWebView() { - CookieManager cookieManager = CookieManager.getInstance(); - cookieManager.setAcceptCookie(true); - cookieManager.removeAllCookie(); - - mWebViewClient = new SsoWebViewClient(mHandler, this); - mSsoWebView.setWebViewClient(mWebViewClient); - WebSettings webSettings = mSsoWebView.getSettings(); - webSettings.setJavaScriptEnabled(true); - webSettings.setBuiltInZoomControls(true); - webSettings.setLoadWithOverviewMode(false); - webSettings.setSavePassword(false); - 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; @@ -409,9 +384,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList 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)); } @@ -429,6 +401,8 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList super.onSaveInstanceState(outState); /// connection state and info + outState.putInt(KEY_AUTH_MESSAGE_VISIBILITY, mAuthMessage.getVisibility()); + outState.putString(KEY_AUTH_MESSAGE_TEXT, mAuthMessage.getText().toString()); outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText); outState.putInt(KEY_SERVER_STATUS_ICON, mServerStatusIcon); outState.putBoolean(KEY_SERVER_VALID, mServerIsValid); @@ -450,12 +424,10 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList 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)); + } @@ -486,13 +458,14 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList super.onResume(); if (mAction == ACTION_UPDATE_TOKEN && mJustCreated && getIntent().getBooleanExtra(EXTRA_ENFORCED_UPDATE, false)) { if (AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mCurrentAuthTokenType)) { - Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show(); - + //Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show(); + showAuthMessage(getString(R.string.auth_expired_oauth_token_toast)); } 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(); - + //Toast.makeText(this, R.string.auth_expired_saml_sso_token_toast, Toast.LENGTH_LONG).show(); + showAuthMessage(getString(R.string.auth_expired_saml_sso_token_toast)); } else { - Toast.makeText(this, R.string.auth_expired_basic_auth_toast, Toast.LENGTH_LONG).show(); + //Toast.makeText(this, R.string.auth_expired_basic_auth_toast, Toast.LENGTH_LONG).show(); + showAuthMessage(getString(R.string.auth_expired_basic_auth_toast)); } } @@ -501,6 +474,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } mJustCreated = false; + } @@ -686,6 +660,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList return; } + hideAuthMessage(); if (AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mCurrentAuthTokenType)) { startOauthorization(); } else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) { @@ -797,11 +772,14 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } catch (IllegalArgumentException e) { // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens } - + if (result.isTemporalRedirection()) { String url = result.getRedirectedLocation(); - mWebViewClient.setTargetUrl(mHostBaseUrl + AccountUtils.getWebdavPath(mDiscoveredVersion, mCurrentAuthTokenType)); - mSsoWebView.loadUrl(url); + String targetUrl = mHostBaseUrl + AccountUtils.getWebdavPath(mDiscoveredVersion, mCurrentAuthTokenType); + + // Show dialog + mSamlDialog = SamlWebViewDialog.newInstance(url, targetUrl); + mSamlDialog.show(getSupportFragmentManager(), TAG_SAML_DIALOG); mAuthStatusIcon = android.R.drawable.ic_secure; mAuthStatusText = R.string.auth_follow_auth_server; @@ -1448,7 +1426,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mUsernameInput.setVisibility(View.GONE); mPasswordInput.setVisibility(View.GONE); mAccountNameInput.setVisibility(View.GONE); - mSsoWebView.setVisibility(View.GONE); } else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) { // SAML-based web Single Sign On @@ -1457,8 +1434,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mUsernameInput.setVisibility(View.GONE); mPasswordInput.setVisibility(View.GONE); mAccountNameInput.setVisibility(View.VISIBLE); - mSsoWebView.setVisibility(View.VISIBLE); - } else { // basic HTTP authorization mOAuthAuthEndpointText.setVisibility(View.GONE); @@ -1466,7 +1441,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mUsernameInput.setVisibility(View.VISIBLE); mPasswordInput.setVisibility(View.VISIBLE); mAccountNameInput.setVisibility(View.GONE); - mSsoWebView.setVisibility(View.GONE); } } @@ -1537,20 +1511,33 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList } + public void onSamlDialogSuccess(String sessionCookie){ + mAuthToken = sessionCookie; + + if (sessionCookie != null && sessionCookie.length() > 0) { + Log_OC.d(TAG, "Successful SSO - time to save the account"); + mAuthToken = sessionCookie; + if (mAction == ACTION_CREATE) { + createAccount(); + + } else { + updateToken(); + } + + finish(); + + } + } + + + @Override public void onSsoFinished(String sessionCookie) { //Toast.makeText(this, "got cookies: " + sessionCookie, Toast.LENGTH_LONG).show(); - + if (sessionCookie != null && sessionCookie.length() > 0) { Log_OC.d(TAG, "Successful SSO - time to save the account"); - mAuthToken = sessionCookie; - if (mAction == ACTION_CREATE) { - createAccount(); - - } else { - updateToken(); - } - + onSamlDialogSuccess(sessionCookie); finish(); } else { @@ -1558,5 +1545,19 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList Log_OC.d(TAG, "SSO failed"); } } + + + /** Show auth_message + * + * @param message + */ + private void showAuthMessage(String message) { + mAuthMessage.setVisibility(View.VISIBLE); + mAuthMessage.setText(message); + } + + private void hideAuthMessage() { + mAuthMessage.setVisibility(View.GONE); + } }