\r
package com.owncloud.android.authentication;\r
\r
-import java.security.cert.X509Certificate;\r
-import java.util.Map;\r
-\r
import android.accounts.Account;\r
import android.accounts.AccountManager;\r
import android.app.Dialog;\r
import android.os.Handler;\r
import android.os.IBinder;\r
import android.preference.PreferenceManager;\r
+import android.support.v4.app.DialogFragment;\r
import android.support.v4.app.Fragment;\r
import android.support.v4.app.FragmentManager;\r
import android.support.v4.app.FragmentTransaction;\r
import android.view.View;\r
import android.view.View.OnFocusChangeListener;\r
import android.view.View.OnTouchListener;\r
-import android.view.Window;\r
import android.view.inputmethod.EditorInfo;\r
import android.webkit.HttpAuthHandler;\r
import android.webkit.SslErrorHandler;\r
import android.widget.TextView.OnEditorActionListener;\r
import android.widget.Toast;\r
\r
-import com.actionbarsherlock.app.SherlockDialogFragment;\r
import com.owncloud.android.MainApp;\r
import com.owncloud.android.R;\r
import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;\r
import com.owncloud.android.utils.DisplayUtils;\r
\r
+import java.security.cert.X509Certificate;\r
+import java.util.Map;\r
+\r
/**\r
* This Activity is used to add an ownCloud account to the App\r
*/\r
private EditText mUsernameInput;\r
private EditText mPasswordInput;\r
private View mOkButton;\r
+ private View mCenteredRefreshButton;\r
private TextView mAuthStatusView;\r
\r
private int mAuthStatusText = 0, mAuthStatusIcon = 0;\r
/// Identifier of operation in progress which result shouldn't be lost \r
private long mWaitingForOpId = Long.MAX_VALUE;\r
\r
- private final String BASIC_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType());\r
- private final String OAUTH_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType());\r
+ private final String BASIC_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypePass(\r
+ MainApp.getAccountType());\r
+ private final String OAUTH_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeAccessToken(\r
+ MainApp.getAccountType());\r
private final String SAML_TOKEN_TYPE =\r
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType());\r
\r
protected void onCreate(Bundle savedInstanceState) {\r
//Log_OC.wtf(TAG, "onCreate init");\r
super.onCreate(savedInstanceState);\r
- getWindow().requestFeature(Window.FEATURE_NO_TITLE);\r
+\r
+ // Workaround, for fixing a problem with Android Library Suppor v7 19\r
+ //getWindow().requestFeature(Window.FEATURE_NO_TITLE);\r
+ if (getSupportActionBar() != null) {\r
+ getSupportActionBar().hide();\r
+\r
+ getSupportActionBar().setDisplayHomeAsUpEnabled(false);\r
+ getSupportActionBar().setDisplayShowHomeEnabled(false);\r
+ getSupportActionBar().setDisplayShowTitleEnabled(false);\r
+ }\r
\r
mIsFirstAuthAttempt = true;\r
\r
\r
/// initialize general UI elements\r
initOverallUi();\r
+\r
+ mOkButton = findViewById(R.id.buttonOK);\r
+ mOkButton.setOnClickListener(new View.OnClickListener() {\r
+\r
+ @Override\r
+ public void onClick(View v) {\r
+ onOkClick();\r
+ }\r
+ });\r
+\r
+ mCenteredRefreshButton = findViewById(R.id.centeredRefreshButton);\r
+ mCenteredRefreshButton.setOnClickListener(new View.OnClickListener() {\r
+\r
+ @Override\r
+ public void onClick(View v) {\r
+ checkOcServer();\r
+ }\r
+ });\r
\r
mOkButton = findViewById(R.id.buttonOK);\r
\r
if (mAccount != null) {\r
mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);\r
// TODO do next in a setter for mBaseUrl\r
- mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); \r
- String ocVersion = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_VERSION);\r
- if (ocVersion != null) {\r
- mServerInfo.mVersion = new OwnCloudVersion(ocVersion);\r
- }\r
+ mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");\r
+ mServerInfo.mVersion = AccountUtils.getServerVersion(mAccount);\r
} else {\r
mServerInfo.mBaseUrl = getString(R.string.server_url).trim();\r
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");\r
* intended to defer the processing of the redirection caught in \r
* {@link #onNewIntent(Intent)} until {@link #onResume()} \r
* \r
- * See {@link #onSaveInstanceState(Bundle)}\r
+ * See {@link super#onSaveInstanceState(Bundle)}\r
*/\r
@Override\r
protected void onSaveInstanceState(Bundle outState) {\r
mOAuthTokenEndpointText.getText().toString().trim());\r
\r
getServerInfoIntent.putExtra(\r
- OperationsService.EXTRA_OAUTH2_QUERY_PARAMETERS, \r
+ OperationsService.EXTRA_OAUTH2_QUERY_PARAMETERS,\r
queryParameters);\r
\r
if (mOperationsServiceBinder != null) {\r
showRefreshButton(false);\r
\r
if (uri.length() != 0) {\r
+ uri = stripIndexPhpOrAppsFiles(uri, mHostUrlInput);\r
+\r
// Handle internationalized domain names\r
uri = DisplayUtils.convertIdn(uri, true);\r
\r
Intent getServerInfoIntent = new Intent();\r
getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO);\r
getServerInfoIntent.putExtra(\r
- OperationsService.EXTRA_SERVER_URL,\r
- normalizeUrlSuffix(uri)\r
+ OperationsService.EXTRA_SERVER_URL,\r
+ normalizeUrlSuffix(uri)\r
);\r
if (mOperationsServiceBinder != null) {\r
mWaitingForOpId = mOperationsServiceBinder.queueNewOperation(getServerInfoIntent);\r
* is postponed until it is available.\r
* \r
* IMPORTANT ENTRY POINT 4\r
- * \r
- * @param view OK button\r
*/\r
- public void onOkClick(View view) {\r
+ public void onOkClick() {\r
// this check should be unnecessary\r
if (mServerInfo.mVersion == null || \r
!mServerInfo.mVersion.isVersionValid() || \r
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
\r
/// validate credentials accessing the root folder\r
- OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);\r
+ OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username,\r
+ password);\r
accessRootFolder(credentials);\r
}\r
\r
\r
} catch (AccountNotFoundException e) {\r
Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);\r
- Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();\r
+ Toast.makeText(this, R.string.auth_account_does_not_exist,\r
+ Toast.LENGTH_SHORT).show();\r
finish();\r
}\r
}\r
url = "http://" + url;\r
}\r
}\r
- \r
+\r
url = normalizeUrlSuffix(url);\r
}\r
return (url != null ? url : "");\r
return url;\r
}\r
\r
+ private String stripIndexPhpOrAppsFiles(String url, EditText mHostUrlInput) {\r
+ if (url.endsWith("/index.php")) {\r
+ url = url.substring(0, url.lastIndexOf("/index.php"));\r
+ mHostUrlInput.setText(url);\r
+ } else if (url.contains("/index.php/apps/")) {\r
+ url = url.substring(0, url.lastIndexOf("/index.php/apps/"));\r
+ mHostUrlInput.setText(url);\r
+ }\r
+\r
+ return url;\r
+ }\r
\r
// TODO remove, if possible\r
private String trimUrlWebdav(String url){ \r
if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0_AND_LATER)){\r
url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0_AND_LATER.length());\r
}\r
- return (url != null ? url : "");\r
+ return url;\r
}\r
\r
\r
\r
switch (result.getCode()) {\r
case OK_SSL:\r
- mServerStatusIcon = android.R.drawable.ic_secure;\r
+ mServerStatusIcon = R.drawable.ic_lock;\r
mServerStatusText = R.string.auth_secure_connection;\r
break;\r
\r
mServerStatusIcon = R.drawable.ic_ok;\r
} else {\r
mServerStatusText = R.string.auth_nossl_plain_ok_title;\r
- mServerStatusIcon = android.R.drawable.ic_partial_secure;\r
+ mServerStatusIcon = R.drawable.ic_lock_open;\r
}\r
break;\r
\r
mServerStatusText = R.string.auth_unknown_error_title;\r
break;\r
case OK_REDIRECT_TO_NON_SECURE_CONNECTION:\r
- mServerStatusIcon = android.R.drawable.ic_partial_secure;\r
+ mServerStatusIcon = R.drawable.ic_lock_open;\r
mServerStatusText = R.string.auth_redirect_non_secure_connection_title;\r
break;\r
default:\r
\r
switch (result.getCode()) {\r
case OK_SSL:\r
- mAuthStatusIcon = android.R.drawable.ic_secure;\r
+ mAuthStatusIcon = R.drawable.ic_lock;\r
mAuthStatusText = R.string.auth_secure_connection;\r
break;\r
\r
mAuthStatusIcon = R.drawable.ic_ok;\r
} else {\r
mAuthStatusText = R.string.auth_nossl_plain_ok_title;\r
- mAuthStatusIcon = android.R.drawable.ic_partial_secure;\r
+ mAuthStatusIcon = R.drawable.ic_lock_open;\r
}\r
break;\r
\r
Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
\r
/// validate token accessing to root folder / getting session\r
- OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBearerCredentials(mAuthToken);\r
+ OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBearerCredentials(\r
+ mAuthToken);\r
accessRootFolder(credentials);\r
\r
} else {\r
public void onAuthenticatorTaskCallback(RemoteOperationResult result) {\r
mWaitingForOpId = Long.MAX_VALUE;\r
dismissDialog(WAIT_DIALOG_TAG);\r
+ mAsyncTask = null;\r
\r
if (result.isSuccess()) {\r
Log_OC.d(TAG, "Successful access - time to save the account");\r
\r
} catch (AccountNotFoundException e) {\r
Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);\r
- Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();\r
+ Toast.makeText(this, R.string.auth_account_does_not_exist,\r
+ Toast.LENGTH_SHORT).show();\r
finish();\r
}\r
}\r
response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);\r
\r
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).\r
- equals(mAuthTokenType)) { \r
+ equals(mAuthTokenType)) {\r
response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);\r
// the next line is necessary, notifications are calling directly to the \r
// AuthenticatorActivity to update, without AccountManager intervention\r
}\r
\r
\r
- private void getRemoteUserNameOperation(String sessionCookie, boolean followRedirects) {\r
+ private void getRemoteUserNameOperation(String sessionCookie) {\r
\r
Intent getUserNameIntent = new Intent();\r
getUserNameIntent.setAction(OperationsService.ACTION_GET_USER_NAME);\r
if (sessionCookie != null && sessionCookie.length() > 0) {\r
Log_OC.d(TAG, "Successful SSO - time to save the account");\r
mAuthToken = sessionCookie;\r
- getRemoteUserNameOperation(sessionCookie, true);\r
+ getRemoteUserNameOperation(sessionCookie);\r
Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG);\r
- if (fd != null && fd instanceof SherlockDialogFragment) {\r
- Dialog d = ((SherlockDialogFragment)fd).getDialog();\r
+ if (fd != null && fd instanceof DialogFragment) {\r
+ Dialog d = ((DialogFragment)fd).getDialog();\r
if (d != null && d.isShowing()) {\r
d.dismiss();\r
}\r
X509Certificate x509Certificate, SslError error, SslErrorHandler handler\r
) {\r
// Show a dialog with the certificate info\r
- SslUntrustedCertDialog dialog = null;\r
+ SslUntrustedCertDialog dialog;\r
if (x509Certificate == null) {\r
dialog = SslUntrustedCertDialog.newInstanceForEmptySslError(error, handler);\r
} else {\r
\r
private void dismissDialog(String dialogTag){\r
Fragment frag = getSupportFragmentManager().findFragmentByTag(dialogTag);\r
- if (frag != null && frag instanceof SherlockDialogFragment) {\r
- SherlockDialogFragment dialog = (SherlockDialogFragment) frag;\r
+ if (frag != null && frag instanceof DialogFragment) {\r
+ DialogFragment dialog = (DialogFragment) frag;\r
dialog.dismiss();\r
}\r
}\r
\r
doOnResumeAndBound();\r
\r
- } else {\r
- return;\r
}\r
\r
}\r
\r
/**\r
* Create and show dialog for request authentication to the user\r
- * @param webView\r
- * @param handler\r
+ * @param webView Web view to emebd into the authentication dialog.\r
+ * @param handler Object responsible for catching and recovering HTTP authentication fails.\r
*/\r
public void createAuthenticationDialog(WebView webView, HttpAuthHandler handler) {\r
\r
mIsFirstAuthAttempt = true;\r
}\r
\r
-\r
}\r