\r
package com.owncloud.android.authentication;\r
\r
-import com.owncloud.android.Log_OC;\r
-import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
-import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
-import com.owncloud.android.utils.OwnCloudVersion;\r
-import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
-import com.owncloud.android.network.OwnCloudClientUtils;\r
-import com.owncloud.android.operations.OwnCloudServerCheckOperation;\r
-import com.owncloud.android.operations.ExistenceCheckOperation;\r
-import com.owncloud.android.operations.OAuth2GetAccessToken;\r
-import com.owncloud.android.operations.OnRemoteOperationListener;\r
-import com.owncloud.android.operations.RemoteOperation;\r
-import com.owncloud.android.operations.RemoteOperationResult;\r
-import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
-\r
import android.accounts.Account;\r
-import android.accounts.AccountAuthenticatorActivity;\r
import android.accounts.AccountManager;\r
-import android.annotation.SuppressLint;\r
import android.app.AlertDialog;\r
import android.app.Dialog;\r
import android.app.ProgressDialog;\r
import android.view.View.OnTouchListener;\r
import android.view.Window;\r
import android.view.inputmethod.EditorInfo;\r
-import android.webkit.CookieManager;\r
-import android.webkit.WebSettings;\r
-import android.webkit.WebView;\r
+import android.widget.Button;\r
import android.widget.CheckBox;\r
import android.widget.EditText;\r
-import android.widget.Button;\r
import android.widget.TextView;\r
-import android.widget.Toast;\r
import android.widget.TextView.OnEditorActionListener;\r
+import android.widget.Toast;\r
\r
+import com.owncloud.android.Log_OC;\r
import com.owncloud.android.R;\r
+import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
+import com.owncloud.android.network.OwnCloudClientUtils;\r
+import com.owncloud.android.operations.ExistenceCheckOperation;\r
+import com.owncloud.android.operations.OAuth2GetAccessToken;\r
+import com.owncloud.android.operations.OnRemoteOperationListener;\r
+import com.owncloud.android.operations.OwnCloudServerCheckOperation;\r
+import com.owncloud.android.operations.RemoteOperation;\r
+import com.owncloud.android.operations.RemoteOperationResult;\r
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
+import com.owncloud.android.ui.dialog.SamlWebViewDialog;\r
+import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
+import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
+import com.owncloud.android.utils.OwnCloudVersion;\r
\r
import eu.alefzero.webdav.WebdavClient;\r
\r
* @author David A. Velasco\r
*/\r
public class AuthenticatorActivity extends AccountAuthenticatorActivity\r
-implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener, OnEditorActionListener, SsoWebViewClientListener {\r
+implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener, OnEditorActionListener, SsoWebViewClientListener{\r
\r
private static final String TAG = AuthenticatorActivity.class.getSimpleName();\r
\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
public static final byte ACTION_CREATE = 0;\r
public static final byte ACTION_UPDATE_TOKEN = 1;\r
\r
+ private static final String TAG_SAML_DIALOG = "samlWebViewDialog";\r
+ \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
private TextView mOAuthTokenEndpointText;\r
\r
private TextView mAccountNameInput;\r
- private WebView mSsoWebView;\r
- private SsoWebViewClient mWebViewClient;\r
+ private SamlWebViewDialog mSamlDialog;\r
\r
private View mOkButton;\r
\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
mOAuthTokenEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_2);\r
mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check);\r
mAccountNameInput = (EditText) findViewById(R.id.account_name);\r
- mSsoWebView = (WebView) findViewById(R.id.web_sso_view);\r
mOkButton = findViewById(R.id.buttonOK);\r
mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text); \r
\r
\r
if (savedInstanceState == null) {\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
+ mAccountNameInput.setText(userName);\r
}\r
initAuthorizationMethod(); // checks intent and setup.xml to determine mCurrentAuthorizationMethod\r
mJustCreated = true;\r
\r
} else {\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
if (mCurrentAuthTokenType == null) {\r
mCurrentAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD;\r
\r
- } else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) {\r
- restoreWebView(savedInstanceState);\r
}\r
\r
// check if server check was interrupted by a configuration change\r
\r
}\r
\r
+ if (mAuthMessageVisibility== View.VISIBLE) {\r
+ showAuthMessage(mAuthMessageText);\r
+ }\r
+ else {\r
+ hideAuthMessage();\r
+ }\r
adaptViewAccordingToAuthenticationMethod();\r
showServerStatus();\r
showAuthStatus();\r
mUsernameInput.setEnabled(false);\r
mUsernameInput.setFocusable(false);\r
mOAuth2Check.setVisibility(View.GONE);\r
+ mAccountNameInput.setEnabled(false);\r
+ mAccountNameInput.setFocusable(false);\r
}\r
\r
//if (mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled) showRefreshButton();\r
\r
}\r
\r
- @SuppressLint("SetJavaScriptEnabled")\r
- private void initWebView() {\r
- CookieManager cookieManager = CookieManager.getInstance();\r
- cookieManager.setAcceptCookie(true);\r
- cookieManager.removeAllCookie();\r
-\r
- mWebViewClient = new SsoWebViewClient(mHandler, this);\r
- mSsoWebView.setWebViewClient(mWebViewClient);\r
- WebSettings webSettings = mSsoWebView.getSettings();\r
- webSettings.setJavaScriptEnabled(true);\r
- webSettings.setBuiltInZoomControls(true);\r
- webSettings.setLoadWithOverviewMode(false);\r
- webSettings.setSavePassword(false);\r
- webSettings.setUserAgentString(WebdavClient.USER_AGENT);\r
- }\r
-\r
- @SuppressLint("SetJavaScriptEnabled")\r
- private void restoreWebView(Bundle savedInstanceState) {\r
- mSsoWebView.restoreState(savedInstanceState);\r
- \r
- CookieManager cookieManager = CookieManager.getInstance();\r
- Log_OC.e(TAG, "Accept Cookie: " + cookieManager.acceptCookie());\r
-\r
- mWebViewClient = new SsoWebViewClient(mHandler, this);\r
- mSsoWebView.setWebViewClient(mWebViewClient);\r
- mWebViewClient.setTargetUrl(mHostBaseUrl + AccountUtils.getWebdavPath(mDiscoveredVersion, mCurrentAuthTokenType));\r
- \r
- WebSettings webSettings = mSsoWebView.getSettings();\r
- webSettings.setJavaScriptEnabled(true); // at least this one is not being kept by WebView#restoreState\r
- webSettings.setBuiltInZoomControls(true);\r
- webSettings.setLoadWithOverviewMode(false);\r
- webSettings.setSavePassword(false);\r
- webSettings.setUserAgentString(WebdavClient.USER_AGENT);\r
- }\r
+ \r
\r
private void initAuthorizationMethod() {\r
boolean oAuthRequired = false;\r
mUsernameInput.setText(userName);\r
}\r
\r
- if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) {\r
- initWebView();\r
- }\r
mOAuth2Check.setChecked(AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mCurrentAuthTokenType));\r
\r
}\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
outState.putParcelable(KEY_ACCOUNT, mAccount);\r
}\r
outState.putString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE, mCurrentAuthTokenType);\r
- if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) {\r
- mSsoWebView.saveState(outState);\r
- }\r
\r
// refresh button enabled\r
outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));\r
+ \r
\r
}\r
\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(mCurrentAuthTokenType)) {\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(mCurrentAuthTokenType)) {\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
}\r
\r
mJustCreated = false;\r
+ \r
}\r
\r
\r
return;\r
}\r
\r
+ hideAuthMessage();\r
if (AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mCurrentAuthTokenType)) {\r
startOauthorization();\r
} else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) { \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
+ \r
if (result.isTemporalRedirection()) {\r
String url = result.getRedirectedLocation();\r
- mWebViewClient.setTargetUrl(mHostBaseUrl + AccountUtils.getWebdavPath(mDiscoveredVersion, mCurrentAuthTokenType));\r
- mSsoWebView.loadUrl(url);\r
+ String targetUrl = mHostBaseUrl + AccountUtils.getWebdavPath(mDiscoveredVersion, mCurrentAuthTokenType);\r
+ \r
+ // Show dialog\r
+ mSamlDialog = SamlWebViewDialog.newInstance(url, targetUrl); \r
+ mSamlDialog.show(getSupportFragmentManager(), TAG_SAML_DIALOG);\r
\r
mAuthStatusIcon = android.R.drawable.ic_secure;\r
mAuthStatusText = R.string.auth_follow_auth_server;\r
mUsernameInput.setVisibility(View.GONE);\r
mPasswordInput.setVisibility(View.GONE);\r
mAccountNameInput.setVisibility(View.GONE);\r
- mSsoWebView.setVisibility(View.GONE);\r
\r
} else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) {\r
// SAML-based web Single Sign On\r
mUsernameInput.setVisibility(View.GONE);\r
mPasswordInput.setVisibility(View.GONE);\r
mAccountNameInput.setVisibility(View.VISIBLE);\r
- mSsoWebView.setVisibility(View.VISIBLE);\r
- \r
} else {\r
// basic HTTP authorization\r
mOAuthAuthEndpointText.setVisibility(View.GONE);\r
mUsernameInput.setVisibility(View.VISIBLE);\r
mPasswordInput.setVisibility(View.VISIBLE);\r
mAccountNameInput.setVisibility(View.GONE);\r
- mSsoWebView.setVisibility(View.GONE);\r
}\r
}\r
\r
}\r
\r
\r
+ public void onSamlDialogSuccess(String sessionCookie){\r
+ mAuthToken = sessionCookie;\r
+ \r
+ if (sessionCookie != null && sessionCookie.length() > 0) {\r
+ Log_OC.d(TAG, "Successful SSO - time to save the account");\r
+ mAuthToken = sessionCookie;\r
+ if (mAction == ACTION_CREATE) {\r
+ createAccount();\r
+\r
+ } else {\r
+ updateToken();\r
+ }\r
+\r
+ finish();\r
+\r
+ }\r
+ }\r
+\r
+\r
+\r
@Override\r
public void onSsoFinished(String sessionCookie) {\r
//Toast.makeText(this, "got cookies: " + sessionCookie, Toast.LENGTH_LONG).show();\r
- \r
+\r
if (sessionCookie != null && sessionCookie.length() > 0) {\r
Log_OC.d(TAG, "Successful SSO - time to save the account");\r
- mAuthToken = sessionCookie;\r
- if (mAction == ACTION_CREATE) {\r
- createAccount();\r
-\r
- } else {\r
- updateToken();\r
- }\r
-\r
+ onSamlDialogSuccess(sessionCookie);\r
finish();\r
\r
} else { \r
Log_OC.d(TAG, "SSO failed");\r
}\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
}\r