summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/se/leap/leapclient/ConfigHelper.java7
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java60
2 files changed, 33 insertions, 34 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java
index 7476c89a..8f38cbeb 100644
--- a/src/se/leap/leapclient/ConfigHelper.java
+++ b/src/se/leap/leapclient/ConfigHelper.java
@@ -32,6 +32,7 @@ public class ConfigHelper {
final static String downloadNewProviderDotJSON = "downloadNewProviderDotJSON";
public static final String srpRegister = "srpRegister";
final public static String srpAuth = "srpAuth";
+ public static String logOut = "logOut";
final public static String resultKey = "result";
final static String provider_key = "provider";
final static String cert_key = "cert";
@@ -53,8 +54,10 @@ public class ConfigHelper {
final public static int INCORRECTLY_DOWNLOADED_JSON_FILES = 2;
final public static int SRP_AUTHENTICATION_SUCCESSFUL = 3;
final public static int SRP_AUTHENTICATION_FAILED = 4;
- public static final int SRP_REGISTRATION_SUCCESSFUL = 5;
- public static final int SRP_REGISTRATION_FAILED = 6;
+ final public static int SRP_REGISTRATION_SUCCESSFUL = 5;
+ final public static int SRP_REGISTRATION_FAILED = 6;
+ final public static int LOGOUT_SUCCESSFUL = 7;
+ final public static int LOGOUT_FAILED = 8;
static void saveSharedPref(String shared_preferences_key, JSONObject content) {
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java
index 55686f70..d47e3b65 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -12,6 +12,7 @@ import java.util.Scanner;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
@@ -63,6 +64,12 @@ public class ProviderAPI extends IntentService {
else
receiver.send(ConfigHelper.SRP_AUTHENTICATION_FAILED, Bundle.EMPTY);
}
+ else if ((task = task_for.getBundleExtra(ConfigHelper.logOut)) != null) {
+ if(logOut(task))
+ receiver.send(ConfigHelper.LOGOUT_SUCCESSFUL, Bundle.EMPTY);
+ else
+ receiver.send(ConfigHelper.LOGOUT_FAILED, Bundle.EMPTY);
+ }
}
private boolean downloadJsonFiles(Bundle task) {
@@ -215,38 +222,6 @@ public class ProviderAPI extends IntentService {
}
}
- private boolean downloadJsonFilesBundleExtra(Bundle task) {
- //TODO task only contains provider main url -> we need to infer cert_url, provider_name and eip_service_json_url from that.
- String provider_main_url = (String) task.get(ConfigHelper.provider_main_url);
- String provider_name = ConfigHelper.extractProviderName(provider_main_url);
- String cert_url = (String) task.get(ConfigHelper.cert_key);
- String eip_service_json_url = (String) task.get(ConfigHelper.eip_service_key);
- try {
- //JSONObject provider_json = new JSONObject("{ \"provider\" : \"" + provider_name + "\"}");
- //ConfigHelper.saveSharedPref(ConfigHelper.provider_key, provider_json);
-
- /*String cert_string = getStringFromProvider(cert_url);
- JSONObject cert_json = new JSONObject("{ \"certificate\" : \"" + cert_string + "\"}");
- ConfigHelper.saveSharedPref(ConfigHelper.cert_key, cert_json);
- ConfigHelper.addTrustedCertificate(provider_name, cert_string);*/
- URL cacert = new URL(cert_url);
- ConfigHelper.addTrustedCertificate(provider_name, cacert.openStream());
- JSONObject eip_service_json = getJSONFromProvider(eip_service_json_url);
- ConfigHelper.saveSharedPref(ConfigHelper.eip_service_key, eip_service_json);
- return true;
- } catch (IOException e) {
- //TODO It could happen when the url is not valid.
- e.printStackTrace();
- return false;
- } catch (JSONException e) {
- ConfigHelper.rescueJSONException(e);
- return false;
- } catch(Exception e) {
- e.printStackTrace();
- return false;
- }
- }
-
private JSONObject downloadNewProviderDotJsonWithoutCert(
String provider_json_url) {
JSONObject provider_json = null;
@@ -284,8 +259,29 @@ public class ProviderAPI extends IntentService {
return json_file_content;
}
+
private JSONObject getJSONFromProvider(String json_url) throws IOException, JSONException {
String json_file_content = getStringFromProvider(json_url);
return new JSONObject(json_file_content);
}
+
+ private boolean logOut(Bundle task) {
+ DefaultHttpClient client = LeapHttpClient.getInstance(getApplicationContext());
+ int session_id_index = 0;
+ //String delete_url = task.getString(ConfigHelper.srp_server_url_key) + "/sessions/" + client.getCookieStore().getCookies().get(0).getValue();
+ String delete_url = task.getString(ConfigHelper.srp_server_url_key) + "/logout" + "?authenticity_token=" + client.getCookieStore().getCookies().get(session_id_index).getValue();
+ HttpDelete delete = new HttpDelete(delete_url);
+ try {
+ HttpResponse getResponse = client.execute(delete);
+ HttpEntity responseEntity = getResponse.getEntity();
+ responseEntity.consumeContent();
+ } catch (ClientProtocolException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return true;
+ }
}