import android.accounts.AccountManager;
import android.accounts.AccountsException;
import android.content.Context;
+import android.net.Uri;
public class AccountUtils {
public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php";
public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php";
public static final String CARDDAV_PATH_4_0 = "/remote/carddav.php";
public static final String STATUS_PATH = "/status.php";
+
+ // Key for UserName in Saml Cookie
+ private static final String KEY_OC_USERNAME_EQUALS = "oc_username=";
/**
*
return mFailedAccount;
}
}
+
+ /**
+ * Get the UserName for the SamlSso cookie
+ * @param authToken
+ * @return userName
+ */
+ public static String getUserNameForSamlSso(String authToken) {
+ if (authToken != null) {
+ String [] cookies = authToken.split(";");
+ for (int i=0; i<cookies.length; i++) {
+ if (cookies[i].startsWith(KEY_OC_USERNAME_EQUALS )) {
+ String value = Uri.decode(cookies[i].substring(KEY_OC_USERNAME_EQUALS.length()));
+ return value;
+ }
+ }
+ }
+ return "";
+ }
}
private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED";\r
\r
- private static final String KEY_OC_USERNAME_EQUALS = "oc_username=";\r
+ // TODO Remove it\r
+ //private static final String KEY_OC_USERNAME_EQUALS = "oc_username="; \r
\r
private static final String AUTH_ON = "on";\r
private static final String AUTH_OFF = "off";\r
mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);\r
\r
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {\r
- String username = getUserNameForSamlSso();\r
+ String username = com.owncloud.android.oc_framework.accounts.AccountUtils.getUserNameForSamlSso(mAuthToken);\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
Uri uri = Uri.parse(mHostBaseUrl);\r
String username = mUsernameInput.getText().toString().trim();\r
if (isSaml) {\r
- username = getUserNameForSamlSso();\r
+ username = com.owncloud.android.oc_framework.accounts.AccountUtils.getUserNameForSamlSso(mAuthToken);\r
\r
} else if (isOAuth) {\r
username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();\r
}\r
}\r
\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
- return "";\r
- }\r
+// TODO Remove it\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
+// return "";\r
+// }\r
\r
\r
/**\r