Merge branch 'saml_based_federated_single_sign_on' into saml_based_federated_single_s...
authorDavid A. Velasco <dvelasco@solidgear.es>
Thu, 22 Aug 2013 15:50:11 +0000 (17:50 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Thu, 22 Aug 2013 15:50:11 +0000 (17:50 +0200)
1  2 
res/layout-land/account_setup.xml
res/layout/account_setup.xml
res/values/strings.xml
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/operations/RemoteOperationResult.java
src/eu/alefzero/webdav/WebdavClient.java

Simple merge
Simple merge
Simple merge
@@@ -231,9 -228,6 +235,8 @@@ implements  OnRemoteOperationListener, 
                  }\r
                  mHostBaseUrl = normalizeUrl(mAccountMgr.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL));\r
                  mHostUrlInput.setText(mHostBaseUrl);\r
-                 mAccountNameInput.setText(userName);\r
 +                String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
 +                mUsernameInput.setText(userName);\r
              }\r
              initAuthorizationMethod();  // checks intent and setup.xml to determine mCurrentAuthorizationMethod\r
              mJustCreated = true;\r
              accountName += ":" + uri.getPort();\r
          }\r
          mAccount = new Account(accountName, AccountAuthenticator.ACCOUNT_TYPE);\r
-         if (isOAuth || isSaml) {\r
-             mAccountMgr.addAccountExplicitly(mAccount, "", null);  // with external authorizations, the password is never input in the app\r
+         if (AccountUtils.exists(mAccount, getApplicationContext())) {\r
+             // fail - not a new account, but an existing one; disallow\r
+             RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW); \r
+             updateAuthStatusIconAndText(result);\r
+             showAuthStatus();\r
+             Log_OC.d(TAG, result.getLogMessage());\r
+             return false;\r
+             \r
+             \r
          } else {\r
-             mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);\r
-         }\r
\r
-         /// add the new account as default in preferences, if there is none already\r
-         Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);\r
-         if (defaultAccount == null) {\r
-             SharedPreferences.Editor editor = PreferenceManager\r
-                     .getDefaultSharedPreferences(this).edit();\r
-             editor.putString("select_oc_account", accountName);\r
-             editor.commit();\r
+         \r
+             if (isOAuth || isSaml) {\r
+                 mAccountMgr.addAccountExplicitly(mAccount, "", null);  // with external authorizations, the password is never input in the app\r
+             } else {\r
+                 mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);\r
+             }\r
+     \r
+             /// add the new account as default in preferences, if there is none already\r
+             Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);\r
+             if (defaultAccount == null) {\r
+                 SharedPreferences.Editor editor = PreferenceManager\r
+                         .getDefaultSharedPreferences(this).edit();\r
+                 editor.putString("select_oc_account", accountName);\r
+                 editor.commit();\r
+             }\r
+     \r
+             /// prepare result to return to the Authenticator\r
+             //  TODO check again what the Authenticator makes with it; probably has the same effect as addAccountExplicitly, but it's not well done\r
+             final Intent intent = new Intent();       \r
+             intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE,    AccountAuthenticator.ACCOUNT_TYPE);\r
+             intent.putExtra(AccountManager.KEY_ACCOUNT_NAME,    mAccount.name);\r
+             /*if (!isOAuth)\r
+                 intent.putExtra(AccountManager.KEY_AUTHTOKEN,   AccountAuthenticator.ACCOUNT_TYPE); */\r
+             intent.putExtra(AccountManager.KEY_USERDATA,        username);\r
+             if (isOAuth || isSaml) {\r
+                 mAccountMgr.setAuthToken(mAccount, mCurrentAuthTokenType, mAuthToken);\r
+             }\r
+             /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA\r
+             mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION,    mDiscoveredVersion.toString());\r
+             mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL,   mHostBaseUrl);\r
+             if (isSaml) {\r
+                 mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); \r
+             } else if (isOAuth) {\r
+                 mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_SUPPORTS_OAUTH2, "TRUE");  \r
+             }\r
+     \r
+             setAccountAuthenticatorResult(intent.getExtras());\r
+             setResult(RESULT_OK, intent);\r
+     \r
+             /// immediately request for the synchronization of the new account\r
+             Bundle bundle = new Bundle();\r
+             bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
+             ContentResolver.requestSync(mAccount, AccountAuthenticator.AUTHORITY, bundle);\r
++            syncAccount();\r
++//          Bundle bundle = new Bundle();\r
++//          bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
++//          ContentResolver.requestSync(mAccount, AccountAuthenticator.AUTHORITY, bundle);\r
+             return true;\r
          }\r
+     }\r
  \r
-         /// prepare result to return to the Authenticator\r
-         //  TODO check again what the Authenticator makes with it; probably has the same effect as addAccountExplicitly, but it's not well done\r
-         final Intent intent = new Intent();       \r
-         intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE,    AccountAuthenticator.ACCOUNT_TYPE);\r
-         intent.putExtra(AccountManager.KEY_ACCOUNT_NAME,    mAccount.name);\r
-         /*if (!isOAuth)\r
-             intent.putExtra(AccountManager.KEY_AUTHTOKEN,   AccountAuthenticator.ACCOUNT_TYPE); */\r
-         intent.putExtra(AccountManager.KEY_USERDATA,        username);\r
-         if (isOAuth || isSaml) {\r
-             mAccountMgr.setAuthToken(mAccount, mCurrentAuthTokenType, mAuthToken);\r
-         }\r
-         /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA\r
-         mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION,    mDiscoveredVersion.toString());\r
-         mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL,   mHostBaseUrl);\r
-         if (isSaml) {\r
-             mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); \r
-         } else if (isOAuth) {\r
-             mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_SUPPORTS_OAUTH2, "TRUE");  \r
+     \r
+     private String getUserNameForSamlSso() {\r
+         if (mAuthToken != null) {\r
+             String [] cookies = mAuthToken.split(";");\r
+             for (int i=0; i<cookies.length; i++) {\r
+                 if (cookies[i].startsWith(KEY_OC_USERNAME_EQUALS )) {\r
+                     String value = Uri.decode(cookies[i].substring(KEY_OC_USERNAME_EQUALS.length()));\r
+                     return value;\r
+                 }\r
+             }\r
          }\r
\r
-         setAccountAuthenticatorResult(intent.getExtras());\r
-         setResult(RESULT_OK, intent);\r
\r
-         /// immediately request for the synchronization of the new account\r
-         syncAccount();\r
- //        Bundle bundle = new Bundle();\r
- //        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
- //        ContentResolver.requestSync(mAccount, AccountAuthenticator.AUTHORITY, bundle);\r
+         return "";\r
      }\r
  \r
  \r
@@@ -99,10 -93,9 +99,10 @@@ public class WebdavClient extends HttpC
      
      public void setSsoSessionCookie(String accessToken) {
          getParams().setAuthenticationPreemptive(false);
-         getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
+         getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
          mSsoSessionCookie = accessToken;
          mCredentials = null;
 +        mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE;
      }