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
.view
.KeyEvent
;
49 import android
.view
.MotionEvent
;
50 import android
.view
.View
;
51 import android
.view
.View
.OnFocusChangeListener
;
52 import android
.view
.View
.OnTouchListener
;
53 import android
.view
.Window
;
54 import android
.view
.inputmethod
.EditorInfo
;
55 import android
.webkit
.SslErrorHandler
;
56 import android
.widget
.Button
;
57 import android
.widget
.CheckBox
;
58 import android
.widget
.EditText
;
59 import android
.widget
.TextView
;
60 import android
.widget
.TextView
.OnEditorActionListener
;
61 import android
.widget
.Toast
;
63 import com
.actionbarsherlock
.app
.SherlockDialogFragment
;
64 import com
.owncloud
.android
.MainApp
;
65 import com
.owncloud
.android
.R
;
66 import com
.owncloud
.android
.authentication
.SsoWebViewClient
.SsoWebViewClientListener
;
67 import com
.owncloud
.android
.lib
.common
.accounts
.AccountTypeUtils
;
68 import com
.owncloud
.android
.lib
.common
.accounts
.AccountUtils
.Constants
;
69 import com
.owncloud
.android
.lib
.common
.OwnCloudClientFactory
;
70 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
71 import com
.owncloud
.android
.operations
.DetectAuthenticationMethodOperation
;
72 import com
.owncloud
.android
.operations
.DetectAuthenticationMethodOperation
.AuthenticationMethod
;
73 import com
.owncloud
.android
.operations
.OAuth2GetAccessToken
;
75 import com
.owncloud
.android
.lib
.common
.network
.CertificateCombinedException
;
76 import com
.owncloud
.android
.lib
.common
.operations
.OnRemoteOperationListener
;
77 import com
.owncloud
.android
.lib
.resources
.status
.GetRemoteStatusOperation
;
78 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
79 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
80 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
81 import com
.owncloud
.android
.lib
.resources
.files
.ExistenceCheckRemoteOperation
;
82 import com
.owncloud
.android
.lib
.resources
.users
.GetRemoteUserNameOperation
;
84 import com
.owncloud
.android
.services
.OperationsService
;
85 import com
.owncloud
.android
.services
.OperationsService
.OperationsServiceBinder
;
86 import com
.owncloud
.android
.ui
.dialog
.SamlWebViewDialog
;
87 import com
.owncloud
.android
.ui
.dialog
.SslUntrustedCertDialog
;
88 import com
.owncloud
.android
.ui
.dialog
.SslUntrustedCertDialog
.OnSslUntrustedCertListener
;
89 import com
.owncloud
.android
.utils
.Log_OC
;
90 import com
.owncloud
.android
.lib
.resources
.status
.OwnCloudVersion
;
93 * This Activity is used to add an ownCloud account to the App
95 * @author Bartek Przybylski
96 * @author David A. Velasco
98 public class AuthenticatorActivity
extends AccountAuthenticatorActivity
99 implements OnRemoteOperationListener
, OnFocusChangeListener
, OnEditorActionListener
,
100 SsoWebViewClientListener
, OnSslUntrustedCertListener
{
102 private static final String TAG
= AuthenticatorActivity
.class.getSimpleName();
104 public static final String EXTRA_ACCOUNT
= "ACCOUNT";
105 public static final String EXTRA_USER_NAME
= "USER_NAME";
106 public static final String EXTRA_HOST_NAME
= "HOST_NAME";
107 public static final String EXTRA_ACTION
= "ACTION";
108 public static final String EXTRA_ENFORCED_UPDATE
= "ENFORCE_UPDATE";
110 private static final String KEY_AUTH_MESSAGE_VISIBILITY
= "AUTH_MESSAGE_VISIBILITY";
111 private static final String KEY_AUTH_MESSAGE_TEXT
= "AUTH_MESSAGE_TEXT";
112 private static final String KEY_HOST_URL_TEXT
= "HOST_URL_TEXT";
113 private static final String KEY_OC_VERSION
= "OC_VERSION";
114 private static final String KEY_OC_VERSION_STRING
= "OC_VERSION_STRING";
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";
128 private static final String AUTH_ON
= "on";
129 private static final String AUTH_OFF
= "off";
130 private static final String AUTH_OPTIONAL
= "optional";
132 private static final int DIALOG_LOGIN_PROGRESS
= 0;
133 private static final int DIALOG_CERT_NOT_SAVED
= 1;
134 private static final int DIALOG_OAUTH2_LOGIN_PROGRESS
= 2;
136 public static final byte ACTION_CREATE
= 0;
137 public static final byte ACTION_UPDATE_TOKEN
= 1;
139 private static final String TAG_SAML_DIALOG
= "samlWebViewDialog";
141 private String mHostBaseUrl
;
142 private OwnCloudVersion mDiscoveredVersion
;
144 private String mAuthMessageText
;
145 private int mAuthMessageVisibility
, mServerStatusText
, mServerStatusIcon
;
146 private boolean mServerIsChecked
, mServerIsValid
, mIsSslConn
;
147 private int mAuthStatusText
, mAuthStatusIcon
;
148 private TextView mAuthStatusLayout
;
150 private ServiceConnection mOperationsConnection
= null
;
151 private OperationsServiceBinder mOperationsBinder
= null
;
153 private final Handler mHandler
= new Handler();
154 private Thread mOperationThread
;
155 private GetRemoteStatusOperation mOcServerChkOperation
;
156 private ExistenceCheckRemoteOperation mAuthCheckOperation
;
158 private Uri mNewCapturedUriFromOAuth2Redirection
;
160 private AccountManager mAccountMgr
;
161 private boolean mJustCreated
;
162 private byte mAction
;
163 private Account mAccount
;
165 private TextView mAuthMessage
;
167 private EditText mHostUrlInput
;
168 private boolean mHostUrlInputEnabled
;
169 private View mRefreshButton
;
171 private String mAuthTokenType
;
173 private EditText mUsernameInput
;
174 private EditText mPasswordInput
;
176 private CheckBox mOAuth2Check
;
178 private TextView mOAuthAuthEndpointText
;
179 private TextView mOAuthTokenEndpointText
;
181 private SamlWebViewDialog mSamlDialog
;
183 private View mOkButton
;
185 private String mAuthToken
;
187 private boolean mResumed
; // Control if activity is resumed
189 public static String DIALOG_UNTRUSTED_CERT
= "DIALOG_UNTRUSTED_CERT";
191 private ServiceConnection mOperationsServiceConnection
= null
;
193 private OperationsServiceBinder mOperationsServiceBinder
= null
;
199 * IMPORTANT ENTRY POINT 1: activity is shown to the user
202 protected void onCreate(Bundle savedInstanceState
) {
203 super.onCreate(savedInstanceState
);
204 getWindow().requestFeature(Window
.FEATURE_NO_TITLE
);
206 // bind to Operations Service
207 mOperationsConnection
= new ServiceConnection() {
210 public void onServiceConnected(ComponentName name
, IBinder service
) {
211 Log_OC
.d(TAG
, "Operations service connected");
212 mOperationsBinder
= (OperationsServiceBinder
) service
;
216 public void onServiceDisconnected(ComponentName name
) {
217 Log_OC
.d(TAG
, "Operations service crashed");
218 mOperationsBinder
= null
;
222 if (!bindService(new Intent(this, OperationsService
.class),
223 mOperationsConnection
,
224 Context
.BIND_AUTO_CREATE
)) {
226 R
.string
.error_cant_bind_to_operations_service
,
232 /// set view and get references to view elements
233 setContentView(R
.layout
.account_setup
);
234 mAuthMessage
= (TextView
) findViewById(R
.id
.auth_message
);
235 mHostUrlInput
= (EditText
) findViewById(R
.id
.hostUrlInput
);
236 mHostUrlInput
.setText(getString(R
.string
.server_url
)); // valid although R.string.server_url is an empty string
237 mUsernameInput
= (EditText
) findViewById(R
.id
.account_username
);
238 mPasswordInput
= (EditText
) findViewById(R
.id
.account_password
);
239 mOAuthAuthEndpointText
= (TextView
)findViewById(R
.id
.oAuthEntryPoint_1
);
240 mOAuthTokenEndpointText
= (TextView
)findViewById(R
.id
.oAuthEntryPoint_2
);
241 mOAuth2Check
= (CheckBox
) findViewById(R
.id
.oauth_onOff_check
);
242 mOkButton
= findViewById(R
.id
.buttonOK
);
243 mAuthStatusLayout
= (TextView
) findViewById(R
.id
.auth_status_text
);
245 /// set Host Url Input Enabled
246 mHostUrlInputEnabled
= getResources().getBoolean(R
.bool
.show_server_url_input
);
248 /// set visibility of link for new users
249 boolean accountRegisterVisibility
= getResources().getBoolean(R
.bool
.show_welcome_link
);
250 Button welcomeLink
= (Button
) findViewById(R
.id
.welcome_link
);
251 if (welcomeLink
!= null
) {
252 if (accountRegisterVisibility
) {
253 welcomeLink
.setVisibility(View
.VISIBLE
);
254 welcomeLink
.setText(String
.format(getString(R
.string
.auth_register
), getString(R
.string
.app_name
)));
256 findViewById(R
.id
.welcome_link
).setVisibility(View
.GONE
);
261 mAccountMgr
= AccountManager
.get(this);
262 mNewCapturedUriFromOAuth2Redirection
= null
;
263 mAction
= getIntent().getByteExtra(EXTRA_ACTION
, ACTION_CREATE
);
266 boolean refreshButtonEnabled
= false
;
268 // URL input configuration applied
269 if (!mHostUrlInputEnabled
)
271 findViewById(R
.id
.hostUrlFrame
).setVisibility(View
.GONE
);
272 mRefreshButton
= findViewById(R
.id
.centeredRefreshButton
);
275 mRefreshButton
= findViewById(R
.id
.embeddedRefreshButton
);
278 if (savedInstanceState
== null
) {
280 /// connection state and info
281 mAuthMessageVisibility
= View
.GONE
;
282 mServerStatusText
= mServerStatusIcon
= 0;
283 mServerIsValid
= false
;
284 mServerIsChecked
= false
;
286 mAuthStatusText
= mAuthStatusIcon
= 0;
288 /// retrieve extras from intent
289 mAccount
= getIntent().getExtras().getParcelable(EXTRA_ACCOUNT
);
290 if (mAccount
!= null
) {
291 String ocVersion
= mAccountMgr
.getUserData(mAccount
, Constants
.KEY_OC_VERSION
);
292 String ocVersionString
= mAccountMgr
.getUserData(mAccount
, Constants
.KEY_OC_VERSION_STRING
);
293 if (ocVersion
!= null
) {
294 mDiscoveredVersion
= new OwnCloudVersion(ocVersion
, ocVersionString
);
296 mHostBaseUrl
= normalizeUrl(mAccountMgr
.getUserData(mAccount
, Constants
.KEY_OC_BASE_URL
));
297 mHostUrlInput
.setText(mHostBaseUrl
);
298 String userName
= mAccount
.name
.substring(0, mAccount
.name
.lastIndexOf('@'));
299 mUsernameInput
.setText(userName
);
302 initAuthorizationMethod(); // checks intent and setup.xml to determine mCurrentAuthorizationMethod
305 if (mAction
== ACTION_UPDATE_TOKEN
|| !mHostUrlInputEnabled
) {
311 /// connection state and info
312 mAuthMessageVisibility
= savedInstanceState
.getInt(KEY_AUTH_MESSAGE_VISIBILITY
);
313 mAuthMessageText
= savedInstanceState
.getString(KEY_AUTH_MESSAGE_TEXT
);
314 mServerIsValid
= savedInstanceState
.getBoolean(KEY_SERVER_VALID
);
315 mServerIsChecked
= savedInstanceState
.getBoolean(KEY_SERVER_CHECKED
);
316 mServerStatusText
= savedInstanceState
.getInt(KEY_SERVER_STATUS_TEXT
);
317 mServerStatusIcon
= savedInstanceState
.getInt(KEY_SERVER_STATUS_ICON
);
318 mIsSslConn
= savedInstanceState
.getBoolean(KEY_IS_SSL_CONN
);
319 mAuthStatusText
= savedInstanceState
.getInt(KEY_AUTH_STATUS_TEXT
);
320 mAuthStatusIcon
= savedInstanceState
.getInt(KEY_AUTH_STATUS_ICON
);
321 if (savedInstanceState
.getBoolean(KEY_PASSWORD_VISIBLE
, false
)) {
326 String ocVersion
= savedInstanceState
.getString(KEY_OC_VERSION
);
327 String ocVersionString
= savedInstanceState
.getString(KEY_OC_VERSION_STRING
);
328 if (ocVersion
!= null
) {
329 mDiscoveredVersion
= new OwnCloudVersion(ocVersion
, ocVersionString
);
331 mHostBaseUrl
= savedInstanceState
.getString(KEY_HOST_URL_TEXT
);
333 // account data, if updating
334 mAccount
= savedInstanceState
.getParcelable(KEY_ACCOUNT
);
335 mAuthTokenType
= savedInstanceState
.getString(AccountAuthenticator
.KEY_AUTH_TOKEN_TYPE
);
336 if (mAuthTokenType
== null
) {
337 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypePass(MainApp
.getAccountType());
341 // check if server check was interrupted by a configuration change
342 if (savedInstanceState
.getBoolean(KEY_SERVER_CHECK_IN_PROGRESS
, false
)) {
346 // refresh button enabled
347 refreshButtonEnabled
= savedInstanceState
.getBoolean(KEY_REFRESH_BUTTON_ENABLED
);
352 if (mAuthMessageVisibility
== View
.VISIBLE
) {
353 showAuthMessage(mAuthMessageText
);
358 adaptViewAccordingToAuthenticationMethod();
362 if (mAction
== ACTION_UPDATE_TOKEN
) {
363 /// lock things that should not change
364 mHostUrlInput
.setEnabled(false
);
365 mHostUrlInput
.setFocusable(false
);
366 mUsernameInput
.setEnabled(false
);
367 mUsernameInput
.setFocusable(false
);
368 mOAuth2Check
.setVisibility(View
.GONE
);
371 //if (mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled) showRefreshButton();
372 if (mServerIsChecked
&& !mServerIsValid
&& refreshButtonEnabled
) showRefreshButton();
373 mOkButton
.setEnabled(mServerIsValid
); // state not automatically recovered in configuration changes
375 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
) ||
376 !AUTH_OPTIONAL
.equals(getString(R
.string
.auth_method_oauth2
))) {
377 mOAuth2Check
.setVisibility(View
.GONE
);
380 mPasswordInput
.setText(""); // clean password to avoid social hacking (disadvantage: password in removed if the device is turned aside)
382 /// bind view elements to listeners and other friends
383 mHostUrlInput
.setOnFocusChangeListener(this);
384 mHostUrlInput
.setImeOptions(EditorInfo
.IME_ACTION_NEXT
);
385 mHostUrlInput
.setOnEditorActionListener(this);
386 mHostUrlInput
.addTextChangedListener(new TextWatcher() {
389 public void afterTextChanged(Editable s
) {
390 if (!mHostBaseUrl
.equals(normalizeUrl(mHostUrlInput
.getText().toString()))) {
391 mOkButton
.setEnabled(false
);
396 public void beforeTextChanged(CharSequence s
, int start
, int count
, int after
) {
400 public void onTextChanged(CharSequence s
, int start
, int before
, int count
) {
410 mPasswordInput
.setOnFocusChangeListener(this);
411 mPasswordInput
.setImeOptions(EditorInfo
.IME_ACTION_DONE
);
412 mPasswordInput
.setOnEditorActionListener(this);
413 mPasswordInput
.setOnTouchListener(new RightDrawableOnTouchListener() {
415 public boolean onDrawableTouch(final MotionEvent event
) {
416 if (event
.getAction() == MotionEvent
.ACTION_UP
) {
417 AuthenticatorActivity
.this.onViewPasswordClick();
423 findViewById(R
.id
.scroll
).setOnTouchListener(new OnTouchListener() {
425 public boolean onTouch(View view
, MotionEvent event
) {
426 if (event
.getAction() == MotionEvent
.ACTION_DOWN
) {
427 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
) &&
428 mHostUrlInput
.hasFocus()) {
436 mOperationsServiceConnection
= new OperationsServiceConnection();
437 bindService(new Intent(this, OperationsService
.class), mOperationsServiceConnection
, Context
.BIND_AUTO_CREATE
);
442 private void initAuthorizationMethod() {
443 boolean oAuthRequired
= false
;
444 boolean samlWebSsoRequired
= false
;
446 mAuthTokenType
= getIntent().getExtras().getString(AccountAuthenticator
.KEY_AUTH_TOKEN_TYPE
);
447 mAccount
= getIntent().getExtras().getParcelable(EXTRA_ACCOUNT
);
449 // TODO could be a good moment to validate the received token type, if not null
451 if (mAuthTokenType
== null
) {
452 if (mAccount
!= null
) {
453 /// same authentication method than the one used to create the account to update
454 oAuthRequired
= (mAccountMgr
.getUserData(mAccount
, Constants
.KEY_SUPPORTS_OAUTH2
) != null
);
455 samlWebSsoRequired
= (mAccountMgr
.getUserData(mAccount
, Constants
.KEY_SUPPORTS_SAML_WEB_SSO
) != null
);
458 /// use the one set in setup.xml
459 oAuthRequired
= AUTH_ON
.equals(getString(R
.string
.auth_method_oauth2
));
460 samlWebSsoRequired
= AUTH_ON
.equals(getString(R
.string
.auth_method_saml_web_sso
));
463 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType());
464 } else if (samlWebSsoRequired
) {
465 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType());
467 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypePass(MainApp
.getAccountType());
471 if (mAccount
!= null
) {
472 String userName
= mAccount
.name
.substring(0, mAccount
.name
.lastIndexOf('@'));
473 mUsernameInput
.setText(userName
);
476 mOAuth2Check
.setChecked(AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
));
481 * Saves relevant state before {@link #onPause()}
483 * Do NOT save {@link #mNewCapturedUriFromOAuth2Redirection}; it keeps a temporal flag, intended to defer the
484 * processing of the redirection caught in {@link #onNewIntent(Intent)} until {@link #onResume()}
486 * See {@link #loadSavedInstanceState(Bundle)}
489 protected void onSaveInstanceState(Bundle outState
) {
490 super.onSaveInstanceState(outState
);
492 /// connection state and info
493 outState
.putInt(KEY_AUTH_MESSAGE_VISIBILITY
, mAuthMessage
.getVisibility());
494 outState
.putString(KEY_AUTH_MESSAGE_TEXT
, mAuthMessage
.getText().toString());
495 outState
.putInt(KEY_SERVER_STATUS_TEXT
, mServerStatusText
);
496 outState
.putInt(KEY_SERVER_STATUS_ICON
, mServerStatusIcon
);
497 outState
.putBoolean(KEY_SERVER_VALID
, mServerIsValid
);
498 outState
.putBoolean(KEY_SERVER_CHECKED
, mServerIsChecked
);
499 outState
.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS
, (!mServerIsValid
&& mOcServerChkOperation
!= null
));
500 outState
.putBoolean(KEY_IS_SSL_CONN
, mIsSslConn
);
501 outState
.putBoolean(KEY_PASSWORD_VISIBLE
, isPasswordVisible());
502 outState
.putInt(KEY_AUTH_STATUS_ICON
, mAuthStatusIcon
);
503 outState
.putInt(KEY_AUTH_STATUS_TEXT
, mAuthStatusText
);
506 if (mDiscoveredVersion
!= null
) {
507 outState
.putString(KEY_OC_VERSION
, mDiscoveredVersion
.getVersion());
508 outState
.putString(KEY_OC_VERSION_STRING
, mDiscoveredVersion
.getVersionString());
510 outState
.putString(KEY_HOST_URL_TEXT
, mHostBaseUrl
);
512 /// account data, if updating
513 if (mAccount
!= null
) {
514 outState
.putParcelable(KEY_ACCOUNT
, mAccount
);
516 outState
.putString(AccountAuthenticator
.KEY_AUTH_TOKEN_TYPE
, mAuthTokenType
);
518 // refresh button enabled
519 outState
.putBoolean(KEY_REFRESH_BUTTON_ENABLED
, (mRefreshButton
.getVisibility() == View
.VISIBLE
));
525 * The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION request
528 * To make this possible, this activity needs to be qualified with android:launchMode = "singleTask" in the
529 * AndroidManifest.xml file.
532 protected void onNewIntent (Intent intent
) {
533 Log_OC
.d(TAG
, "onNewIntent()");
534 Uri data
= intent
.getData();
535 if (data
!= null
&& data
.toString().startsWith(getString(R
.string
.oauth2_redirect_uri
))) {
536 mNewCapturedUriFromOAuth2Redirection
= data
;
541 * The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION, and
542 * deferred in {@link #onNewIntent(Intent)}, is processed here.
545 protected void onResume() {
547 if (mAction
== ACTION_UPDATE_TOKEN
&& mJustCreated
&& getIntent().getBooleanExtra(EXTRA_ENFORCED_UPDATE
, false
)) {
548 if (AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
549 //Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show();
550 showAuthMessage(getString(R
.string
.auth_expired_oauth_token_toast
));
551 } else if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
552 //Toast.makeText(this, R.string.auth_expired_saml_sso_token_toast, Toast.LENGTH_LONG).show();
553 showAuthMessage(getString(R
.string
.auth_expired_saml_sso_token_toast
));
555 //Toast.makeText(this, R.string.auth_expired_basic_auth_toast, Toast.LENGTH_LONG).show();
556 showAuthMessage(getString(R
.string
.auth_expired_basic_auth_toast
));
560 if (mNewCapturedUriFromOAuth2Redirection
!= null
) {
561 getOAuth2AccessTokenFromCapturedRedirection();
564 mJustCreated
= false
;
570 protected void onDestroy() {
571 if (mOperationsConnection
!= null
) {
572 unbindService(mOperationsConnection
);
573 mOperationsBinder
= null
;
580 * Parses the redirection with the response to the GET AUTHORIZATION request to the
581 * oAuth server and requests for the access token (GET ACCESS TOKEN)
583 private void getOAuth2AccessTokenFromCapturedRedirection() {
584 /// Parse data from OAuth redirection
585 String queryParameters
= mNewCapturedUriFromOAuth2Redirection
.getQuery();
586 mNewCapturedUriFromOAuth2Redirection
= null
;
588 /// Showing the dialog with instructions for the user.
589 showDialog(DIALOG_OAUTH2_LOGIN_PROGRESS
);
591 /// GET ACCESS TOKEN to the oAuth server
592 RemoteOperation operation
= new OAuth2GetAccessToken( getString(R
.string
.oauth2_client_id
),
593 getString(R
.string
.oauth2_redirect_uri
),
594 getString(R
.string
.oauth2_grant_type
),
596 //OwnCloudClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());
597 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(Uri
.parse(mOAuthTokenEndpointText
.getText().toString().trim()), getApplicationContext(), true
);
598 operation
.execute(client
, this, mHandler
);
604 * Handles the change of focus on the text inputs for the server URL and the password
606 public void onFocusChange(View view
, boolean hasFocus
) {
607 if (view
.getId() == R
.id
.hostUrlInput
) {
609 onUrlInputFocusLost((TextView
) view
);
615 } else if (view
.getId() == R
.id
.account_password
) {
616 onPasswordFocusChanged((TextView
) view
, hasFocus
);
622 * Handles changes in focus on the text input for the server URL.
624 * IMPORTANT ENTRY POINT 2: When (!hasFocus), user wrote the server URL and changed to
625 * other field. The operation to check the existence of the server in the entered URL is
628 * When hasFocus: user 'comes back' to write again the server URL.
630 * @param hostInput TextView with the URL input field receiving the change of focus.
632 private void onUrlInputFocusLost(TextView hostInput
) {
633 if (!mHostBaseUrl
.equals(normalizeUrl(mHostUrlInput
.getText().toString()))) {
636 mOkButton
.setEnabled(mServerIsValid
);
637 if (!mServerIsValid
) {
644 private void checkOcServer() {
645 String uri
= trimUrlWebdav(mHostUrlInput
.getText().toString().trim());
647 if (!mHostUrlInputEnabled
){
648 uri
= getString(R
.string
.server_url
);
651 mServerIsValid
= false
;
652 mServerIsChecked
= false
;
653 mOkButton
.setEnabled(false
);
654 mDiscoveredVersion
= null
;
656 if (uri
.length() != 0) {
657 mServerStatusText
= R
.string
.auth_testing_connection
;
658 mServerStatusIcon
= R
.drawable
.progress_small
;
660 mOcServerChkOperation
= new GetRemoteStatusOperation(uri
, this);
661 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(Uri
.parse(uri
), this, true
);
662 mOperationThread
= mOcServerChkOperation
.execute(client
, this, mHandler
);
664 mServerStatusText
= 0;
665 mServerStatusIcon
= 0;
672 * Handles changes in focus on the text input for the password (basic authorization).
674 * When (hasFocus), the button to toggle password visibility is shown.
676 * When (!hasFocus), the button is made invisible and the password is hidden.
678 * @param passwordInput TextView with the password input field receiving the change of focus.
679 * @param hasFocus 'True' if focus is received, 'false' if is lost
681 private void onPasswordFocusChanged(TextView passwordInput
, boolean hasFocus
) {
683 showViewPasswordButton();
686 hidePasswordButton();
691 private void showViewPasswordButton() {
692 //int drawable = android.R.drawable.ic_menu_view;
693 int drawable
= R
.drawable
.ic_view
;
694 if (isPasswordVisible()) {
695 //drawable = android.R.drawable.ic_secure;
696 drawable
= R
.drawable
.ic_hide
;
698 mPasswordInput
.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable
, 0);
701 private boolean isPasswordVisible() {
702 return ((mPasswordInput
.getInputType() & InputType
.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
) == InputType
.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
);
705 private void hidePasswordButton() {
706 mPasswordInput
.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
709 private void showPassword() {
710 mPasswordInput
.setInputType(InputType
.TYPE_CLASS_TEXT
| InputType
.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
);
711 showViewPasswordButton();
714 private void hidePassword() {
715 mPasswordInput
.setInputType(InputType
.TYPE_CLASS_TEXT
| InputType
.TYPE_TEXT_VARIATION_PASSWORD
);
716 showViewPasswordButton();
721 * Cancels the authenticator activity
723 * IMPORTANT ENTRY POINT 3: Never underestimate the importance of cancellation
725 * This method is bound in the layout/acceoun_setup.xml resource file.
727 * @param view Cancel button
729 public void onCancelClick(View view
) {
730 setResult(RESULT_CANCELED
); // TODO review how is this related to AccountAuthenticator (debugging)
737 * Checks the credentials of the user in the root of the ownCloud server
738 * before creating a new local account.
740 * For basic authorization, a check of existence of the root folder is
743 * For OAuth, starts the flow to get an access token; the credentials test
744 * is postponed until it is available.
746 * IMPORTANT ENTRY POINT 4
748 * @param view OK button
750 public void onOkClick(View view
) {
751 // this check should be unnecessary
752 if (mDiscoveredVersion
== null
|| !mDiscoveredVersion
.isVersionValid() || mHostBaseUrl
== null
|| mHostBaseUrl
.length() == 0) {
753 mServerStatusIcon
= R
.drawable
.common_error
;
754 mServerStatusText
= R
.string
.auth_wtf_reenter_URL
;
756 mOkButton
.setEnabled(false
);
757 Log_OC
.wtf(TAG
, "The user was allowed to click 'connect' to an unchecked server!!");
761 if (AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
762 startOauthorization();
763 } else if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
764 startSamlBasedFederatedSingleSignOnAuthorization();
766 checkBasicAuthorization();
772 * Tests the credentials entered by the user performing a check of existence on
773 * the root folder of the ownCloud server.
775 private void checkBasicAuthorization() {
776 /// get the path to the root folder through WebDAV from the version server
777 String webdav_path
= AccountUtils
.getWebdavPath(mDiscoveredVersion
, mAuthTokenType
);
779 /// get basic credentials entered by user
780 String username
= mUsernameInput
.getText().toString();
781 String password
= mPasswordInput
.getText().toString();
783 /// be gentle with the user
784 showDialog(DIALOG_LOGIN_PROGRESS
);
786 /// test credentials accessing the root folder
787 mAuthCheckOperation
= new ExistenceCheckRemoteOperation("", this, false
);
788 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(Uri
.parse(mHostBaseUrl
+ webdav_path
), this, true
);
789 client
.setBasicCredentials(username
, password
);
790 mOperationThread
= mAuthCheckOperation
.execute(client
, this, mHandler
);
795 * Starts the OAuth 'grant type' flow to get an access token, with
796 * a GET AUTHORIZATION request to the BUILT-IN authorization server.
798 private void startOauthorization() {
799 // be gentle with the user
800 mAuthStatusIcon
= R
.drawable
.progress_small
;
801 mAuthStatusText
= R
.string
.oauth_login_connection
;
805 // GET AUTHORIZATION request
806 //Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth));
807 Uri uri
= Uri
.parse(mOAuthAuthEndpointText
.getText().toString().trim());
808 Uri
.Builder uriBuilder
= uri
.buildUpon();
809 uriBuilder
.appendQueryParameter(OAuth2Constants
.KEY_RESPONSE_TYPE
, getString(R
.string
.oauth2_response_type
));
810 uriBuilder
.appendQueryParameter(OAuth2Constants
.KEY_REDIRECT_URI
, getString(R
.string
.oauth2_redirect_uri
));
811 uriBuilder
.appendQueryParameter(OAuth2Constants
.KEY_CLIENT_ID
, getString(R
.string
.oauth2_client_id
));
812 uriBuilder
.appendQueryParameter(OAuth2Constants
.KEY_SCOPE
, getString(R
.string
.oauth2_scope
));
813 //uriBuilder.appendQueryParameter(OAuth2Constants.KEY_STATE, whateverwewant);
814 uri
= uriBuilder
.build();
815 Log_OC
.d(TAG
, "Starting browser to view " + uri
.toString());
816 Intent i
= new Intent(Intent
.ACTION_VIEW
, uri
);
822 * Starts the Web Single Sign On flow to get access to the root folder
825 private void startSamlBasedFederatedSingleSignOnAuthorization() {
826 // be gentle with the user
827 mAuthStatusIcon
= R
.drawable
.progress_small
;
828 mAuthStatusText
= R
.string
.auth_connecting_auth_server
;
830 showDialog(DIALOG_LOGIN_PROGRESS
);
832 /// get the path to the root folder through WebDAV from the version server
833 String webdav_path
= AccountUtils
.getWebdavPath(mDiscoveredVersion
, mAuthTokenType
);
835 /// test credentials accessing the root folder
836 mAuthCheckOperation
= new ExistenceCheckRemoteOperation("", this, false
);
837 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(Uri
.parse(mHostBaseUrl
+ webdav_path
), this, false
);
838 mOperationThread
= mAuthCheckOperation
.execute(client
, this, mHandler
);
843 * Callback method invoked when a RemoteOperation executed by this Activity finishes.
845 * Dispatches the operation flow to the right method.
848 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
850 if (operation
instanceof GetRemoteStatusOperation
) {
851 onOcServerCheckFinish((GetRemoteStatusOperation
) operation
, result
);
853 } else if (operation
instanceof OAuth2GetAccessToken
) {
854 onGetOAuthAccessTokenFinish((OAuth2GetAccessToken
)operation
, result
);
856 } else if (operation
instanceof ExistenceCheckRemoteOperation
) {
857 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
858 onSamlBasedFederatedSingleSignOnAuthorizationStart(operation
, result
);
861 onAuthorizationCheckFinish((ExistenceCheckRemoteOperation
)operation
, result
);
863 } else if (operation
instanceof GetRemoteUserNameOperation
) {
864 onGetUserNameFinish((GetRemoteUserNameOperation
) operation
, result
);
866 } else if (operation
instanceof DetectAuthenticationMethodOperation
) {
867 onDetectAutheticationFinish((DetectAuthenticationMethodOperation
) operation
, result
);
872 private void onDetectAutheticationFinish(DetectAuthenticationMethodOperation operation
, RemoteOperationResult result
) {
873 // Read authentication method
874 if (result
.getData().size() > 0) {
875 AuthenticationMethod authMethod
= (AuthenticationMethod
) result
.getData().get(0);
876 String basic
= AccountTypeUtils
.getAuthTokenTypePass(MainApp
.getAccountType());
877 String oAuth
= AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType());
878 String saml
= AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType());
880 if ( ( mAuthTokenType
.equals(basic
) && !authMethod
.equals(AuthenticationMethod
.BASIC_HTTP_AUTH
) ) ||
881 ( mAuthTokenType
.equals(oAuth
) && !authMethod
.equals(AuthenticationMethod
.BEARER_TOKEN
) ) ||
882 ( mAuthTokenType
.equals(saml
) && !authMethod
.equals(AuthenticationMethod
.SAML_WEB_SSO
) ) ) {
884 mOkButton
.setEnabled(false
);
885 mServerIsValid
= false
;
886 //show an alert message ( Server Status )
887 updateServerStatusIconNoRegularAuth();
891 mOkButton
.setEnabled(true
);
893 // Show server status
902 private void onGetUserNameFinish(GetRemoteUserNameOperation operation
, RemoteOperationResult result
) {
904 if (result
.isSuccess()) {
905 boolean success
= false
;
906 String username
= operation
.getUserName();
908 if ( mAction
== ACTION_CREATE
) {
909 mUsernameInput
.setText(username
);
910 success
= createAccount();
913 if (!mUsernameInput
.getText().toString().equals(username
)) {
914 // fail - not a new account, but an existing one; disallow
915 result
= new RemoteOperationResult(ResultCode
.ACCOUNT_NOT_THE_SAME
);
916 updateAuthStatusIconAndText(result
);
918 Log_OC
.d(TAG
, result
.getLogMessage());
928 updateStatusIconFailUserName();
930 Log_OC
.e(TAG
, "Access to user name failed: " + result
.getLogMessage());
935 private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperation operation
, RemoteOperationResult result
) {
937 dismissDialog(DIALOG_LOGIN_PROGRESS
);
938 } catch (IllegalArgumentException e
) {
939 // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens
942 //if (result.isTemporalRedirection() && result.isIdPRedirection()) {
943 if (result
.isIdPRedirection()) {
944 String url
= result
.getRedirectedLocation();
945 String targetUrl
= mHostBaseUrl
+ AccountUtils
.getWebdavPath(mDiscoveredVersion
, mAuthTokenType
);
948 mSamlDialog
= SamlWebViewDialog
.newInstance(url
, targetUrl
);
949 mSamlDialog
.show(getSupportFragmentManager(), TAG_SAML_DIALOG
);
955 mAuthStatusIcon
= R
.drawable
.common_error
;
956 mAuthStatusText
= R
.string
.auth_unsupported_auth_method
;
964 * Processes the result of the server check performed when the user finishes the enter of the
967 * @param operation Server check performed.
968 * @param result Result of the check.
970 private void onOcServerCheckFinish(GetRemoteStatusOperation operation
, RemoteOperationResult result
) {
971 if (operation
.equals(mOcServerChkOperation
)) {
972 /// save result state
973 mServerIsChecked
= true
;
974 mServerIsValid
= result
.isSuccess();
975 mIsSslConn
= (result
.getCode() == ResultCode
.OK_SSL
);
976 mOcServerChkOperation
= null
;
979 /// retrieve discovered version and normalize server URL
980 mDiscoveredVersion
= operation
.getDiscoveredVersion();
981 mHostBaseUrl
= normalizeUrl(mHostUrlInput
.getText().toString());
983 // Refresh server status, but don't show it
984 updateServerStatusIconAndText(result
);
986 /// update status icon and text
987 if (mServerIsValid
) {
989 // Try to create an account with user and pass "", to know if it is a regular server
990 // Update connect button in the answer of this method
991 detectAuthorizationMethod();
994 // Show server status
998 /// very special case (TODO: move to a common place for all the remote operations)
999 if (result
.getCode() == ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
) {
1000 showUntrustedCertDialog(result
);
1004 } // else nothing ; only the last check operation is considered;
1005 // multiple can be triggered if the user amends a URL before a previous check can be triggered
1010 * Try to access with user/pass ""/"", to know if it is a regular server
1012 private void detectAuthorizationMethod() {
1014 Log_OC
.d(TAG
, "Trying empty authorization to detect authentication method");
1016 String webdav_path
= AccountUtils
.getWebdavPath(mDiscoveredVersion
, mAuthTokenType
);
1018 /// test credentials
1019 Intent service
= new Intent(this, OperationsService
.class);
1020 service
.setAction(OperationsService
.ACTION_DETECT_AUTHENTICATION_METHOD
);
1021 service
.putExtra(OperationsService
.EXTRA_SERVER_URL
, mHostBaseUrl
);
1022 service
.putExtra(OperationsService
.EXTRA_WEBDAV_PATH
, webdav_path
);
1023 startService(service
);
1027 private String
normalizeUrl(String url
) {
1028 if (url
!= null
&& url
.length() > 0) {
1030 if (!url
.toLowerCase().startsWith("http://") &&
1031 !url
.toLowerCase().startsWith("https://")) {
1033 url
= "https://" + url
;
1035 url
= "http://" + url
;
1039 // OC-208: Add suffix remote.php/webdav to normalize (OC-34)
1040 url
= trimUrlWebdav(url
);
1042 if (url
.endsWith("/")) {
1043 url
= url
.substring(0, url
.length() - 1);
1047 return (url
!= null ? url
: "");
1051 private String
trimUrlWebdav(String url
){
1052 if(url
.toLowerCase().endsWith(AccountUtils
.WEBDAV_PATH_4_0
)){
1053 url
= url
.substring(0, url
.length() - AccountUtils
.WEBDAV_PATH_4_0
.length());
1054 } else if(url
.toLowerCase().endsWith(AccountUtils
.WEBDAV_PATH_2_0
)){
1055 url
= url
.substring(0, url
.length() - AccountUtils
.WEBDAV_PATH_2_0
.length());
1056 } else if (url
.toLowerCase().endsWith(AccountUtils
.WEBDAV_PATH_1_2
)){
1057 url
= url
.substring(0, url
.length() - AccountUtils
.WEBDAV_PATH_1_2
.length());
1059 return (url
!= null ? url
: "");
1064 * Chooses the right icon and text to show to the user for the received operation result.
1066 * @param result Result of a remote operation performed in this activity
1068 private void updateServerStatusIconAndText(RemoteOperationResult result
) {
1069 mServerStatusIcon
= R
.drawable
.common_error
; // the most common case in the switch below
1071 switch (result
.getCode()) {
1073 mServerStatusIcon
= android
.R
.drawable
.ic_secure
;
1074 mServerStatusText
= R
.string
.auth_secure_connection
;
1079 if (mHostUrlInput
.getText().toString().trim().toLowerCase().startsWith("http://") ) {
1080 mServerStatusText
= R
.string
.auth_connection_established
;
1081 mServerStatusIcon
= R
.drawable
.ic_ok
;
1083 mServerStatusText
= R
.string
.auth_nossl_plain_ok_title
;
1084 mServerStatusIcon
= android
.R
.drawable
.ic_partial_secure
;
1088 case NO_NETWORK_CONNECTION
:
1089 mServerStatusIcon
= R
.drawable
.no_network
;
1090 mServerStatusText
= R
.string
.auth_no_net_conn_title
;
1093 case SSL_RECOVERABLE_PEER_UNVERIFIED
:
1094 mServerStatusText
= R
.string
.auth_ssl_unverified_server_title
;
1096 case BAD_OC_VERSION
:
1097 mServerStatusText
= R
.string
.auth_bad_oc_version_title
;
1099 case WRONG_CONNECTION
:
1100 mServerStatusText
= R
.string
.auth_wrong_connection_title
;
1103 mServerStatusText
= R
.string
.auth_timeout_title
;
1105 case INCORRECT_ADDRESS
:
1106 mServerStatusText
= R
.string
.auth_incorrect_address_title
;
1109 mServerStatusText
= R
.string
.auth_ssl_general_error_title
;
1112 mServerStatusText
= R
.string
.auth_unauthorized
;
1114 case HOST_NOT_AVAILABLE
:
1115 mServerStatusText
= R
.string
.auth_unknown_host_title
;
1117 case INSTANCE_NOT_CONFIGURED
:
1118 mServerStatusText
= R
.string
.auth_not_configured_title
;
1120 case FILE_NOT_FOUND
:
1121 mServerStatusText
= R
.string
.auth_incorrect_path_title
;
1124 mServerStatusText
= R
.string
.auth_oauth_error
;
1126 case OAUTH2_ERROR_ACCESS_DENIED
:
1127 mServerStatusText
= R
.string
.auth_oauth_error_access_denied
;
1129 case UNHANDLED_HTTP_CODE
:
1131 mServerStatusText
= R
.string
.auth_unknown_error_title
;
1134 mServerStatusText
= 0;
1135 mServerStatusIcon
= 0;
1141 * Chooses the right icon and text to show to the user for the received operation result.
1143 * @param result Result of a remote operation performed in this activity
1145 private void updateAuthStatusIconAndText(RemoteOperationResult result
) {
1146 mAuthStatusIcon
= R
.drawable
.common_error
; // the most common case in the switch below
1148 switch (result
.getCode()) {
1150 mAuthStatusIcon
= android
.R
.drawable
.ic_secure
;
1151 mAuthStatusText
= R
.string
.auth_secure_connection
;
1156 if (mHostUrlInput
.getText().toString().trim().toLowerCase().startsWith("http://") ) {
1157 mAuthStatusText
= R
.string
.auth_connection_established
;
1158 mAuthStatusIcon
= R
.drawable
.ic_ok
;
1160 mAuthStatusText
= R
.string
.auth_nossl_plain_ok_title
;
1161 mAuthStatusIcon
= android
.R
.drawable
.ic_partial_secure
;
1165 case NO_NETWORK_CONNECTION
:
1166 mAuthStatusIcon
= R
.drawable
.no_network
;
1167 mAuthStatusText
= R
.string
.auth_no_net_conn_title
;
1170 case SSL_RECOVERABLE_PEER_UNVERIFIED
:
1171 mAuthStatusText
= R
.string
.auth_ssl_unverified_server_title
;
1173 case BAD_OC_VERSION
:
1174 mAuthStatusText
= R
.string
.auth_bad_oc_version_title
;
1176 case WRONG_CONNECTION
:
1177 mAuthStatusText
= R
.string
.auth_wrong_connection_title
;
1180 mAuthStatusText
= R
.string
.auth_timeout_title
;
1182 case INCORRECT_ADDRESS
:
1183 mAuthStatusText
= R
.string
.auth_incorrect_address_title
;
1186 mAuthStatusText
= R
.string
.auth_ssl_general_error_title
;
1189 mAuthStatusText
= R
.string
.auth_unauthorized
;
1191 case HOST_NOT_AVAILABLE
:
1192 mAuthStatusText
= R
.string
.auth_unknown_host_title
;
1194 case INSTANCE_NOT_CONFIGURED
:
1195 mAuthStatusText
= R
.string
.auth_not_configured_title
;
1197 case FILE_NOT_FOUND
:
1198 mAuthStatusText
= R
.string
.auth_incorrect_path_title
;
1201 mAuthStatusText
= R
.string
.auth_oauth_error
;
1203 case OAUTH2_ERROR_ACCESS_DENIED
:
1204 mAuthStatusText
= R
.string
.auth_oauth_error_access_denied
;
1206 case ACCOUNT_NOT_NEW
:
1207 mAuthStatusText
= R
.string
.auth_account_not_new
;
1209 case ACCOUNT_NOT_THE_SAME
:
1210 mAuthStatusText
= R
.string
.auth_account_not_the_same
;
1212 case UNHANDLED_HTTP_CODE
:
1214 mAuthStatusText
= R
.string
.auth_unknown_error_title
;
1217 mAuthStatusText
= 0;
1218 mAuthStatusIcon
= 0;
1223 private void updateStatusIconFailUserName(){
1224 mAuthStatusIcon
= R
.drawable
.common_error
;
1225 mAuthStatusText
= R
.string
.auth_fail_get_user_name
;
1228 private void updateServerStatusIconNoRegularAuth(){
1229 mServerStatusIcon
= R
.drawable
.common_error
;
1230 mServerStatusText
= R
.string
.auth_can_not_auth_against_server
;
1234 * Processes the result of the request for and access token send
1235 * to an OAuth authorization server.
1237 * @param operation Operation performed requesting the access token.
1238 * @param result Result of the operation.
1240 private void onGetOAuthAccessTokenFinish(OAuth2GetAccessToken operation
, RemoteOperationResult result
) {
1242 dismissDialog(DIALOG_OAUTH2_LOGIN_PROGRESS
);
1243 } catch (IllegalArgumentException e
) {
1244 // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens
1247 String webdav_path
= AccountUtils
.getWebdavPath(mDiscoveredVersion
, mAuthTokenType
);
1248 if (result
.isSuccess() && webdav_path
!= null
) {
1249 /// be gentle with the user
1250 showDialog(DIALOG_LOGIN_PROGRESS
);
1252 /// time to test the retrieved access token on the ownCloud server
1253 mAuthToken
= ((OAuth2GetAccessToken
)operation
).getResultTokenMap().get(OAuth2Constants
.KEY_ACCESS_TOKEN
);
1254 Log_OC
.d(TAG
, "Got ACCESS TOKEN: " + mAuthToken
);
1255 mAuthCheckOperation
= new ExistenceCheckRemoteOperation("", this, false
);
1256 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(Uri
.parse(mHostBaseUrl
+ webdav_path
), this, true
);
1257 client
.setBearerCredentials(mAuthToken
);
1258 mAuthCheckOperation
.execute(client
, this, mHandler
);
1261 updateAuthStatusIconAndText(result
);
1263 Log_OC
.d(TAG
, "Access failed: " + result
.getLogMessage());
1269 * Processes the result of the access check performed to try the user credentials.
1271 * Creates a new account through the AccountManager.
1273 * @param operation Access check performed.
1274 * @param result Result of the operation.
1276 private void onAuthorizationCheckFinish(ExistenceCheckRemoteOperation operation
, RemoteOperationResult result
) {
1278 dismissDialog(DIALOG_LOGIN_PROGRESS
);
1279 } catch (IllegalArgumentException e
) {
1280 // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens
1283 if (result
.isSuccess()) {
1284 Log_OC
.d(TAG
, "Successful access - time to save the account");
1286 boolean success
= false
;
1287 if (mAction
== ACTION_CREATE
) {
1288 success
= createAccount();
1299 } else if (result
.isServerFail() || result
.isException()) {
1300 /// if server fail or exception in authorization, the UI is updated as when a server check failed
1301 mServerIsChecked
= true
;
1302 mServerIsValid
= false
;
1304 mOcServerChkOperation
= null
;
1305 mDiscoveredVersion
= null
;
1306 mHostBaseUrl
= normalizeUrl(mHostUrlInput
.getText().toString());
1308 // update status icon and text
1309 updateServerStatusIconAndText(result
);
1311 mAuthStatusIcon
= 0;
1312 mAuthStatusText
= 0;
1315 // update input controls state
1316 showRefreshButton();
1317 mOkButton
.setEnabled(false
);
1319 // very special case (TODO: move to a common place for all the remote operations) (dangerous here?)
1320 if (result
.getCode() == ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
) {
1321 showUntrustedCertDialog(result
);
1324 } else { // authorization fail due to client side - probably wrong credentials
1325 updateAuthStatusIconAndText(result
);
1327 Log_OC
.d(TAG
, "Access failed: " + result
.getLogMessage());
1335 * Sets the proper response to get that the Account Authenticator that started this activity saves
1336 * a new authorization token for mAccount.
1338 private void updateToken() {
1339 Bundle response
= new Bundle();
1340 response
.putString(AccountManager
.KEY_ACCOUNT_NAME
, mAccount
.name
);
1341 response
.putString(AccountManager
.KEY_ACCOUNT_TYPE
, mAccount
.type
);
1343 if (AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1344 response
.putString(AccountManager
.KEY_AUTHTOKEN
, mAuthToken
);
1345 // the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention
1346 mAccountMgr
.setAuthToken(mAccount
, mAuthTokenType
, mAuthToken
);
1348 } else if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1350 response
.putString(AccountManager
.KEY_AUTHTOKEN
, mAuthToken
);
1351 // the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention
1352 mAccountMgr
.setAuthToken(mAccount
, mAuthTokenType
, mAuthToken
);
1355 response
.putString(AccountManager
.KEY_AUTHTOKEN
, mPasswordInput
.getText().toString());
1356 mAccountMgr
.setPassword(mAccount
, mPasswordInput
.getText().toString());
1358 setAccountAuthenticatorResult(response
);
1364 * Creates a new account through the Account Authenticator that started this activity.
1366 * This makes the account permanent.
1368 * TODO Decide how to name the OAuth accounts
1370 private boolean createAccount() {
1371 /// create and save new ownCloud account
1372 boolean isOAuth
= AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
);
1373 boolean isSaml
= AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
);
1375 Uri uri
= Uri
.parse(mHostBaseUrl
);
1376 String username
= mUsernameInput
.getText().toString().trim();
1378 username
= "OAuth_user" + (new java
.util
.Random(System
.currentTimeMillis())).nextLong();
1380 String accountName
= username
+ "@" + uri
.getHost();
1381 if (uri
.getPort() >= 0) {
1382 accountName
+= ":" + uri
.getPort();
1384 mAccount
= new Account(accountName
, MainApp
.getAccountType());
1385 if (AccountUtils
.exists(mAccount
, getApplicationContext())) {
1386 // fail - not a new account, but an existing one; disallow
1387 RemoteOperationResult result
= new RemoteOperationResult(ResultCode
.ACCOUNT_NOT_NEW
);
1388 updateAuthStatusIconAndText(result
);
1390 Log_OC
.d(TAG
, result
.getLogMessage());
1395 if (isOAuth
|| isSaml
) {
1396 mAccountMgr
.addAccountExplicitly(mAccount
, "", null
); // with external authorizations, the password is never input in the app
1398 mAccountMgr
.addAccountExplicitly(mAccount
, mPasswordInput
.getText().toString(), null
);
1401 /// add the new account as default in preferences, if there is none already
1402 Account defaultAccount
= AccountUtils
.getCurrentOwnCloudAccount(this);
1403 if (defaultAccount
== null
) {
1404 SharedPreferences
.Editor editor
= PreferenceManager
1405 .getDefaultSharedPreferences(this).edit();
1406 editor
.putString("select_oc_account", accountName
);
1410 /// prepare result to return to the Authenticator
1411 // TODO check again what the Authenticator makes with it; probably has the same effect as addAccountExplicitly, but it's not well done
1412 final Intent intent
= new Intent();
1413 intent
.putExtra(AccountManager
.KEY_ACCOUNT_TYPE
, MainApp
.getAccountType());
1414 intent
.putExtra(AccountManager
.KEY_ACCOUNT_NAME
, mAccount
.name
);
1416 intent.putExtra(AccountManager.KEY_AUTHTOKEN, MainApp.getAccountType()); */
1417 intent
.putExtra(AccountManager
.KEY_USERDATA
, username
);
1418 if (isOAuth
|| isSaml
) {
1419 mAccountMgr
.setAuthToken(mAccount
, mAuthTokenType
, mAuthToken
);
1421 /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA
1422 mAccountMgr
.setUserData(mAccount
, Constants
.KEY_OC_VERSION
, mDiscoveredVersion
.getVersion());
1423 mAccountMgr
.setUserData(mAccount
, Constants
.KEY_OC_VERSION_STRING
, mDiscoveredVersion
.getVersionString());
1424 mAccountMgr
.setUserData(mAccount
, Constants
.KEY_OC_BASE_URL
, mHostBaseUrl
);
1427 mAccountMgr
.setUserData(mAccount
, Constants
.KEY_SUPPORTS_SAML_WEB_SSO
, "TRUE");
1428 } else if (isOAuth
) {
1429 mAccountMgr
.setUserData(mAccount
, Constants
.KEY_SUPPORTS_OAUTH2
, "TRUE");
1432 setAccountAuthenticatorResult(intent
.getExtras());
1433 setResult(RESULT_OK
, intent
);
1443 * Necessary to update the contents of the SSL Dialog
1445 * TODO move to some common place for all possible untrusted SSL failures
1448 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
1450 case DIALOG_LOGIN_PROGRESS
:
1451 case DIALOG_CERT_NOT_SAVED
:
1452 case DIALOG_OAUTH2_LOGIN_PROGRESS
:
1455 Log_OC
.e(TAG
, "Incorrect dialog called with id = " + id
);
1464 protected Dialog
onCreateDialog(int id
) {
1465 Dialog dialog
= null
;
1467 case DIALOG_LOGIN_PROGRESS
: {
1468 /// simple progress dialog
1469 ProgressDialog working_dialog
= new ProgressDialog(this);
1470 working_dialog
.setMessage(getResources().getString(R
.string
.auth_trying_to_login
));
1471 working_dialog
.setIndeterminate(true
);
1472 working_dialog
.setCancelable(true
);
1474 .setOnCancelListener(new DialogInterface
.OnCancelListener() {
1476 public void onCancel(DialogInterface dialog
) {
1477 /// TODO study if this is enough
1478 Log_OC
.i(TAG
, "Login canceled");
1479 if (mOperationThread
!= null
) {
1480 mOperationThread
.interrupt();
1485 dialog
= working_dialog
;
1488 case DIALOG_OAUTH2_LOGIN_PROGRESS
: {
1489 ProgressDialog working_dialog
= new ProgressDialog(this);
1490 working_dialog
.setMessage(String
.format("Getting authorization"));
1491 working_dialog
.setIndeterminate(true
);
1492 working_dialog
.setCancelable(true
);
1494 .setOnCancelListener(new DialogInterface
.OnCancelListener() {
1496 public void onCancel(DialogInterface dialog
) {
1497 Log_OC
.i(TAG
, "Login canceled");
1501 dialog
= working_dialog
;
1504 case DIALOG_CERT_NOT_SAVED
: {
1505 AlertDialog
.Builder builder
= new AlertDialog
.Builder(this);
1506 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
1507 builder
.setCancelable(false
);
1508 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
1510 public void onClick(DialogInterface dialog
, int which
) {
1514 dialog
= builder
.create();
1518 Log_OC
.e(TAG
, "Incorrect dialog called with id = " + id
);
1525 * Starts and activity to open the 'new account' page in the ownCloud web site
1527 * @param view 'Account register' button
1529 public void onRegisterClick(View view
) {
1530 Intent register
= new Intent(Intent
.ACTION_VIEW
, Uri
.parse(getString(R
.string
.welcome_link_url
)));
1531 setResult(RESULT_CANCELED
);
1532 startActivity(register
);
1537 * Updates the content and visibility state of the icon and text associated
1538 * to the last check on the ownCloud server.
1540 private void showServerStatus() {
1541 TextView tv
= (TextView
) findViewById(R
.id
.server_status_text
);
1543 if (mServerStatusIcon
== 0 && mServerStatusText
== 0) {
1544 tv
.setVisibility(View
.INVISIBLE
);
1547 tv
.setText(mServerStatusText
);
1548 tv
.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon
, 0, 0, 0);
1549 tv
.setVisibility(View
.VISIBLE
);
1556 * Updates the content and visibility state of the icon and text associated
1557 * to the interactions with the OAuth authorization server.
1559 private void showAuthStatus() {
1560 if (mAuthStatusIcon
== 0 && mAuthStatusText
== 0) {
1561 mAuthStatusLayout
.setVisibility(View
.INVISIBLE
);
1564 mAuthStatusLayout
.setText(mAuthStatusText
);
1565 mAuthStatusLayout
.setCompoundDrawablesWithIntrinsicBounds(mAuthStatusIcon
, 0, 0, 0);
1566 mAuthStatusLayout
.setVisibility(View
.VISIBLE
);
1571 private void showRefreshButton() {
1572 mRefreshButton
.setVisibility(View
.VISIBLE
);
1575 private void hideRefreshButton() {
1576 mRefreshButton
.setVisibility(View
.GONE
);
1580 * Called when the refresh button in the input field for ownCloud host is clicked.
1582 * Performs a new check on the URL in the input field.
1584 * @param view Refresh 'button'
1586 public void onRefreshClick(View view
) {
1592 * Called when the eye icon in the password field is clicked.
1594 * Toggles the visibility of the password in the field.
1596 public void onViewPasswordClick() {
1597 int selectionStart
= mPasswordInput
.getSelectionStart();
1598 int selectionEnd
= mPasswordInput
.getSelectionEnd();
1599 if (isPasswordVisible()) {
1604 mPasswordInput
.setSelection(selectionStart
, selectionEnd
);
1609 * Called when the checkbox for OAuth authorization is clicked.
1611 * Hides or shows the input fields for user & password.
1613 * @param view 'View password' 'button'
1615 public void onCheckClick(View view
) {
1616 CheckBox oAuth2Check
= (CheckBox
)view
;
1617 if (oAuth2Check
.isChecked()) {
1618 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType());
1620 mAuthTokenType
= AccountTypeUtils
.getAuthTokenTypePass(MainApp
.getAccountType());
1622 adaptViewAccordingToAuthenticationMethod();
1627 * Changes the visibility of input elements depending on
1628 * the current authorization method.
1630 private void adaptViewAccordingToAuthenticationMethod () {
1631 if (AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1632 // OAuth 2 authorization
1633 mOAuthAuthEndpointText
.setVisibility(View
.VISIBLE
);
1634 mOAuthTokenEndpointText
.setVisibility(View
.VISIBLE
);
1635 mUsernameInput
.setVisibility(View
.GONE
);
1636 mPasswordInput
.setVisibility(View
.GONE
);
1638 } else if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1639 // SAML-based web Single Sign On
1640 mOAuthAuthEndpointText
.setVisibility(View
.GONE
);
1641 mOAuthTokenEndpointText
.setVisibility(View
.GONE
);
1642 mUsernameInput
.setVisibility(View
.GONE
);
1643 mPasswordInput
.setVisibility(View
.GONE
);
1645 // basic HTTP authorization
1646 mOAuthAuthEndpointText
.setVisibility(View
.GONE
);
1647 mOAuthTokenEndpointText
.setVisibility(View
.GONE
);
1648 mUsernameInput
.setVisibility(View
.VISIBLE
);
1649 mPasswordInput
.setVisibility(View
.VISIBLE
);
1654 * Called when the 'action' button in an IME is pressed ('enter' in software keyboard).
1656 * Used to trigger the authentication check when the user presses 'enter' after writing the password,
1657 * or to throw the server test when the only field on screen is the URL input field.
1660 public boolean onEditorAction(TextView inputField
, int actionId
, KeyEvent event
) {
1661 if (actionId
== EditorInfo
.IME_ACTION_DONE
&& inputField
!= null
&& inputField
.equals(mPasswordInput
)) {
1662 if (mOkButton
.isEnabled()) {
1663 mOkButton
.performClick();
1666 } else if (actionId
== EditorInfo
.IME_ACTION_NEXT
&& inputField
!= null
&& inputField
.equals(mHostUrlInput
)) {
1667 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
)) {
1671 return false
; // always return false to grant that the software keyboard is hidden anyway
1675 private abstract static class RightDrawableOnTouchListener
implements OnTouchListener
{
1677 private int fuzz
= 75;
1683 public boolean onTouch(View view
, MotionEvent event
) {
1684 Drawable rightDrawable
= null
;
1685 if (view
instanceof TextView
) {
1686 Drawable
[] drawables
= ((TextView
)view
).getCompoundDrawables();
1687 if (drawables
.length
> 2) {
1688 rightDrawable
= drawables
[2];
1691 if (rightDrawable
!= null
) {
1692 final int x
= (int) event
.getX();
1693 final int y
= (int) event
.getY();
1694 final Rect bounds
= rightDrawable
.getBounds();
1695 if (x
>= (view
.getRight() - bounds
.width() - fuzz
) && x
<= (view
.getRight() - view
.getPaddingRight() + fuzz
)
1696 && y
>= (view
.getPaddingTop() - fuzz
) && y
<= (view
.getHeight() - view
.getPaddingBottom()) + fuzz
) {
1698 return onDrawableTouch(event
);
1704 public abstract boolean onDrawableTouch(final MotionEvent event
);
1708 public void onSamlDialogSuccess(String sessionCookie
) {
1709 mAuthToken
= sessionCookie
;
1711 if (sessionCookie
!= null
&& sessionCookie
.length() > 0) {
1712 mAuthToken
= sessionCookie
;
1714 GetRemoteUserNameOperation getUserOperation
= new GetRemoteUserNameOperation();
1715 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(Uri
.parse(mHostBaseUrl
), getApplicationContext(), true
);
1716 client
.setSsoSessionCookie(mAuthToken
);
1717 getUserOperation
.execute(client
, this, mHandler
);
1725 public void onSsoFinished(String sessionCookies
) {
1726 //Toast.makeText(this, "got cookies: " + sessionCookie, Toast.LENGTH_LONG).show();
1728 if (sessionCookies
!= null
&& sessionCookies
.length() > 0) {
1729 Log_OC
.d(TAG
, "Successful SSO - time to save the account");
1730 onSamlDialogSuccess(sessionCookies
);
1731 Fragment fd
= getSupportFragmentManager().findFragmentByTag(TAG_SAML_DIALOG
);
1732 if (fd
!= null
&& fd
instanceof SherlockDialogFragment
) {
1733 Dialog d
= ((SherlockDialogFragment
)fd
).getDialog();
1734 if (d
!= null
&& d
.isShowing()) {
1741 Log_OC
.d(TAG
, "SSO failed");
1746 /** Show auth_message
1750 private void showAuthMessage(String message
) {
1751 mAuthMessage
.setVisibility(View
.VISIBLE
);
1752 mAuthMessage
.setText(message
);
1755 private void hideAuthMessage() {
1756 mAuthMessage
.setVisibility(View
.GONE
);
1760 public boolean onTouchEvent(MotionEvent event
) {
1761 if (AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType()).equals(mAuthTokenType
) &&
1762 mHostUrlInput
.hasFocus() && event
.getAction() == MotionEvent
.ACTION_DOWN
) {
1765 return super.onTouchEvent(event
);
1770 * Show untrusted cert dialog
1772 public void showUntrustedCertDialog(X509Certificate x509Certificate
, SslError error
, SslErrorHandler handler
) {
1773 // Show a dialog with the certificate info
1774 SslUntrustedCertDialog dialog
= null
;
1775 if (x509Certificate
== null
) {
1776 dialog
= SslUntrustedCertDialog
.newInstanceForEmptySslError(error
, handler
);
1778 dialog
= SslUntrustedCertDialog
.newInstanceForFullSslError(x509Certificate
, error
, handler
);
1780 FragmentManager fm
= getSupportFragmentManager();
1781 FragmentTransaction ft
= fm
.beginTransaction();
1782 ft
.addToBackStack(null
);
1783 dialog
.show(ft
, DIALOG_UNTRUSTED_CERT
);
1787 * Show untrusted cert dialog
1789 public void showUntrustedCertDialog(RemoteOperationResult result
) {
1790 // Show a dialog with the certificate info
1791 SslUntrustedCertDialog dialog
= SslUntrustedCertDialog
.newInstanceForFullSslError((CertificateCombinedException
)result
.getException());
1792 FragmentManager fm
= getSupportFragmentManager();
1793 FragmentTransaction ft
= fm
.beginTransaction();
1794 ft
.addToBackStack(null
);
1795 dialog
.show(ft
, DIALOG_UNTRUSTED_CERT
);
1800 * Dismiss untrusted cert dialog
1802 public void dismissUntrustedCertDialog(){
1803 /*Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_UNTRUSTED_CERT);
1805 SslErrorViewAdapter dialog = (SslErrorViewAdapter) frag;
1812 * Called from SslValidatorDialog when a new server certificate was correctly saved.
1814 public void onSavedCertificate() {
1815 Fragment fd
= getSupportFragmentManager().findFragmentByTag(TAG_SAML_DIALOG
);
1817 // if SAML dialog is not shown, the SslDialog was shown due to an SSL error in the server check
1823 * Called from SslValidatorDialog when a new server certificate could not be saved
1824 * when the user requested it.
1827 public void onFailedSavingCertificate() {
1828 showDialog(DIALOG_CERT_NOT_SAVED
);
1833 public void onCancelCertificate() {
1838 public void cancelWebView() {
1839 Fragment fd
= getSupportFragmentManager().findFragmentByTag(TAG_SAML_DIALOG
);
1840 if (fd
!= null
&& fd
instanceof SherlockDialogFragment
) {
1841 Dialog d
= ((SherlockDialogFragment
)fd
).getDialog();
1842 if (d
!= null
&& d
.isShowing()) {
1850 * Implements callback methods for service binding. Passed as a parameter to {
1852 private class OperationsServiceConnection
implements ServiceConnection
{
1855 public void onServiceConnected(ComponentName component
, IBinder service
) {
1856 if (component
.equals(new ComponentName(AuthenticatorActivity
.this, OperationsService
.class))) {
1857 Log_OC
.d(TAG
, "Operations service connected");
1858 mOperationsServiceBinder
= (OperationsServiceBinder
) service
;
1859 mOperationsServiceBinder
.addOperationListener(AuthenticatorActivity
.this, mHandler
);
1867 public void onServiceDisconnected(ComponentName component
) {
1868 if (component
.equals(new ComponentName(AuthenticatorActivity
.this, OperationsService
.class))) {
1869 Log_OC
.d(TAG
, "Operations service disconnected");
1870 mOperationsServiceBinder
= null
;
1871 // TODO whatever could be waiting for the service is unbound