diff options
author | cyBerta <richy@cyborgsociety.org> | 2013-12-20 20:25:48 +0100 |
---|---|---|
committer | cyBerta <richy@cyborgsociety.org> | 2013-12-20 20:25:48 +0100 |
commit | 31e0ee7819ff6e852bc40f66858f0ac02659bf04 (patch) | |
tree | 85969d750a2473a95603e07f256681ca46c746cd /src/se/leap/bitmaskclient/ProviderAPI.java | |
parent | 8bc035e5785b8a14c26cdb6ab409242b66554992 (diff) | |
parent | c500f60c9188c938b550b8741ca9a4f4939429e4 (diff) |
Merge branch 'feature/token-based-auth' into develop
Conflicts:
src/se/leap/bitmaskclient/ConfigurationWizard.java
src/se/leap/bitmaskclient/Dashboard.java
src/se/leap/bitmaskclient/ProviderAPI.java
src/se/leap/bitmaskclient/ProviderListFragment.java
Diffstat (limited to 'src/se/leap/bitmaskclient/ProviderAPI.java')
-rw-r--r-- | src/se/leap/bitmaskclient/ProviderAPI.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java index 2a1cd29b..cc94edff 100644 --- a/src/se/leap/bitmaskclient/ProviderAPI.java +++ b/src/se/leap/bitmaskclient/ProviderAPI.java @@ -27,6 +27,7 @@ import java.net.CookieManager; import java.net.CookiePolicy; import java.net.MalformedURLException; import java.net.SocketTimeoutException; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; @@ -343,6 +344,9 @@ public class ProviderAPI extends IntentService { session_idAndM2.put(ConfigHelper.SESSION_ID_COOKIE_KEY, session_id_cookie.getName()); session_idAndM2.put(ConfigHelper.SESSION_ID_KEY, session_id_cookie.getValue());*/ session_idAndM2.put(LeapSRPSession.M2, ConfigHelper.trim(M2_not_trimmed)); + CookieHandler.setDefault(null); // we don't need cookies anymore + String token = json_response.getString(LeapSRPSession.TOKEN); + LeapSRPSession.setToken(token); } return session_idAndM2; } @@ -516,6 +520,8 @@ public class ProviderAPI extends IntentService { provider_url = new URL(string_url); URLConnection url_connection = provider_url.openConnection(); url_connection.setConnectTimeout(seconds_of_timeout*1000); + if(!LeapSRPSession.getToken().isEmpty()) + url_connection.addRequestProperty(LeapSRPSession.TOKEN, LeapSRPSession.getToken()); json_file_content = new Scanner(url_connection.getInputStream()).useDelimiter("\\A").next(); } catch (MalformedURLException e) { json_file_content = formatErrorMessage(R.string.malformed_url); @@ -551,6 +557,8 @@ public class ProviderAPI extends IntentService { HttpsURLConnection urlConnection = (HttpsURLConnection)url.openConnection(); urlConnection.setSSLSocketFactory(getProviderSSLSocketFactory()); + if(!LeapSRPSession.getToken().isEmpty()) + urlConnection.addRequestProperty(LeapSRPSession.TOKEN, LeapSRPSession.getToken()); json_file_content = new Scanner(urlConnection.getInputStream()).useDelimiter("\\A").next(); } catch (CertificateException e) { // TODO Auto-generated catch block @@ -670,6 +678,7 @@ public class ProviderAPI extends IntentService { int responseCode = urlConnection.getResponseCode(); broadcast_progress(progress++); + LeapSRPSession.setToken(""); Log.d("logout", Integer.toString(responseCode)); } catch (ClientProtocolException e) { // TODO Auto-generated catch block @@ -710,11 +719,14 @@ public class ProviderAPI extends IntentService { try { String type_of_certificate = task.getString(ConfigurationWizard.TYPE_OF_CERTIFICATE); JSONObject provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY); - URL provider_main_url = new URL(provider_json.getString(Provider.API_URL)); - String new_cert_string_url = provider_main_url.toString() + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.CERTIFICATE; + String provider_main_url = provider_json.getString(Provider.API_URL); + URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.CERTIFICATE); boolean danger_on = ConfigHelper.getBoolFromSharedPref(ProviderItem.DANGER_ON); - String cert_string = downloadWithProviderCA(new_cert_string_url, true); +//<<<<<<< HEAD +// String cert_string = downloadWithProviderCA(new_cert_string_url, true); +//======= + String cert_string = downloadWithProviderCA(new_cert_string_url.toString(), danger_on); if(!cert_string.isEmpty()) { if(ConfigHelper.checkErroneousDownload(cert_string)) { String reason_to_fail = provider_json.getString(ERRORS); |