case ACCOUNT_NOT_NEW:\r
mAuthStatusText = R.string.auth_account_not_new;\r
break;\r
+ case ACCOUNT_NOT_THE_SAME:\r
+ mAuthStatusText = R.string.auth_account_not_the_same;\r
+ break;\r
case UNHANDLED_HTTP_CODE:\r
case UNKNOWN_ERROR:\r
mAuthStatusText = R.string.auth_unknown_error_title;\r
if (result.isSuccess()) {\r
Log_OC.d(TAG, "Successful access - time to save the account");\r
\r
- boolean success = true;\r
+ boolean success = false;\r
if (mAction == ACTION_CREATE) {\r
success = createAccount();\r
\r
} else {\r
- updateToken();\r
+ success = updateToken();\r
}\r
\r
if (success) {\r
* Sets the proper response to get that the Account Authenticator that started this activity saves \r
* a new authorization token for mAccount.\r
*/\r
- private void updateToken() {\r
+ private boolean updateToken() {\r
Bundle response = new Bundle();\r
response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);\r
response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);\r
mAccountMgr.setAuthToken(mAccount, mCurrentAuthTokenType, mAuthToken);\r
\r
} else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) {\r
+ String username = getUserNameForSamlSso();\r
+ if (!mUsernameInput.getText().toString().equals(username)) {\r
+ // fail - not a new account, but an existing one; disallow\r
+ RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME); \r
+ updateAuthStatusIconAndText(result);\r
+ showAuthStatus();\r
+ Log_OC.d(TAG, result.getLogMessage());\r
+ \r
+ return false;\r
+ }\r
+ \r
response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);\r
// the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention\r
mAccountMgr.setAuthToken(mAccount, mCurrentAuthTokenType, mAuthToken);\r
+ Log_OC.e(TAG, "saving auth token: " + mAuthToken);\r
\r
} else {\r
response.putString(AccountManager.KEY_AUTHTOKEN, mPasswordInput.getText().toString());\r
}\r
setAccountAuthenticatorResult(response);\r
\r
- // Sync Account\r
- syncAccount();\r
+ return true;\r
}\r
\r
\r
Log_OC.d(TAG, result.getLogMessage());\r
return false;\r
\r
- \r
} else {\r
\r
if (isOAuth || isSaml) {\r
intent.putExtra(AccountManager.KEY_USERDATA, username);\r
if (isOAuth || isSaml) {\r
mAccountMgr.setAuthToken(mAccount, mCurrentAuthTokenType, mAuthToken);\r
+ Log_OC.e(TAG, "saving auth token: " + 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
if (sessionCookie != null && sessionCookie.length() > 0) {\r
Log_OC.d(TAG, "Successful SSO - time to save the account");\r
mAuthToken = sessionCookie;\r
- boolean success = true;\r
+ boolean success = false;\r
if (mAction == ACTION_CREATE) {\r
success = createAccount();\r
\r
} else {\r
- updateToken();\r
+ success = updateToken();\r
}\r
if (success) {\r
finish();\r
} else if (isSamlSso) { // TODO avoid a call to getUserData here
String accessToken = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE, false);
client.setSsoSessionCookie(accessToken);
+ Log_OC.e(TAG, "client with auth token: " + accessToken);
} else {
String username = account.name.substring(0, account.name.lastIndexOf('@'));
String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
if (accessToken == null) throw new AuthenticatorException("WTF!");
client.setSsoSessionCookie(accessToken);
+ Log_OC.e(TAG, "client with auth token: " + accessToken);
} else {
String username = account.name.substring(0, account.name.lastIndexOf('@'));
public class RemoteOperationResult implements Serializable {
/** Generated - should be refreshed every time the class changes!! */
- private static final long serialVersionUID = 3267227833178885664L;
+ private static final long serialVersionUID = -4415103901492836870L;
private static final String TAG = "RemoteOperationResult";
QUOTA_EXCEEDED,
ACCOUNT_NOT_FOUND,
ACCOUNT_EXCEPTION,
- ACCOUNT_NOT_NEW
+ ACCOUNT_NOT_NEW,
+ ACCOUNT_NOT_THE_SAME
}
private boolean mSuccess = false;
} else if (mCode == ResultCode.ACCOUNT_NOT_NEW) {
return "Account already existing when creating a new one";
+
+ } else if (mCode == ResultCode.ACCOUNT_NOT_THE_SAME) {
+ return "Authenticated with a different account than the one updating";
}
return "Operation finished with HTTP status code " + mHttpCode + " (" + (isSuccess() ? "success" : "fail") + ")";
}
public boolean isIdPRedirection() {
- return (mRedirectedLocation.toUpperCase().contains("SAML") ||
- mRedirectedLocation.toLowerCase().contains("wayf"));
+ return (mRedirectedLocation != null &&
+ (mRedirectedLocation.toUpperCase().contains("SAML") ||
+ mRedirectedLocation.toLowerCase().contains("wayf")));
}
}
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
+import android.webkit.CookieSyncManager;
import android.webkit.WebBackForwardList;
import android.webkit.WebSettings;
import android.webkit.WebView;
public void onCreate(Bundle savedInstanceState) {
Log_OC.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
+
+ CookieSyncManager.createInstance(getActivity());
if (savedInstanceState == null) {
mInitialUrl = getArguments().getString(ARG_INITIAL_URL);