1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.authentication
;
21 import java
.security
.cert
.X509Certificate
;
23 import android
.accounts
.Account
;
24 import android
.accounts
.AccountManager
;
25 import android
.app
.AlertDialog
;
26 import android
.app
.Dialog
;
27 import android
.app
.ProgressDialog
;
28 import android
.content
.ComponentName
;
29 import android
.content
.Context
;
30 import android
.content
.DialogInterface
;
31 import android
.content
.Intent
;
32 import android
.content
.ServiceConnection
;
33 import android
.content
.SharedPreferences
;
34 import android
.graphics
.Rect
;
35 import android
.graphics
.drawable
.Drawable
;
36 import android
.net
.Uri
;
37 import android
.net
.http
.SslError
;
38 import android
.os
.Bundle
;
39 import android
.os
.Handler
;
40 import android
.os
.IBinder
;
41 import android
.preference
.PreferenceManager
;
42 import android
.support
.v4
.app
.Fragment
;
43 import android
.support
.v4
.app
.FragmentManager
;
44 import android
.support
.v4
.app
.FragmentTransaction
;
45 import android
.text
.Editable
;
46 import android
.text
.InputType
;
47 import android
.text
.TextWatcher
;
48 import android
.util
.Log
;
49 import android
.view
.KeyEvent
;
50 import android
.view
.MotionEvent
;
51 import android
.view
.View
;
52 import android
.view
.View
.OnFocusChangeListener
;
53 import android
.view
.View
.OnTouchListener
;
54 import android
.view
.Window
;
55 import android
.view
.inputmethod
.EditorInfo
;
56 import android
.webkit
.SslErrorHandler
;
57 import android
.widget
.Button
;
58 import android
.widget
.CheckBox
;
59 import android
.widget
.EditText
;
60 import android
.widget
.TextView
;
61 import android
.widget
.TextView
.OnEditorActionListener
;
62 import android
.widget
.Toast
;
64 import com
.actionbarsherlock
.app
.SherlockDialogFragment
;
65 import com
.owncloud
.android
.MainApp
;
66 import com
.owncloud
.android
.R
;
67 import com
.owncloud
.android
.authentication
.SsoWebViewClient
.SsoWebViewClientListener
;
68 import com
.owncloud
.android
.lib
.common
.accounts
.AccountTypeUtils
;
69 import com
.owncloud
.android
.lib
.common
.accounts
.AccountUtils
.Constants
;
70 import com
.owncloud
.android
.lib
.common
.OwnCloudClientFactory
;
71 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
72 import com
.owncloud
.android
.operations
.DetectAuthenticationMethodOperation
;
73 import com
.owncloud
.android
.operations
.DetectAuthenticationMethodOperation
.AuthenticationMethod
;
74 import com
.owncloud
.android
.operations
.OAuth2GetAccessToken
;
76 import com
.owncloud
.android
.lib
.common
.network
.CertificateCombinedException
;
77 import com
.owncloud
.android
.lib
.common
.operations
.OnRemoteOperationListener
;
78 import com
.owncloud
.android
.lib
.resources
.status
.GetRemoteStatusOperation
;
79 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
80 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
81 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
82 import com
.owncloud
.android
.lib
.resources
.files
.ExistenceCheckRemoteOperation
;
83 import com
.owncloud
.android
.lib
.resources
.users
.GetRemoteUserNameOperation
;
85 import com
.owncloud
.android
.services
.OperationsService
;
86 import com
.owncloud
.android
.services
.OperationsService
.OperationsServiceBinder
;
87 import com
.owncloud
.android
.ui
.dialog
.SamlWebViewDialog
;
88 import com
.owncloud
.android
.ui
.dialog
.SslUntrustedCertDialog
;
89 import com
.owncloud
.android
.ui
.dialog
.SslUntrustedCertDialog
.OnSslUntrustedCertListener
;
90 import com
.owncloud
.android
.utils
.Log_OC
;
91 import com
.owncloud
.android
.lib
.resources
.status
.OwnCloudVersion
;
94 * This Activity is used to add an ownCloud account to the App
96 * @author Bartek Przybylski
97 * @author David A. Velasco
99 public class AuthenticatorActivity
extends AccountAuthenticatorActivity
100 implements OnRemoteOperationListener
, OnFocusChangeListener
, OnEditorActionListener
,
101 SsoWebViewClientListener
, OnSslUntrustedCertListener
{
103 private static final String TAG
= AuthenticatorActivity
.class.getSimpleName();
105 public static final String EXTRA_ACCOUNT
= "ACCOUNT";
106 public static final String EXTRA_USER_NAME
= "USER_NAME";
107 public static final String EXTRA_HOST_NAME
= "HOST_NAME";
108 public static final String EXTRA_ACTION
= "ACTION";
109 public static final String EXTRA_ENFORCED_UPDATE
= "ENFORCE_UPDATE";
111 private static final String KEY_AUTH_MESSAGE_VISIBILITY
= "AUTH_MESSAGE_VISIBILITY";
112 private static final String KEY_AUTH_MESSAGE_TEXT
= "AUTH_MESSAGE_TEXT";
113 private static final String KEY_HOST_URL_TEXT
= "HOST_URL_TEXT";
114 private static final String KEY_OC_VERSION
= "OC_VERSION";
115 private static final String KEY_ACCOUNT
= "ACCOUNT";
116 private static final String KEY_SERVER_VALID
= "SERVER_VALID";
117 private static final String KEY_SERVER_CHECKED
= "SERVER_CHECKED";
118 private static final String KEY_SERVER_CHECK_IN_PROGRESS
= "SERVER_CHECK_IN_PROGRESS";
119 private static final String KEY_SERVER_STATUS_TEXT
= "SERVER_STATUS_TEXT";
120 private static final String KEY_SERVER_STATUS_ICON
= "SERVER_STATUS_ICON";
121 private static final String KEY_IS_SSL_CONN
= "IS_SSL_CONN";
122 private static final String KEY_PASSWORD_VISIBLE
= "PASSWORD_VISIBLE";
123 private static final String KEY_AUTH_STATUS_TEXT
= "AUTH_STATUS_TEXT";
124 private static final String KEY_AUTH_STATUS_ICON
= "AUTH_STATUS_ICON";
125 private static final String KEY_REFRESH_BUTTON_ENABLED
= "KEY_REFRESH_BUTTON_ENABLED";
126 //private static final String KEY_IS_SHARED_SUPPORTED = "KEY_IS_SHARE_SUPPORTED";
127 private static final String KEY_SERVER_AUTH_METHOD
= "KEY_SERVER_AUTH_METHOD";
128 private static final String KEY_DETECT_AUTH_OP_ID
= "KEY_DETECT_AUTH_OP_ID";
131 private static final String AUTH_ON
= "on";
132 private static final String AUTH_OFF
= "off";
133 private static final String AUTH_OPTIONAL
= "optional";
135 private static final int DIALOG_LOGIN_PROGRESS
= 0;
136 private static final int DIALOG_CERT_NOT_SAVED
= 1;
137 private static final int DIALOG_OAUTH2_LOGIN_PROGRESS
= 2;
139 public static final byte ACTION_CREATE
= 0;
140 public static final byte ACTION_UPDATE_TOKEN
= 1;
142 private static final String TAG_SAML_DIALOG
= "samlWebViewDialog";
144 private String mHostBaseUrl
;
145 private OwnCloudVersion mDiscoveredVersion
;
147 private String mAuthMessageText
;
148 private int mAuthMessageVisibility
, mServerStatusText
, mServerStatusIcon
;
149 private boolean mServerIsChecked
, mServerIsValid
, mIsSslConn
;
150 private AuthenticationMethod mServerAuthMethod
= AuthenticationMethod
.UNKNOWN
;
151 private int mDetectAuthOpId
= -1;
153 private int mAuthStatusText
, mAuthStatusIcon
;
154 private TextView mAuthStatusLayout
;
156 private final Handler mHandler
= new Handler();
157 private Thread mOperationThread
;
158 private GetRemoteStatusOperation mOcServerChkOperation
;
159 //private ExistenceCheckRemoteOperation mAuthCheckOperation;
160 private int mExistenceCheckOpId
= -1;
162 private Uri mNewCapturedUriFromOAuth2Redirection
;
164 private AccountManager mAccountMgr
;
165 private boolean mJustCreated
;
166 private byte mAction
;
167 private Account mAccount
;
169 private TextView mAuthMessage
;
171 private EditText mHostUrlInput
;
172 private boolean mHostUrlInputEnabled
;
173 private View mRefreshButton
;
175 private String mAuthTokenType
;
177 private EditText mUsernameInput
;
178 private EditText mPasswordInput
;
180 private CheckBox mOAuth2Check
;
182 private TextView mOAuthAuthEndpointText
;
183 private TextView mOAuthTokenEndpointText
;
185 private SamlWebViewDialog mSamlDialog
;
187 private View mOkButton
;
189 private String mAuthToken
;
191 private boolean mResumed
; // Control if activity is resumed
193 public static String DIALOG_UNTRUSTED_CERT
= "DIALOG_UNTRUSTED_CERT";
195 private ServiceConnection mOperationsServiceConnection
= null
;
197 private OperationsServiceBinder mOperationsServiceBinder
= null
;
202 * IMPORTANT ENTRY POINT 1: activity is shown to the user
205 protected void onCreate(Bundle savedInstanceState
) {
206 super.onCreate(savedInstanceState
);
207 getWindow().requestFeature(Window
.FEATURE_NO_TITLE
);
209 // bind to Operations Service
210 mOperationsServiceConnection
= new OperationsServiceConnection();
211 if (!bindService(new Intent(this, OperationsService
.class),
212 mOperationsServiceConnection
,
213 Context
.BIND_AUTO_CREATE
)) {
215 R
.string
.error_cant_bind_to_operations_service
,
221 /// set view and get references to view elements
222 setContentView(R
.layout
.account_setup
);
223 mAuthMessage
= (TextView
) findViewById(R
.id
.auth_message
);
224 mHostUrlInput
= (EditText
) findViewById(R
.id
.hostUrlInput
);
225 mHostUrlInput
.setText(getString(R
.string
.server_url
)); // valid although R.string.server_url is an empty string
226 mUsernameInput
= (EditText
) findViewById(R
.id
.account_username
);
227 mPasswordInput
= (EditText
) findViewById(R
.id
.account_password
);
228 mOAuthAuthEndpointText
= (TextView
)findViewById(R
.id
.oAuthEntryPoint_1
);
229 mOAuthTokenEndpointText
= (TextView
)findViewById(R
.id
.oAuthEntryPoint_2
);
230 mOAuth2Check
= (CheckBox
) findViewById(R
.id
.oauth_onOff_check
);
231 mOkButton
= findViewById(R
.id
.buttonOK
);
232 mAuthStatusLayout
= (TextView
) findViewById(R
.id
.auth_status_text
);
234 /// set Host Url Input Enabled
235 mHostUrlInputEnabled
= getResources().getBoolean(R
.bool
.show_server_url_input
);
237 /// set visibility of link for new users
238 boolean accountRegisterVisibility
= getResources().getBoolean(R
.bool
.show_welcome_link
);
239 Button welcomeLink
= (Button
) findViewById(R
.id
.welcome_link
);
240 if (welcomeLink
!= null
) {
241 if (accountRegisterVisibility
) {
242 welcomeLink
.setVisibility(View
.VISIBLE
);
243 welcomeLink
.setText(String
.format(getString(R
.string
.auth_register
), getString(R
.string
.app_name
)));
245 findViewById(R
.id
.welcome_link
).setVisibility(View
.GONE
);
250 mAccountMgr
= AccountManager
.get(this);
251 mNewCapturedUriFromOAuth2Redirection
= null
;
252 mAction
= getIntent().getByteExtra(EXTRA_ACTION
, ACTION_CREATE
);
255 boolean refreshButtonEnabled
= false
;
257 // URL input configuration applied
258 if (!mHostUrlInputEnabled
)
260 findViewById(R
.id
.hostUrlFrame
).setVisibility(View
.GONE
);
261 mRefreshButton
= findViewById(R
.id
.centeredRefreshButton
);
264 mRefreshButton
= findViewById(R
.id
.embeddedRefreshButton
);
267 if (savedInstanceState
== null
) {
269 /// connection state and info
270 mAuthMessageVisibility
= View
.GONE
;
271 mServerStatusText
= mServerStatusIcon
= 0;
272 mServerIsValid
= false
;
273 mServerIsChecked
= false
;
275 mAuthStatusText
= mAuthStatusIcon
= 0;
277 /// retrieve extras from intent
278 mAccount
= getIntent().getExtras().getParcelable(EXTRA_ACCOUNT
);
279 if (mAccount
!= null
) {
280 String ocVersion
= mAccountMgr
.getUserData(mAccount
, Constants
.KEY_OC_VERSION
);
281 if (ocVersion
!= null
) {
282 mDiscoveredVersion
= new OwnCloudVersion(ocVersion
);
284 mHostBaseUrl
= normalizeUrl(mAccountMgr
.getUserData(mAccount
, Constants
.KEY_OC_BASE_URL
));
285 mHostUrlInput
.setText(mHostBaseUrl
);
286 String userName
= mAccount
.name
.substring(0, mAccount
.name
.lastIndexOf('@'));
287 mUsernameInput
.setText(userName
);
290 initAuthorizationMethod(); // checks intent and setup.xml to determine mCurrentAuthorizationMethod
293 if (mAction
== ACTION_UPDATE_TOKEN
|| !mHostUrlInputEnabled
) {
299 /// connection state and info
300 mAuthMessageVisibility
= savedInstanceState
.getInt(KEY_AUTH_MESSAGE_VISIBILITY
);
301 mAuthMessageText
= savedInstanceState
.getString(KEY_AUTH_MESSAGE_TEXT
);
302 mServerIsValid
= savedInstanceState
.getBoolean(KEY_SERVER_VALID
);
303 mServerIsChecked
= savedInstanceState
.getBoolean(KEY_SERVER_CHECKED
);
304 mServerStatusText
= savedInstanceState
.getInt(KEY_SERVER_STATUS_TEXT
);
305 mServerStatusIcon
= savedInstanceState
.getInt(KEY_SERVER_STATUS_ICON
);
306 mIsSslConn
= savedInstanceState
.getBoolean(KEY_IS_SSL_CONN
);
307 mAuthStatusText
= savedInstanceState
.getInt(KEY_AUTH_STATUS_TEXT
);
308 mAuthStatusIcon
= savedInstanceState
.getInt(KEY_AUTH_STATUS_ICON
);
309 if (savedInstanceState
.getBoolean(KEY_PASSWORD_VISIBLE
, false
)) {
314 String ocVersion
= savedInstanceState
.getString(KEY_OC_VERSION
);
315 if (ocVersion
!= null
) {
316 mDiscoveredVersion
= new OwnCloudVersion(ocVersion
);
318 mHostBaseUrl
= savedInstanceState
.getString(KEY_HOST_URL_TEXT
);
320 // account data, if updating
321 mAccount
= savedInstanceState
.getParcelable(KEY_ACCOUNT
);
322 mAuthTokenType
= savedInstanceState
.getString(AccountAuthenticator
.KEY_AUTH_TOKEN_TYPE
);
323 if (mAuthTokenType
== null
) {
324 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypePass(MainApp
.getAccountType());
328 // check if server check was interrupted by a configuration change
329 if (savedInstanceState
.getBoolean(KEY_SERVER_CHECK_IN_PROGRESS
, false
)) {
333 // refresh button enabled
334 refreshButtonEnabled
= savedInstanceState
.getBoolean(KEY_REFRESH_BUTTON_ENABLED
);
337 mServerAuthMethod
= AuthenticationMethod
.valueOf(
338 savedInstanceState
.getString(KEY_SERVER_AUTH_METHOD
));
339 mDetectAuthOpId
= savedInstanceState
.getInt(KEY_DETECT_AUTH_OP_ID
);
343 if (mAuthMessageVisibility
== View
.VISIBLE
) {
344 showAuthMessage(mAuthMessageText
);
349 adaptViewAccordingToAuthenticationMethod();
353 if (mAction
== ACTION_UPDATE_TOKEN
) {
354 /// lock things that should not change
355 mHostUrlInput
.setEnabled(false
);
356 mHostUrlInput
.setFocusable(false
);
357 mUsernameInput
.setEnabled(false
);
358 mUsernameInput
.setFocusable(false
);
359 mOAuth2Check
.setVisibility(View
.GONE
);
362 //if (mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled) showRefreshButton();
363 if (mServerIsChecked
&& !mServerIsValid
&& refreshButtonEnabled
) showRefreshButton();
364 mOkButton
.setEnabled(mServerIsValid
); // state not automatically recovered in configuration changes
366 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
) ||
367 !AUTH_OPTIONAL
.equals(getString(R
.string
.auth_method_oauth2
))) {
368 mOAuth2Check
.setVisibility(View
.GONE
);
371 mPasswordInput
.setText(""); // clean password to avoid social hacking (disadvantage: password in removed if the device is turned aside)
373 /// bind view elements to listeners and other friends
374 mHostUrlInput
.setOnFocusChangeListener(this);
375 mHostUrlInput
.setImeOptions(EditorInfo
.IME_ACTION_NEXT
);
376 mHostUrlInput
.setOnEditorActionListener(this);
377 mHostUrlInput
.addTextChangedListener(new TextWatcher() {
380 public void afterTextChanged(Editable s
) {
381 if (!mHostBaseUrl
.equals(normalizeUrl(mHostUrlInput
.getText().toString()))) {
382 mOkButton
.setEnabled(false
);
387 public void beforeTextChanged(CharSequence s
, int start
, int count
, int after
) {
391 public void onTextChanged(CharSequence s
, int start
, int before
, int count
) {
401 mPasswordInput
.setOnFocusChangeListener(this);
402 mPasswordInput
.setImeOptions(EditorInfo
.IME_ACTION_DONE
);
403 mPasswordInput
.setOnEditorActionListener(this);
404 mPasswordInput
.setOnTouchListener(new RightDrawableOnTouchListener() {
406 public boolean onDrawableTouch(final MotionEvent event
) {
407 if (event
.getAction() == MotionEvent
.ACTION_UP
) {
408 AuthenticatorActivity
.this.onViewPasswordClick();
414 findViewById(R
.id
.scroll
).setOnTouchListener(new OnTouchListener() {
416 public boolean onTouch(View view
, MotionEvent event
) {
417 if (event
.getAction() == MotionEvent
.ACTION_DOWN
) {
418 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
) &&
419 mHostUrlInput
.hasFocus()) {
431 private void initAuthorizationMethod() {
432 boolean oAuthRequired
= false
;
433 boolean samlWebSsoRequired
= false
;
435 mAuthTokenType
= getIntent().getExtras().getString(AccountAuthenticator
.KEY_AUTH_TOKEN_TYPE
);
436 mAccount
= getIntent().getExtras().getParcelable(EXTRA_ACCOUNT
);
438 // TODO could be a good moment to validate the received token type, if not null
440 if (mAuthTokenType
== null
) {
441 if (mAccount
!= null
) {
442 /// same authentication method than the one used to create the account to update
443 oAuthRequired
= (mAccountMgr
.getUserData(mAccount
, Constants
.KEY_SUPPORTS_OAUTH2
) != null
);
444 samlWebSsoRequired
= (mAccountMgr
.getUserData(mAccount
, Constants
.KEY_SUPPORTS_SAML_WEB_SSO
) != null
);
447 /// use the one set in setup.xml
448 oAuthRequired
= AUTH_ON
.equals(getString(R
.string
.auth_method_oauth2
));
449 samlWebSsoRequired
= AUTH_ON
.equals(getString(R
.string
.auth_method_saml_web_sso
));
452 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType());
453 } else if (samlWebSsoRequired
) {
454 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType());
456 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypePass(MainApp
.getAccountType());
460 if (mAccount
!= null
) {
461 String userName
= mAccount
.name
.substring(0, mAccount
.name
.lastIndexOf('@'));
462 mUsernameInput
.setText(userName
);
465 mOAuth2Check
.setChecked(AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
));
470 * Saves relevant state before {@link #onPause()}
472 * Do NOT save {@link #mNewCapturedUriFromOAuth2Redirection}; it keeps a temporal flag, intended to defer the
473 * processing of the redirection caught in {@link #onNewIntent(Intent)} until {@link #onResume()}
475 * See {@link #loadSavedInstanceState(Bundle)}
478 protected void onSaveInstanceState(Bundle outState
) {
479 //Log.wtf(TAG, "onSaveInstanceState init" );
480 super.onSaveInstanceState(outState
);
482 /// connection state and info
483 outState
.putInt(KEY_AUTH_MESSAGE_VISIBILITY
, mAuthMessage
.getVisibility());
484 outState
.putString(KEY_AUTH_MESSAGE_TEXT
, mAuthMessage
.getText().toString());
485 outState
.putInt(KEY_SERVER_STATUS_TEXT
, mServerStatusText
);
486 outState
.putInt(KEY_SERVER_STATUS_ICON
, mServerStatusIcon
);
487 outState
.putBoolean(KEY_SERVER_VALID
, mServerIsValid
);
488 outState
.putBoolean(KEY_SERVER_CHECKED
, mServerIsChecked
);
489 outState
.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS
, (!mServerIsValid
&& mOcServerChkOperation
!= null
));
490 outState
.putBoolean(KEY_IS_SSL_CONN
, mIsSslConn
);
491 outState
.putBoolean(KEY_PASSWORD_VISIBLE
, isPasswordVisible());
492 outState
.putInt(KEY_AUTH_STATUS_ICON
, mAuthStatusIcon
);
493 outState
.putInt(KEY_AUTH_STATUS_TEXT
, mAuthStatusText
);
496 if (mDiscoveredVersion
!= null
) {
497 outState
.putString(KEY_OC_VERSION
, mDiscoveredVersion
.getVersion());
499 outState
.putString(KEY_HOST_URL_TEXT
, mHostBaseUrl
);
501 /// account data, if updating
502 if (mAccount
!= null
) {
503 outState
.putParcelable(KEY_ACCOUNT
, mAccount
);
505 outState
.putString(AccountAuthenticator
.KEY_AUTH_TOKEN_TYPE
, mAuthTokenType
);
507 // refresh button enabled
508 outState
.putBoolean(KEY_REFRESH_BUTTON_ENABLED
, (mRefreshButton
.getVisibility() == View
.VISIBLE
));
510 outState
.putString(KEY_SERVER_AUTH_METHOD
, mServerAuthMethod
.name());
511 outState
.putInt(KEY_DETECT_AUTH_OP_ID
, mDetectAuthOpId
);
512 //Log.wtf(TAG, "onSaveInstanceState end" );
517 * The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION request
520 * To make this possible, this activity needs to be qualified with android:launchMode = "singleTask" in the
521 * AndroidManifest.xml file.
524 protected void onNewIntent (Intent intent
) {
525 Log_OC
.d(TAG
, "onNewIntent()");
526 Uri data
= intent
.getData();
527 if (data
!= null
&& data
.toString().startsWith(getString(R
.string
.oauth2_redirect_uri
))) {
528 mNewCapturedUriFromOAuth2Redirection
= data
;
534 * The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION, and
535 * deferred in {@link #onNewIntent(Intent)}, is processed here.
538 protected void onResume() {
539 //Log.wtf(TAG, "onResume init" );
542 if (mAction
== ACTION_UPDATE_TOKEN
&& mJustCreated
&& getIntent().getBooleanExtra(EXTRA_ENFORCED_UPDATE
, false
)) {
543 if (AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
544 //Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show();
545 showAuthMessage(getString(R
.string
.auth_expired_oauth_token_toast
));
546 } else if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
547 //Toast.makeText(this, R.string.auth_expired_saml_sso_token_toast, Toast.LENGTH_LONG).show();
548 showAuthMessage(getString(R
.string
.auth_expired_saml_sso_token_toast
));
550 //Toast.makeText(this, R.string.auth_expired_basic_auth_toast, Toast.LENGTH_LONG).show();
551 showAuthMessage(getString(R
.string
.auth_expired_basic_auth_toast
));
555 if (mNewCapturedUriFromOAuth2Redirection
!= null
) {
556 getOAuth2AccessTokenFromCapturedRedirection();
559 mJustCreated
= false
;
561 if (mOperationsServiceBinder
!= null
) {
562 doOnResumeAndBound();
565 //Log.wtf(TAG, "onResume end" );
570 protected void onPause() {
571 //Log.wtf(TAG, "onPause init" );
572 if (mOperationsServiceBinder
!= null
) {
573 //Log.wtf(TAG, "unregistering to listen for operation callbacks" );
574 mOperationsServiceBinder
.removeOperationListener(this);
577 //Log.wtf(TAG, "onPause end" );
581 protected void onDestroy() {
582 if (mOperationsServiceConnection
!= null
) {
583 unbindService(mOperationsServiceConnection
);
584 mOperationsServiceBinder
= null
;
591 * Parses the redirection with the response to the GET AUTHORIZATION request to the
592 * oAuth server and requests for the access token (GET ACCESS TOKEN)
594 private void getOAuth2AccessTokenFromCapturedRedirection() {
595 /// Parse data from OAuth redirection
596 String queryParameters
= mNewCapturedUriFromOAuth2Redirection
.getQuery();
597 mNewCapturedUriFromOAuth2Redirection
= null
;
599 /// Showing the dialog with instructions for the user.
600 showDialog(DIALOG_OAUTH2_LOGIN_PROGRESS
);
602 /// GET ACCESS TOKEN to the oAuth server
603 RemoteOperation operation
= new OAuth2GetAccessToken( getString(R
.string
.oauth2_client_id
),
604 getString(R
.string
.oauth2_redirect_uri
),
605 getString(R
.string
.oauth2_grant_type
),
607 //OwnCloudClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());
608 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(Uri
.parse(mOAuthTokenEndpointText
.getText().toString().trim()), getApplicationContext(), true
);
609 operation
.execute(client
, this, mHandler
);
615 * Handles the change of focus on the text inputs for the server URL and the password
617 public void onFocusChange(View view
, boolean hasFocus
) {
618 if (view
.getId() == R
.id
.hostUrlInput
) {
620 onUrlInputFocusLost((TextView
) view
);
626 } else if (view
.getId() == R
.id
.account_password
) {
627 onPasswordFocusChanged((TextView
) view
, hasFocus
);
633 * Handles changes in focus on the text input for the server URL.
635 * IMPORTANT ENTRY POINT 2: When (!hasFocus), user wrote the server URL and changed to
636 * other field. The operation to check the existence of the server in the entered URL is
639 * When hasFocus: user 'comes back' to write again the server URL.
641 * @param hostInput TextView with the URL input field receiving the change of focus.
643 private void onUrlInputFocusLost(TextView hostInput
) {
644 if (!mHostBaseUrl
.equals(normalizeUrl(mHostUrlInput
.getText().toString()))) {
647 mOkButton
.setEnabled(mServerIsValid
);
648 if (!mServerIsValid
) {
655 private void checkOcServer() {
656 String uri
= trimUrlWebdav(mHostUrlInput
.getText().toString().trim());
658 if (!mHostUrlInputEnabled
){
659 uri
= getString(R
.string
.server_url
);
662 mServerIsValid
= false
;
663 mServerIsChecked
= false
;
664 mOkButton
.setEnabled(false
);
665 mDiscoveredVersion
= null
;
667 if (uri
.length() != 0) {
668 mServerStatusText
= R
.string
.auth_testing_connection
;
669 mServerStatusIcon
= R
.drawable
.progress_small
;
671 mOcServerChkOperation
= new GetRemoteStatusOperation(uri
, this);
672 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(Uri
.parse(uri
), this, true
);
673 mOperationThread
= mOcServerChkOperation
.execute(client
, this, mHandler
);
675 mServerStatusText
= 0;
676 mServerStatusIcon
= 0;
683 * Handles changes in focus on the text input for the password (basic authorization).
685 * When (hasFocus), the button to toggle password visibility is shown.
687 * When (!hasFocus), the button is made invisible and the password is hidden.
689 * @param passwordInput TextView with the password input field receiving the change of focus.
690 * @param hasFocus 'True' if focus is received, 'false' if is lost
692 private void onPasswordFocusChanged(TextView passwordInput
, boolean hasFocus
) {
694 showViewPasswordButton();
697 hidePasswordButton();
702 private void showViewPasswordButton() {
703 //int drawable = android.R.drawable.ic_menu_view;
704 int drawable
= R
.drawable
.ic_view
;
705 if (isPasswordVisible()) {
706 //drawable = android.R.drawable.ic_secure;
707 drawable
= R
.drawable
.ic_hide
;
709 mPasswordInput
.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable
, 0);
712 private boolean isPasswordVisible() {
713 return ((mPasswordInput
.getInputType() & InputType
.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
) == InputType
.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
);
716 private void hidePasswordButton() {
717 mPasswordInput
.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
720 private void showPassword() {
721 mPasswordInput
.setInputType(InputType
.TYPE_CLASS_TEXT
| InputType
.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
);
722 showViewPasswordButton();
725 private void hidePassword() {
726 mPasswordInput
.setInputType(InputType
.TYPE_CLASS_TEXT
| InputType
.TYPE_TEXT_VARIATION_PASSWORD
);
727 showViewPasswordButton();
732 * Cancels the authenticator activity
734 * IMPORTANT ENTRY POINT 3: Never underestimate the importance of cancellation
736 * This method is bound in the layout/acceoun_setup.xml resource file.
738 * @param view Cancel button
740 public void onCancelClick(View view
) {
741 setResult(RESULT_CANCELED
); // TODO review how is this related to AccountAuthenticator (debugging)
748 * Checks the credentials of the user in the root of the ownCloud server
749 * before creating a new local account.
751 * For basic authorization, a check of existence of the root folder is
754 * For OAuth, starts the flow to get an access token; the credentials test
755 * is postponed until it is available.
757 * IMPORTANT ENTRY POINT 4
759 * @param view OK button
761 public void onOkClick(View view
) {
762 // this check should be unnecessary
763 if (mDiscoveredVersion
== null
|| !mDiscoveredVersion
.isVersionValid() || mHostBaseUrl
== null
|| mHostBaseUrl
.length() == 0) {
764 mServerStatusIcon
= R
.drawable
.common_error
;
765 mServerStatusText
= R
.string
.auth_wtf_reenter_URL
;
767 mOkButton
.setEnabled(false
);
768 Log_OC
.wtf(TAG
, "The user was allowed to click 'connect' to an unchecked server!!");
772 if (AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
773 startOauthorization();
774 } else if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
775 startSamlBasedFederatedSingleSignOnAuthorization();
777 checkBasicAuthorization();
783 * Tests the credentials entered by the user performing a check of existence on
784 * the root folder of the ownCloud server.
786 private void checkBasicAuthorization() {
787 /// get the path to the root folder through WebDAV from the version server
788 String webdav_path
= AccountUtils
.getWebdavPath(mDiscoveredVersion
, mAuthTokenType
);
790 /// get basic credentials entered by user
791 String username
= mUsernameInput
.getText().toString();
792 String password
= mPasswordInput
.getText().toString();
794 /// be gentle with the user
795 showDialog(DIALOG_LOGIN_PROGRESS
);
797 /// test credentials accessing the root folder
798 String remotePath
="";
799 boolean successIfAbsent
= false
;
800 boolean followRedirects
= true
;
801 startExistenceCheckRemoteOperation(remotePath
, this, successIfAbsent
, webdav_path
, username
, password
, followRedirects
);
805 private void startExistenceCheckRemoteOperation(String remotePath
, Context context
, boolean successIfAbsent
, String webdav_path
,
806 String username
, String password
, boolean followRedirects
) {
808 Intent existenceCheckIntent
= new Intent();
809 existenceCheckIntent
.setAction(OperationsService
.ACTION_EXISTENCE_CHECK
);
810 existenceCheckIntent
.putExtra(OperationsService
.EXTRA_SERVER_URL
, mHostBaseUrl
);
811 existenceCheckIntent
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, remotePath
);
812 existenceCheckIntent
.putExtra(OperationsService
.EXTRA_SUCCESS_IF_ABSENT
, successIfAbsent
);
813 existenceCheckIntent
.putExtra(OperationsService
.EXTRA_WEBDAV_PATH
, webdav_path
);
814 existenceCheckIntent
.putExtra(OperationsService
.EXTRA_USERNAME
, username
);
815 existenceCheckIntent
.putExtra(OperationsService
.EXTRA_PASSWORD
, password
);
816 existenceCheckIntent
.putExtra(OperationsService
.EXTRA_AUTH_TOKEN
, mAuthToken
);
817 existenceCheckIntent
.putExtra(OperationsService
.EXTRA_FOLLOW_REDIRECTS
, followRedirects
);
819 if (mOperationsServiceBinder
!= null
) {
820 Log
.wtf(TAG
, "starting existenceCheckRemoteOperation..." );
821 mExistenceCheckOpId
= mOperationsServiceBinder
.newOperation(existenceCheckIntent
);
826 * Starts the OAuth 'grant type' flow to get an access token, with
827 * a GET AUTHORIZATION request to the BUILT-IN authorization server.
829 private void startOauthorization() {
830 // be gentle with the user
831 mAuthStatusIcon
= R
.drawable
.progress_small
;
832 mAuthStatusText
= R
.string
.oauth_login_connection
;
836 // GET AUTHORIZATION request
837 //Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth));
838 Uri uri
= Uri
.parse(mOAuthAuthEndpointText
.getText().toString().trim());
839 Uri
.Builder uriBuilder
= uri
.buildUpon();
840 uriBuilder
.appendQueryParameter(OAuth2Constants
.KEY_RESPONSE_TYPE
, getString(R
.string
.oauth2_response_type
));
841 uriBuilder
.appendQueryParameter(OAuth2Constants
.KEY_REDIRECT_URI
, getString(R
.string
.oauth2_redirect_uri
));
842 uriBuilder
.appendQueryParameter(OAuth2Constants
.KEY_CLIENT_ID
, getString(R
.string
.oauth2_client_id
));
843 uriBuilder
.appendQueryParameter(OAuth2Constants
.KEY_SCOPE
, getString(R
.string
.oauth2_scope
));
844 //uriBuilder.appendQueryParameter(OAuth2Constants.KEY_STATE, whateverwewant);
845 uri
= uriBuilder
.build();
846 Log_OC
.d(TAG
, "Starting browser to view " + uri
.toString());
847 Intent i
= new Intent(Intent
.ACTION_VIEW
, uri
);
853 * Starts the Web Single Sign On flow to get access to the root folder
856 private void startSamlBasedFederatedSingleSignOnAuthorization() {
857 // be gentle with the user
858 mAuthStatusIcon
= R
.drawable
.progress_small
;
859 mAuthStatusText
= R
.string
.auth_connecting_auth_server
;
861 showDialog(DIALOG_LOGIN_PROGRESS
);
863 /// get the path to the root folder through WebDAV from the version server
864 String webdav_path
= AccountUtils
.getWebdavPath(mDiscoveredVersion
, mAuthTokenType
);
866 /// test credentials accessing the root folder
867 String remotePath
="";
868 boolean successIfAbsent
= false
;
869 boolean followRedirections
= false
;
870 startExistenceCheckRemoteOperation(remotePath
, this, successIfAbsent
, webdav_path
, "", "", followRedirections
);
875 * Callback method invoked when a RemoteOperation executed by this Activity finishes.
877 * Dispatches the operation flow to the right method.
880 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
882 if (operation
instanceof GetRemoteStatusOperation
) {
883 onOcServerCheckFinish((GetRemoteStatusOperation
) operation
, result
);
885 } else if (operation
instanceof OAuth2GetAccessToken
) {
886 onGetOAuthAccessTokenFinish((OAuth2GetAccessToken
)operation
, result
);
888 } else if (operation
instanceof ExistenceCheckRemoteOperation
) {
889 Log
.wtf(TAG
, "received detection response through callback" );
890 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
891 onSamlBasedFederatedSingleSignOnAuthorizationStart(result
);
894 onAuthorizationCheckFinish(result
);
896 } else if (operation
instanceof GetRemoteUserNameOperation
) {
897 onGetUserNameFinish((GetRemoteUserNameOperation
) operation
, result
);
899 } else if (operation
instanceof DetectAuthenticationMethodOperation
) {
900 Log
.wtf(TAG
, "received detection response through callback" );
901 onDetectAuthenticationFinish(result
);
906 private void onDetectAuthenticationFinish(RemoteOperationResult result
) {
907 // Read authentication method
908 mDetectAuthOpId
= -1;
909 if (result
.getData().size() > 0) {
910 AuthenticationMethod authMethod
= (AuthenticationMethod
) result
.getData().get(0);
911 String basic
= AccountTypeUtils
.getAuthTokenTypePass(MainApp
.getAccountType());
912 String oAuth
= AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType());
913 String saml
= AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType());
915 if ( ( mAuthTokenType
.equals(basic
) && !authMethod
.equals(AuthenticationMethod
.BASIC_HTTP_AUTH
) ) ||
916 ( mAuthTokenType
.equals(oAuth
) && !authMethod
.equals(AuthenticationMethod
.BEARER_TOKEN
) ) ||
917 ( mAuthTokenType
.equals(saml
) && !authMethod
.equals(AuthenticationMethod
.SAML_WEB_SSO
) ) ) {
919 mOkButton
.setEnabled(false
);
920 mServerIsValid
= false
;
921 //show an alert message ( Server Status )
922 updateServerStatusIconNoRegularAuth();
926 mOkButton
.setEnabled(true
);
928 // Show server status
937 private void onGetUserNameFinish(GetRemoteUserNameOperation operation
, RemoteOperationResult result
) {
939 if (result
.isSuccess()) {
940 boolean success
= false
;
941 String username
= operation
.getUserName();
943 if ( mAction
== ACTION_CREATE
) {
944 mUsernameInput
.setText(username
);
945 success
= createAccount();
948 if (!mUsernameInput
.getText().toString().equals(username
)) {
949 // fail - not a new account, but an existing one; disallow
950 result
= new RemoteOperationResult(ResultCode
.ACCOUNT_NOT_THE_SAME
);
951 updateAuthStatusIconAndText(result
);
953 Log_OC
.d(TAG
, result
.getLogMessage());
963 updateStatusIconFailUserName();
965 Log_OC
.e(TAG
, "Access to user name failed: " + result
.getLogMessage());
970 private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperationResult result
) {
972 dismissDialog(DIALOG_LOGIN_PROGRESS
);
973 } catch (IllegalArgumentException e
) {
974 // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens
977 //if (result.isTemporalRedirection() && result.isIdPRedirection()) {
978 if (result
.isIdPRedirection()) {
979 String url
= result
.getRedirectedLocation();
980 String targetUrl
= mHostBaseUrl
+ AccountUtils
.getWebdavPath(mDiscoveredVersion
, mAuthTokenType
);
983 mSamlDialog
= SamlWebViewDialog
.newInstance(url
, targetUrl
);
984 mSamlDialog
.show(getSupportFragmentManager(), TAG_SAML_DIALOG
);
990 mAuthStatusIcon
= R
.drawable
.common_error
;
991 mAuthStatusText
= R
.string
.auth_unsupported_auth_method
;
999 * Processes the result of the server check performed when the user finishes the enter of the
1002 * @param operation Server check performed.
1003 * @param result Result of the check.
1005 private void onOcServerCheckFinish(GetRemoteStatusOperation operation
, RemoteOperationResult result
) {
1006 if (operation
.equals(mOcServerChkOperation
)) {
1007 /// save result state
1008 mServerIsChecked
= true
;
1009 mServerIsValid
= result
.isSuccess();
1010 mIsSslConn
= (result
.getCode() == ResultCode
.OK_SSL
);
1011 mOcServerChkOperation
= null
;
1014 /// retrieve discovered version and normalize server URL
1015 mDiscoveredVersion
= operation
.getDiscoveredVersion();
1016 mHostBaseUrl
= normalizeUrl(mHostUrlInput
.getText().toString());
1018 // Refresh server status, but don't show it
1019 updateServerStatusIconAndText(result
);
1021 /// update status icon and text
1022 if (mServerIsValid
) {
1023 hideRefreshButton();
1024 // Try to create an account with user and pass "", to know if it is a regular server
1025 // Update connect button in the answer of this method
1026 detectAuthorizationMethod();
1028 showRefreshButton();
1029 // Show server status
1033 /// very special case (TODO: move to a common place for all the remote operations)
1034 if (result
.getCode() == ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
) {
1035 showUntrustedCertDialog(result
);
1039 } // else nothing ; only the last check operation is considered;
1040 // multiple can be triggered if the user amends a URL before a previous check can be triggered
1045 * Try to access with user/pass ""/"", to know if it is a regular server
1047 private void detectAuthorizationMethod() {
1049 Log_OC
.d(TAG
, "Trying empty authorization to detect authentication method");
1051 String webdav_path
= AccountUtils
.getWebdavPath(mDiscoveredVersion
, mAuthTokenType
);
1053 /// test credentials
1054 //Intent detectAuthIntent = new Intent(this, OperationsService.class);
1055 Intent detectAuthIntent
= new Intent();
1056 detectAuthIntent
.setAction(OperationsService
.ACTION_DETECT_AUTHENTICATION_METHOD
);
1057 detectAuthIntent
.putExtra(OperationsService
.EXTRA_SERVER_URL
, mHostBaseUrl
);
1058 detectAuthIntent
.putExtra(OperationsService
.EXTRA_WEBDAV_PATH
, webdav_path
);
1060 //if (mOperationsBinder != null) { // let's let it crash to detect if is really possible
1061 mServerAuthMethod
= AuthenticationMethod
.UNKNOWN
;
1062 if (mOperationsServiceBinder
!= null
) {
1063 //Log.wtf(TAG, "starting detection..." );
1064 mDetectAuthOpId
= mOperationsServiceBinder
.newOperation(detectAuthIntent
);
1070 private String
normalizeUrl(String url
) {
1071 if (url
!= null
&& url
.length() > 0) {
1073 if (!url
.toLowerCase().startsWith("http://") &&
1074 !url
.toLowerCase().startsWith("https://")) {
1076 url
= "https://" + url
;
1078 url
= "http://" + url
;
1082 url
= trimUrlWebdav(url
);
1084 if (url
.endsWith("/")) {
1085 url
= url
.substring(0, url
.length() - 1);
1089 return (url
!= null ? url
: "");
1093 private String
trimUrlWebdav(String url
){
1094 if(url
.toLowerCase().endsWith(AccountUtils
.WEBDAV_PATH_4_0
)){
1095 url
= url
.substring(0, url
.length() - AccountUtils
.WEBDAV_PATH_4_0
.length());
1096 } else if(url
.toLowerCase().endsWith(AccountUtils
.WEBDAV_PATH_2_0
)){
1097 url
= url
.substring(0, url
.length() - AccountUtils
.WEBDAV_PATH_2_0
.length());
1098 } else if (url
.toLowerCase().endsWith(AccountUtils
.WEBDAV_PATH_1_2
)){
1099 url
= url
.substring(0, url
.length() - AccountUtils
.WEBDAV_PATH_1_2
.length());
1101 return (url
!= null ? url
: "");
1106 * Chooses the right icon and text to show to the user for the received operation result.
1108 * @param result Result of a remote operation performed in this activity
1110 private void updateServerStatusIconAndText(RemoteOperationResult result
) {
1111 mServerStatusIcon
= R
.drawable
.common_error
; // the most common case in the switch below
1113 switch (result
.getCode()) {
1115 mServerStatusIcon
= android
.R
.drawable
.ic_secure
;
1116 mServerStatusText
= R
.string
.auth_secure_connection
;
1121 if (mHostUrlInput
.getText().toString().trim().toLowerCase().startsWith("http://") ) {
1122 mServerStatusText
= R
.string
.auth_connection_established
;
1123 mServerStatusIcon
= R
.drawable
.ic_ok
;
1125 mServerStatusText
= R
.string
.auth_nossl_plain_ok_title
;
1126 mServerStatusIcon
= android
.R
.drawable
.ic_partial_secure
;
1130 case NO_NETWORK_CONNECTION
:
1131 mServerStatusIcon
= R
.drawable
.no_network
;
1132 mServerStatusText
= R
.string
.auth_no_net_conn_title
;
1135 case SSL_RECOVERABLE_PEER_UNVERIFIED
:
1136 mServerStatusText
= R
.string
.auth_ssl_unverified_server_title
;
1138 case BAD_OC_VERSION
:
1139 mServerStatusText
= R
.string
.auth_bad_oc_version_title
;
1141 case WRONG_CONNECTION
:
1142 mServerStatusText
= R
.string
.auth_wrong_connection_title
;
1145 mServerStatusText
= R
.string
.auth_timeout_title
;
1147 case INCORRECT_ADDRESS
:
1148 mServerStatusText
= R
.string
.auth_incorrect_address_title
;
1151 mServerStatusText
= R
.string
.auth_ssl_general_error_title
;
1154 mServerStatusText
= R
.string
.auth_unauthorized
;
1156 case HOST_NOT_AVAILABLE
:
1157 mServerStatusText
= R
.string
.auth_unknown_host_title
;
1159 case INSTANCE_NOT_CONFIGURED
:
1160 mServerStatusText
= R
.string
.auth_not_configured_title
;
1162 case FILE_NOT_FOUND
:
1163 mServerStatusText
= R
.string
.auth_incorrect_path_title
;
1166 mServerStatusText
= R
.string
.auth_oauth_error
;
1168 case OAUTH2_ERROR_ACCESS_DENIED
:
1169 mServerStatusText
= R
.string
.auth_oauth_error_access_denied
;
1171 case UNHANDLED_HTTP_CODE
:
1173 mServerStatusText
= R
.string
.auth_unknown_error_title
;
1176 mServerStatusText
= 0;
1177 mServerStatusIcon
= 0;
1183 * Chooses the right icon and text to show to the user for the received operation result.
1185 * @param result Result of a remote operation performed in this activity
1187 private void updateAuthStatusIconAndText(RemoteOperationResult result
) {
1188 mAuthStatusIcon
= R
.drawable
.common_error
; // the most common case in the switch below
1190 switch (result
.getCode()) {
1192 mAuthStatusIcon
= android
.R
.drawable
.ic_secure
;
1193 mAuthStatusText
= R
.string
.auth_secure_connection
;
1198 if (mHostUrlInput
.getText().toString().trim().toLowerCase().startsWith("http://") ) {
1199 mAuthStatusText
= R
.string
.auth_connection_established
;
1200 mAuthStatusIcon
= R
.drawable
.ic_ok
;
1202 mAuthStatusText
= R
.string
.auth_nossl_plain_ok_title
;
1203 mAuthStatusIcon
= android
.R
.drawable
.ic_partial_secure
;
1207 case NO_NETWORK_CONNECTION
:
1208 mAuthStatusIcon
= R
.drawable
.no_network
;
1209 mAuthStatusText
= R
.string
.auth_no_net_conn_title
;
1212 case SSL_RECOVERABLE_PEER_UNVERIFIED
:
1213 mAuthStatusText
= R
.string
.auth_ssl_unverified_server_title
;
1215 case BAD_OC_VERSION
:
1216 mAuthStatusText
= R
.string
.auth_bad_oc_version_title
;
1218 case WRONG_CONNECTION
:
1219 mAuthStatusText
= R
.string
.auth_wrong_connection_title
;
1222 mAuthStatusText
= R
.string
.auth_timeout_title
;
1224 case INCORRECT_ADDRESS
:
1225 mAuthStatusText
= R
.string
.auth_incorrect_address_title
;
1228 mAuthStatusText
= R
.string
.auth_ssl_general_error_title
;
1231 mAuthStatusText
= R
.string
.auth_unauthorized
;
1233 case HOST_NOT_AVAILABLE
:
1234 mAuthStatusText
= R
.string
.auth_unknown_host_title
;
1236 case INSTANCE_NOT_CONFIGURED
:
1237 mAuthStatusText
= R
.string
.auth_not_configured_title
;
1239 case FILE_NOT_FOUND
:
1240 mAuthStatusText
= R
.string
.auth_incorrect_path_title
;
1243 mAuthStatusText
= R
.string
.auth_oauth_error
;
1245 case OAUTH2_ERROR_ACCESS_DENIED
:
1246 mAuthStatusText
= R
.string
.auth_oauth_error_access_denied
;
1248 case ACCOUNT_NOT_NEW
:
1249 mAuthStatusText
= R
.string
.auth_account_not_new
;
1251 case ACCOUNT_NOT_THE_SAME
:
1252 mAuthStatusText
= R
.string
.auth_account_not_the_same
;
1254 case UNHANDLED_HTTP_CODE
:
1256 mAuthStatusText
= R
.string
.auth_unknown_error_title
;
1259 mAuthStatusText
= 0;
1260 mAuthStatusIcon
= 0;
1265 private void updateStatusIconFailUserName(){
1266 mAuthStatusIcon
= R
.drawable
.common_error
;
1267 mAuthStatusText
= R
.string
.auth_fail_get_user_name
;
1270 private void updateServerStatusIconNoRegularAuth(){
1271 mServerStatusIcon
= R
.drawable
.common_error
;
1272 mServerStatusText
= R
.string
.auth_can_not_auth_against_server
;
1276 * Processes the result of the request for and access token send
1277 * to an OAuth authorization server.
1279 * @param operation Operation performed requesting the access token.
1280 * @param result Result of the operation.
1282 private void onGetOAuthAccessTokenFinish(OAuth2GetAccessToken operation
, RemoteOperationResult result
) {
1284 dismissDialog(DIALOG_OAUTH2_LOGIN_PROGRESS
);
1285 } catch (IllegalArgumentException e
) {
1286 // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens
1289 String webdav_path
= AccountUtils
.getWebdavPath(mDiscoveredVersion
, mAuthTokenType
);
1290 if (result
.isSuccess() && webdav_path
!= null
) {
1291 /// be gentle with the user
1292 showDialog(DIALOG_LOGIN_PROGRESS
);
1294 /// time to test the retrieved access token on the ownCloud server
1295 mAuthToken
= ((OAuth2GetAccessToken
)operation
).getResultTokenMap().get(OAuth2Constants
.KEY_ACCESS_TOKEN
);
1296 Log_OC
.d(TAG
, "Got ACCESS TOKEN: " + mAuthToken
);
1298 String remotePath
="";
1299 boolean successIfAbsent
= false
;
1300 boolean followRedirects
= true
;
1301 startExistenceCheckRemoteOperation(remotePath
, this, successIfAbsent
, webdav_path
, "", "", followRedirects
);
1304 updateAuthStatusIconAndText(result
);
1306 Log_OC
.d(TAG
, "Access failed: " + result
.getLogMessage());
1312 * Processes the result of the access check performed to try the user credentials.
1314 * Creates a new account through the AccountManager.
1316 * @param operation Access check performed.
1317 * @param result Result of the operation.
1319 private void onAuthorizationCheckFinish(RemoteOperationResult result
) {
1321 dismissDialog(DIALOG_LOGIN_PROGRESS
);
1322 } catch (IllegalArgumentException e
) {
1323 // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens
1326 if (result
.isSuccess()) {
1327 Log_OC
.d(TAG
, "Successful access - time to save the account");
1329 boolean success
= false
;
1330 if (mAction
== ACTION_CREATE
) {
1331 success
= createAccount();
1342 } else if (result
.isServerFail() || result
.isException()) {
1343 /// if server fail or exception in authorization, the UI is updated as when a server check failed
1344 mServerIsChecked
= true
;
1345 mServerIsValid
= false
;
1347 mOcServerChkOperation
= null
;
1348 mDiscoveredVersion
= null
;
1349 mHostBaseUrl
= normalizeUrl(mHostUrlInput
.getText().toString());
1351 // update status icon and text
1352 updateServerStatusIconAndText(result
);
1354 mAuthStatusIcon
= 0;
1355 mAuthStatusText
= 0;
1358 // update input controls state
1359 showRefreshButton();
1360 mOkButton
.setEnabled(false
);
1362 // very special case (TODO: move to a common place for all the remote operations) (dangerous here?)
1363 if (result
.getCode() == ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
) {
1364 showUntrustedCertDialog(result
);
1367 } else { // authorization fail due to client side - probably wrong credentials
1368 updateAuthStatusIconAndText(result
);
1370 Log_OC
.d(TAG
, "Access failed: " + result
.getLogMessage());
1378 * Sets the proper response to get that the Account Authenticator that started this activity saves
1379 * a new authorization token for mAccount.
1381 private void updateToken() {
1382 Bundle response
= new Bundle();
1383 response
.putString(AccountManager
.KEY_ACCOUNT_NAME
, mAccount
.name
);
1384 response
.putString(AccountManager
.KEY_ACCOUNT_TYPE
, mAccount
.type
);
1386 if (AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1387 response
.putString(AccountManager
.KEY_AUTHTOKEN
, mAuthToken
);
1388 // the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention
1389 mAccountMgr
.setAuthToken(mAccount
, mAuthTokenType
, mAuthToken
);
1391 } else if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1393 response
.putString(AccountManager
.KEY_AUTHTOKEN
, mAuthToken
);
1394 // the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention
1395 mAccountMgr
.setAuthToken(mAccount
, mAuthTokenType
, mAuthToken
);
1398 response
.putString(AccountManager
.KEY_AUTHTOKEN
, mPasswordInput
.getText().toString());
1399 mAccountMgr
.setPassword(mAccount
, mPasswordInput
.getText().toString());
1401 setAccountAuthenticatorResult(response
);
1407 * Creates a new account through the Account Authenticator that started this activity.
1409 * This makes the account permanent.
1411 * TODO Decide how to name the OAuth accounts
1413 private boolean createAccount() {
1414 /// create and save new ownCloud account
1415 boolean isOAuth
= AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
);
1416 boolean isSaml
= AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
);
1418 Uri uri
= Uri
.parse(mHostBaseUrl
);
1419 String username
= mUsernameInput
.getText().toString().trim();
1421 username
= "OAuth_user" + (new java
.util
.Random(System
.currentTimeMillis())).nextLong();
1423 String accountName
= username
+ "@" + uri
.getHost();
1424 if (uri
.getPort() >= 0) {
1425 accountName
+= ":" + uri
.getPort();
1427 mAccount
= new Account(accountName
, MainApp
.getAccountType());
1428 if (AccountUtils
.exists(mAccount
, getApplicationContext())) {
1429 // fail - not a new account, but an existing one; disallow
1430 RemoteOperationResult result
= new RemoteOperationResult(ResultCode
.ACCOUNT_NOT_NEW
);
1431 updateAuthStatusIconAndText(result
);
1433 Log_OC
.d(TAG
, result
.getLogMessage());
1438 if (isOAuth
|| isSaml
) {
1439 mAccountMgr
.addAccountExplicitly(mAccount
, "", null
); // with external authorizations, the password is never input in the app
1441 mAccountMgr
.addAccountExplicitly(mAccount
, mPasswordInput
.getText().toString(), null
);
1444 /// add the new account as default in preferences, if there is none already
1445 Account defaultAccount
= AccountUtils
.getCurrentOwnCloudAccount(this);
1446 if (defaultAccount
== null
) {
1447 SharedPreferences
.Editor editor
= PreferenceManager
1448 .getDefaultSharedPreferences(this).edit();
1449 editor
.putString("select_oc_account", accountName
);
1453 /// prepare result to return to the Authenticator
1454 // TODO check again what the Authenticator makes with it; probably has the same effect as addAccountExplicitly, but it's not well done
1455 final Intent intent
= new Intent();
1456 intent
.putExtra(AccountManager
.KEY_ACCOUNT_TYPE
, MainApp
.getAccountType());
1457 intent
.putExtra(AccountManager
.KEY_ACCOUNT_NAME
, mAccount
.name
);
1459 intent.putExtra(AccountManager.KEY_AUTHTOKEN, MainApp.getAccountType()); */
1460 intent
.putExtra(AccountManager
.KEY_USERDATA
, username
);
1461 if (isOAuth
|| isSaml
) {
1462 mAccountMgr
.setAuthToken(mAccount
, mAuthTokenType
, mAuthToken
);
1464 /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA
1465 mAccountMgr
.setUserData(mAccount
, Constants
.KEY_OC_VERSION
, mDiscoveredVersion
.getVersion());
1466 mAccountMgr
.setUserData(mAccount
, Constants
.KEY_OC_BASE_URL
, mHostBaseUrl
);
1469 mAccountMgr
.setUserData(mAccount
, Constants
.KEY_SUPPORTS_SAML_WEB_SSO
, "TRUE");
1470 } else if (isOAuth
) {
1471 mAccountMgr
.setUserData(mAccount
, Constants
.KEY_SUPPORTS_OAUTH2
, "TRUE");
1474 setAccountAuthenticatorResult(intent
.getExtras());
1475 setResult(RESULT_OK
, intent
);
1485 * Necessary to update the contents of the SSL Dialog
1487 * TODO move to some common place for all possible untrusted SSL failures
1490 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
1492 case DIALOG_LOGIN_PROGRESS
:
1493 case DIALOG_CERT_NOT_SAVED
:
1494 case DIALOG_OAUTH2_LOGIN_PROGRESS
:
1497 Log_OC
.e(TAG
, "Incorrect dialog called with id = " + id
);
1506 protected Dialog
onCreateDialog(int id
) {
1507 Dialog dialog
= null
;
1509 case DIALOG_LOGIN_PROGRESS
: {
1510 /// simple progress dialog
1511 ProgressDialog working_dialog
= new ProgressDialog(this);
1512 working_dialog
.setMessage(getResources().getString(R
.string
.auth_trying_to_login
));
1513 working_dialog
.setIndeterminate(true
);
1514 working_dialog
.setCancelable(true
);
1516 .setOnCancelListener(new DialogInterface
.OnCancelListener() {
1518 public void onCancel(DialogInterface dialog
) {
1519 /// TODO study if this is enough
1520 Log_OC
.i(TAG
, "Login canceled");
1521 if (mOperationThread
!= null
) {
1522 mOperationThread
.interrupt();
1527 dialog
= working_dialog
;
1530 case DIALOG_OAUTH2_LOGIN_PROGRESS
: {
1531 ProgressDialog working_dialog
= new ProgressDialog(this);
1532 working_dialog
.setMessage(String
.format("Getting authorization"));
1533 working_dialog
.setIndeterminate(true
);
1534 working_dialog
.setCancelable(true
);
1536 .setOnCancelListener(new DialogInterface
.OnCancelListener() {
1538 public void onCancel(DialogInterface dialog
) {
1539 Log_OC
.i(TAG
, "Login canceled");
1543 dialog
= working_dialog
;
1546 case DIALOG_CERT_NOT_SAVED
: {
1547 AlertDialog
.Builder builder
= new AlertDialog
.Builder(this);
1548 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
1549 builder
.setCancelable(false
);
1550 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
1552 public void onClick(DialogInterface dialog
, int which
) {
1556 dialog
= builder
.create();
1560 Log_OC
.e(TAG
, "Incorrect dialog called with id = " + id
);
1567 * Starts and activity to open the 'new account' page in the ownCloud web site
1569 * @param view 'Account register' button
1571 public void onRegisterClick(View view
) {
1572 Intent register
= new Intent(Intent
.ACTION_VIEW
, Uri
.parse(getString(R
.string
.welcome_link_url
)));
1573 setResult(RESULT_CANCELED
);
1574 startActivity(register
);
1579 * Updates the content and visibility state of the icon and text associated
1580 * to the last check on the ownCloud server.
1582 private void showServerStatus() {
1583 TextView tv
= (TextView
) findViewById(R
.id
.server_status_text
);
1585 if (mServerStatusIcon
== 0 && mServerStatusText
== 0) {
1586 tv
.setVisibility(View
.INVISIBLE
);
1589 tv
.setText(mServerStatusText
);
1590 tv
.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon
, 0, 0, 0);
1591 tv
.setVisibility(View
.VISIBLE
);
1598 * Updates the content and visibility state of the icon and text associated
1599 * to the interactions with the OAuth authorization server.
1601 private void showAuthStatus() {
1602 if (mAuthStatusIcon
== 0 && mAuthStatusText
== 0) {
1603 mAuthStatusLayout
.setVisibility(View
.INVISIBLE
);
1606 mAuthStatusLayout
.setText(mAuthStatusText
);
1607 mAuthStatusLayout
.setCompoundDrawablesWithIntrinsicBounds(mAuthStatusIcon
, 0, 0, 0);
1608 mAuthStatusLayout
.setVisibility(View
.VISIBLE
);
1613 private void showRefreshButton() {
1614 mRefreshButton
.setVisibility(View
.VISIBLE
);
1617 private void hideRefreshButton() {
1618 mRefreshButton
.setVisibility(View
.GONE
);
1622 * Called when the refresh button in the input field for ownCloud host is clicked.
1624 * Performs a new check on the URL in the input field.
1626 * @param view Refresh 'button'
1628 public void onRefreshClick(View view
) {
1634 * Called when the eye icon in the password field is clicked.
1636 * Toggles the visibility of the password in the field.
1638 public void onViewPasswordClick() {
1639 int selectionStart
= mPasswordInput
.getSelectionStart();
1640 int selectionEnd
= mPasswordInput
.getSelectionEnd();
1641 if (isPasswordVisible()) {
1646 mPasswordInput
.setSelection(selectionStart
, selectionEnd
);
1651 * Called when the checkbox for OAuth authorization is clicked.
1653 * Hides or shows the input fields for user & password.
1655 * @param view 'View password' 'button'
1657 public void onCheckClick(View view
) {
1658 CheckBox oAuth2Check
= (CheckBox
)view
;
1659 if (oAuth2Check
.isChecked()) {
1660 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType());
1662 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypePass(MainApp
.getAccountType());
1664 adaptViewAccordingToAuthenticationMethod();
1669 * Changes the visibility of input elements depending on
1670 * the current authorization method.
1672 private void adaptViewAccordingToAuthenticationMethod () {
1673 if (AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1674 // OAuth 2 authorization
1675 mOAuthAuthEndpointText
.setVisibility(View
.VISIBLE
);
1676 mOAuthTokenEndpointText
.setVisibility(View
.VISIBLE
);
1677 mUsernameInput
.setVisibility(View
.GONE
);
1678 mPasswordInput
.setVisibility(View
.GONE
);
1680 } else if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1681 // SAML-based web Single Sign On
1682 mOAuthAuthEndpointText
.setVisibility(View
.GONE
);
1683 mOAuthTokenEndpointText
.setVisibility(View
.GONE
);
1684 mUsernameInput
.setVisibility(View
.GONE
);
1685 mPasswordInput
.setVisibility(View
.GONE
);
1687 // basic HTTP authorization
1688 mOAuthAuthEndpointText
.setVisibility(View
.GONE
);
1689 mOAuthTokenEndpointText
.setVisibility(View
.GONE
);
1690 mUsernameInput
.setVisibility(View
.VISIBLE
);
1691 mPasswordInput
.setVisibility(View
.VISIBLE
);
1696 * Called when the 'action' button in an IME is pressed ('enter' in software keyboard).
1698 * Used to trigger the authentication check when the user presses 'enter' after writing the password,
1699 * or to throw the server test when the only field on screen is the URL input field.
1702 public boolean onEditorAction(TextView inputField
, int actionId
, KeyEvent event
) {
1703 if (actionId
== EditorInfo
.IME_ACTION_DONE
&& inputField
!= null
&& inputField
.equals(mPasswordInput
)) {
1704 if (mOkButton
.isEnabled()) {
1705 mOkButton
.performClick();
1708 } else if (actionId
== EditorInfo
.IME_ACTION_NEXT
&& inputField
!= null
&& inputField
.equals(mHostUrlInput
)) {
1709 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1713 return false
; // always return false to grant that the software keyboard is hidden anyway
1717 private abstract static class RightDrawableOnTouchListener
implements OnTouchListener
{
1719 private int fuzz
= 75;
1725 public boolean onTouch(View view
, MotionEvent event
) {
1726 Drawable rightDrawable
= null
;
1727 if (view
instanceof TextView
) {
1728 Drawable
[] drawables
= ((TextView
)view
).getCompoundDrawables();
1729 if (drawables
.length
> 2) {
1730 rightDrawable
= drawables
[2];
1733 if (rightDrawable
!= null
) {
1734 final int x
= (int) event
.getX();
1735 final int y
= (int) event
.getY();
1736 final Rect bounds
= rightDrawable
.getBounds();
1737 if (x
>= (view
.getRight() - bounds
.width() - fuzz
) && x
<= (view
.getRight() - view
.getPaddingRight() + fuzz
)
1738 && y
>= (view
.getPaddingTop() - fuzz
) && y
<= (view
.getHeight() - view
.getPaddingBottom()) + fuzz
) {
1740 return onDrawableTouch(event
);
1746 public abstract boolean onDrawableTouch(final MotionEvent event
);
1750 public void onSamlDialogSuccess(String sessionCookie
) {
1751 mAuthToken
= sessionCookie
;
1753 if (sessionCookie
!= null
&& sessionCookie
.length() > 0) {
1754 mAuthToken
= sessionCookie
;
1756 GetRemoteUserNameOperation getUserOperation
= new GetRemoteUserNameOperation();
1757 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(Uri
.parse(mHostBaseUrl
), getApplicationContext(), true
);
1758 client
.setSsoSessionCookie(mAuthToken
);
1759 getUserOperation
.execute(client
, this, mHandler
);
1767 public void onSsoFinished(String sessionCookies
) {
1768 //Toast.makeText(this, "got cookies: " + sessionCookie, Toast.LENGTH_LONG).show();
1770 if (sessionCookies
!= null
&& sessionCookies
.length() > 0) {
1771 Log_OC
.d(TAG
, "Successful SSO - time to save the account");
1772 onSamlDialogSuccess(sessionCookies
);
1773 Fragment fd
= getSupportFragmentManager().findFragmentByTag(TAG_SAML_DIALOG
);
1774 if (fd
!= null
&& fd
instanceof SherlockDialogFragment
) {
1775 Dialog d
= ((SherlockDialogFragment
)fd
).getDialog();
1776 if (d
!= null
&& d
.isShowing()) {
1783 Log_OC
.d(TAG
, "SSO failed");
1788 /** Show auth_message
1792 private void showAuthMessage(String message
) {
1793 mAuthMessage
.setVisibility(View
.VISIBLE
);
1794 mAuthMessage
.setText(message
);
1797 private void hideAuthMessage() {
1798 mAuthMessage
.setVisibility(View
.GONE
);
1802 public boolean onTouchEvent(MotionEvent event
) {
1803 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
) &&
1804 mHostUrlInput
.hasFocus() && event
.getAction() == MotionEvent
.ACTION_DOWN
) {
1807 return super.onTouchEvent(event
);
1812 * Show untrusted cert dialog
1814 public void showUntrustedCertDialog(X509Certificate x509Certificate
, SslError error
, SslErrorHandler handler
) {
1815 // Show a dialog with the certificate info
1816 SslUntrustedCertDialog dialog
= null
;
1817 if (x509Certificate
== null
) {
1818 dialog
= SslUntrustedCertDialog
.newInstanceForEmptySslError(error
, handler
);
1820 dialog
= SslUntrustedCertDialog
.newInstanceForFullSslError(x509Certificate
, error
, handler
);
1822 FragmentManager fm
= getSupportFragmentManager();
1823 FragmentTransaction ft
= fm
.beginTransaction();
1824 ft
.addToBackStack(null
);
1825 dialog
.show(ft
, DIALOG_UNTRUSTED_CERT
);
1829 * Show untrusted cert dialog
1831 public void showUntrustedCertDialog(RemoteOperationResult result
) {
1832 // Show a dialog with the certificate info
1833 SslUntrustedCertDialog dialog
= SslUntrustedCertDialog
.newInstanceForFullSslError((CertificateCombinedException
)result
.getException());
1834 FragmentManager fm
= getSupportFragmentManager();
1835 FragmentTransaction ft
= fm
.beginTransaction();
1836 ft
.addToBackStack(null
);
1837 dialog
.show(ft
, DIALOG_UNTRUSTED_CERT
);
1842 * Dismiss untrusted cert dialog
1844 public void dismissUntrustedCertDialog(){
1845 /*Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_UNTRUSTED_CERT);
1847 SslErrorViewAdapter dialog = (SslErrorViewAdapter) frag;
1854 * Called from SslValidatorDialog when a new server certificate was correctly saved.
1856 public void onSavedCertificate() {
1857 Fragment fd
= getSupportFragmentManager().findFragmentByTag(TAG_SAML_DIALOG
);
1859 // if SAML dialog is not shown, the SslDialog was shown due to an SSL error in the server check
1865 * Called from SslValidatorDialog when a new server certificate could not be saved
1866 * when the user requested it.
1869 public void onFailedSavingCertificate() {
1870 showDialog(DIALOG_CERT_NOT_SAVED
);
1875 public void onCancelCertificate() {
1880 public void cancelWebView() {
1881 Fragment fd
= getSupportFragmentManager().findFragmentByTag(TAG_SAML_DIALOG
);
1882 if (fd
!= null
&& fd
instanceof SherlockDialogFragment
) {
1883 Dialog d
= ((SherlockDialogFragment
)fd
).getDialog();
1884 if (d
!= null
&& d
.isShowing()) {
1892 private void doOnResumeAndBound() {
1893 //Log.wtf(TAG, "registering to listen for operation callbacks" );
1894 mOperationsServiceBinder
.addOperationListener(AuthenticatorActivity
.this, mHandler
);
1896 if (mDetectAuthOpId
!= -1) {
1897 RemoteOperationResult result
=
1898 mOperationsServiceBinder
.getOperationResultIfFinished(mDetectAuthOpId
);
1899 if (result
!= null
) {
1900 //Log.wtf(TAG, "found result of operation finished while rotating");
1901 onDetectAuthenticationFinish(result
);
1905 if (mExistenceCheckOpId
!= -1) {
1906 RemoteOperationResult result
=
1907 mOperationsServiceBinder
.getOperationResultIfFinished(mExistenceCheckOpId
);
1908 if (result
!= null
) {
1909 Log
.wtf(TAG
, "found result of operation finished while rotating");
1910 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1911 onSamlBasedFederatedSingleSignOnAuthorizationStart(result
);
1914 onAuthorizationCheckFinish(result
);
1921 * Implements callback methods for service binding.
1923 private class OperationsServiceConnection
implements ServiceConnection
{
1926 public void onServiceConnected(ComponentName component
, IBinder service
) {
1927 if (component
.equals(new ComponentName(AuthenticatorActivity
.this, OperationsService
.class))) {
1928 //Log_OC.wtf(TAG, "Operations service connected");
1929 mOperationsServiceBinder
= (OperationsServiceBinder
) service
;
1931 doOnResumeAndBound();
1940 public void onServiceDisconnected(ComponentName component
) {
1941 if (component
.equals(new ComponentName(AuthenticatorActivity
.this, OperationsService
.class))) {
1942 Log_OC
.e(TAG
, "Operations service crashed");
1943 mOperationsServiceBinder
= null
;