|
@@ -18,24 +18,8 @@
|
|
|
|
|
|
package com.owncloud.android.authentication;
|
|
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.Account;
|
|
-import android.accounts.AccountAuthenticatorActivity;
|
|
|
|
import android.accounts.AccountManager;
|
|
import android.accounts.AccountManager;
|
|
-import android.annotation.SuppressLint;
|
|
|
|
import android.app.AlertDialog;
|
|
import android.app.AlertDialog;
|
|
import android.app.Dialog;
|
|
import android.app.Dialog;
|
|
import android.app.ProgressDialog;
|
|
import android.app.ProgressDialog;
|
|
@@ -59,17 +43,28 @@ import android.view.View.OnFocusChangeListener;
|
|
import android.view.View.OnTouchListener;
|
|
import android.view.View.OnTouchListener;
|
|
import android.view.Window;
|
|
import android.view.Window;
|
|
import android.view.inputmethod.EditorInfo;
|
|
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.CheckBox;
|
|
import android.widget.EditText;
|
|
import android.widget.EditText;
|
|
-import android.widget.Button;
|
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
-import android.widget.Toast;
|
|
|
|
import android.widget.TextView.OnEditorActionListener;
|
|
import android.widget.TextView.OnEditorActionListener;
|
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
|
|
+import com.owncloud.android.Log_OC;
|
|
import com.owncloud.android.R;
|
|
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;
|
|
import eu.alefzero.webdav.WebdavClient;
|
|
|
|
|
|
@@ -80,7 +75,7 @@ import eu.alefzero.webdav.WebdavClient;
|
|
* @author David A. Velasco
|
|
* @author David A. Velasco
|
|
*/
|
|
*/
|
|
public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|
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();
|
|
private static final String TAG = AuthenticatorActivity.class.getSimpleName();
|
|
|
|
|
|
@@ -116,6 +111,8 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
public static final byte ACTION_CREATE = 0;
|
|
public static final byte ACTION_CREATE = 0;
|
|
public static final byte ACTION_UPDATE_TOKEN = 1;
|
|
public static final byte ACTION_UPDATE_TOKEN = 1;
|
|
|
|
|
|
|
|
+ private static final String TAG_SAML_DIALOG = "samlWebViewDialog";
|
|
|
|
+
|
|
private String mHostBaseUrl;
|
|
private String mHostBaseUrl;
|
|
private OwnCloudVersion mDiscoveredVersion;
|
|
private OwnCloudVersion mDiscoveredVersion;
|
|
|
|
|
|
@@ -152,8 +149,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
private TextView mOAuthTokenEndpointText;
|
|
private TextView mOAuthTokenEndpointText;
|
|
|
|
|
|
private TextView mAccountNameInput;
|
|
private TextView mAccountNameInput;
|
|
- private WebView mSsoWebView;
|
|
|
|
- private SsoWebViewClient mWebViewClient;
|
|
|
|
|
|
+ private SamlWebViewDialog mSamlDialog;
|
|
|
|
|
|
private View mOkButton;
|
|
private View mOkButton;
|
|
|
|
|
|
@@ -180,7 +176,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
mOAuthTokenEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_2);
|
|
mOAuthTokenEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_2);
|
|
mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check);
|
|
mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check);
|
|
mAccountNameInput = (EditText) findViewById(R.id.account_name);
|
|
mAccountNameInput = (EditText) findViewById(R.id.account_name);
|
|
- mSsoWebView = (WebView) findViewById(R.id.web_sso_view);
|
|
|
|
mOkButton = findViewById(R.id.buttonOK);
|
|
mOkButton = findViewById(R.id.buttonOK);
|
|
mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text);
|
|
mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text);
|
|
|
|
|
|
@@ -266,8 +261,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
if (mCurrentAuthTokenType == null) {
|
|
if (mCurrentAuthTokenType == null) {
|
|
mCurrentAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD;
|
|
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
|
|
// check if server check was interrupted by a configuration change
|
|
@@ -340,40 +333,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() {
|
|
private void initAuthorizationMethod() {
|
|
boolean oAuthRequired = false;
|
|
boolean oAuthRequired = false;
|
|
@@ -409,9 +369,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
mUsernameInput.setText(userName);
|
|
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));
|
|
mOAuth2Check.setChecked(AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mCurrentAuthTokenType));
|
|
|
|
|
|
}
|
|
}
|
|
@@ -450,12 +407,10 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
outState.putParcelable(KEY_ACCOUNT, mAccount);
|
|
outState.putParcelable(KEY_ACCOUNT, mAccount);
|
|
}
|
|
}
|
|
outState.putString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE, mCurrentAuthTokenType);
|
|
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
|
|
// refresh button enabled
|
|
outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));
|
|
outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -501,6 +456,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
}
|
|
}
|
|
|
|
|
|
mJustCreated = false;
|
|
mJustCreated = false;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -797,11 +753,14 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
} catch (IllegalArgumentException e) {
|
|
} 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
|
|
// 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()) {
|
|
if (result.isTemporalRedirection()) {
|
|
String url = result.getRedirectedLocation();
|
|
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;
|
|
mAuthStatusIcon = android.R.drawable.ic_secure;
|
|
mAuthStatusText = R.string.auth_follow_auth_server;
|
|
mAuthStatusText = R.string.auth_follow_auth_server;
|
|
@@ -1448,7 +1407,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
mUsernameInput.setVisibility(View.GONE);
|
|
mUsernameInput.setVisibility(View.GONE);
|
|
mPasswordInput.setVisibility(View.GONE);
|
|
mPasswordInput.setVisibility(View.GONE);
|
|
mAccountNameInput.setVisibility(View.GONE);
|
|
mAccountNameInput.setVisibility(View.GONE);
|
|
- mSsoWebView.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
} else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) {
|
|
} else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) {
|
|
// SAML-based web Single Sign On
|
|
// SAML-based web Single Sign On
|
|
@@ -1457,8 +1415,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
mUsernameInput.setVisibility(View.GONE);
|
|
mUsernameInput.setVisibility(View.GONE);
|
|
mPasswordInput.setVisibility(View.GONE);
|
|
mPasswordInput.setVisibility(View.GONE);
|
|
mAccountNameInput.setVisibility(View.VISIBLE);
|
|
mAccountNameInput.setVisibility(View.VISIBLE);
|
|
- mSsoWebView.setVisibility(View.VISIBLE);
|
|
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
// basic HTTP authorization
|
|
// basic HTTP authorization
|
|
mOAuthAuthEndpointText.setVisibility(View.GONE);
|
|
mOAuthAuthEndpointText.setVisibility(View.GONE);
|
|
@@ -1466,7 +1422,6 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
mUsernameInput.setVisibility(View.VISIBLE);
|
|
mUsernameInput.setVisibility(View.VISIBLE);
|
|
mPasswordInput.setVisibility(View.VISIBLE);
|
|
mPasswordInput.setVisibility(View.VISIBLE);
|
|
mAccountNameInput.setVisibility(View.GONE);
|
|
mAccountNameInput.setVisibility(View.GONE);
|
|
- mSsoWebView.setVisibility(View.GONE);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1537,20 +1492,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
|
|
@Override
|
|
public void onSsoFinished(String sessionCookie) {
|
|
public void onSsoFinished(String sessionCookie) {
|
|
//Toast.makeText(this, "got cookies: " + sessionCookie, Toast.LENGTH_LONG).show();
|
|
//Toast.makeText(this, "got cookies: " + sessionCookie, Toast.LENGTH_LONG).show();
|
|
-
|
|
|
|
|
|
+
|
|
if (sessionCookie != null && sessionCookie.length() > 0) {
|
|
if (sessionCookie != null && sessionCookie.length() > 0) {
|
|
Log_OC.d(TAG, "Successful SSO - time to save the account");
|
|
Log_OC.d(TAG, "Successful SSO - time to save the account");
|
|
- mAuthToken = sessionCookie;
|
|
|
|
- if (mAction == ACTION_CREATE) {
|
|
|
|
- createAccount();
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- updateToken();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ onSamlDialogSuccess(sessionCookie);
|
|
finish();
|
|
finish();
|
|
|
|
|
|
} else {
|
|
} else {
|
|
@@ -1558,5 +1526,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
|
|
Log_OC.d(TAG, "SSO failed");
|
|
Log_OC.d(TAG, "SSO failed");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|