Login Testing

This commit is contained in:
Caesar2011
2018-12-17 16:14:50 +01:00
parent c807dda73c
commit cde5fc3582
8 changed files with 428 additions and 35 deletions

View File

@@ -9,6 +9,9 @@
<uses-permission <uses-permission
android:name="android.permission.MANAGE_ACCOUNTS" android:name="android.permission.MANAGE_ACCOUNTS"
android:maxSdkVersion="22" /> android:maxSdkVersion="22" />
<uses-permission
android:name="android.permission.USE_CREDENTIALS"
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- To auto-complete the email text field in the login form with the user's emails --> <!-- To auto-complete the email text field in the login form with the user's emails -->

View File

@@ -1,9 +1,12 @@
package de.sebse.fuplanner; package de.sebse.fuplanner;
import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture; import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@@ -16,6 +19,7 @@ import com.google.android.material.navigation.NavigationView;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
@@ -559,22 +563,49 @@ public class MainActivity extends AppCompatActivity
}); });
} }
private void getTokenForAccountCreateIfNeeded(String accountType, String authTokenType) { private void doInvalidateToken(String accountType, String authTokenType) {
final AccountManagerFuture<Bundle> future = mAccountManager.getAuthTokenByFeatures(accountType, authTokenType, null, this, null, null, //String token = mAccountManager.blockingGetAuthToken();
new AccountManagerCallback<Bundle>() { Account account = mAccountManager.getAccountsByType(accountType)[0];
@Override String token = null;
public void run(AccountManagerFuture<Bundle> future) { try {
Bundle bnd = null; token = mAccountManager.blockingGetAuthToken(account, authTokenType, true);
try { log.d("hihihi", accountType, authTokenType, token);
bnd = future.getResult(); mAccountManager.invalidateAuthToken(accountType, token);
final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN); } catch (AuthenticatorException e) {
showToast(((authtoken != null) ? "SUCCESS!\ntoken: " + authtoken : "FAIL")); e.printStackTrace();
log.d("udinic", "GetTokenForAccount Bundle is " + bnd); } catch (IOException e) {
e.printStackTrace();
} catch (OperationCanceledException e) {
e.printStackTrace();
}
}
} catch (Exception e) { private void deleteAccount(String accountType) {
e.printStackTrace(); Account[] accounts = mAccountManager.getAccountsByType(accountType);
showToast(e.getMessage()); int[] count = {accounts.length};
} for (Account account: accounts) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
mAccountManager.removeAccount(account, null, null, null);
} else {
mAccountManager.removeAccount(account, null, null);
}
}
}
private void getTokenForAccountCreateIfNeeded(String accountType, String authTokenType) {
deleteAccount(accountType);
final AccountManagerFuture<Bundle> future = mAccountManager.getAuthTokenByFeatures(accountType, authTokenType, null, this, null, null,
future1 -> {
Bundle bnd = null;
try {
bnd = future1.getResult();
final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
showToast(((authtoken != null) ? "SUCCESS!\ntoken: " + authtoken : "FAIL"));
log.d("udinic", "GetTokenForAccount Bundle is " + bnd);
} catch (Exception e) {
e.printStackTrace();
showToast(e.getMessage());
} }
} }
, null); , null);

View File

@@ -2,6 +2,9 @@ package de.sebse.fuplanner.services.KVV.types;
import android.content.Context; import android.content.Context;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@@ -118,4 +121,39 @@ public class LoginToken implements Serializable {
} }
return result.substring(0, result.length()-1); return result.substring(0, result.length()-1);
} }
public String toJsonString() {
JSONObject json = new JSONObject();
try {
json.put("username", username);
json.put("shibsessionKey", shibsessionKey);
json.put("shibsessionName", shibsessionName);
json.put("JSESSIONID", JSESSIONID);
json.put("fullName", fullName);
json.put("email", email);
} catch (JSONException e) {
return null;
}
return json.toString();
}
public static LoginToken fromJsonString(String tokenString) {
try {
JSONObject json = new JSONObject(tokenString);
LoginToken token = new LoginToken(
json.getString("username"),
json.getString("shibsessionName"),
json.getString("shibsessionName"),
json.getString("JSESSIONID"));
if (!json.isNull("fullName"))
token.setAdditionals(
json.getString("fullName"),
json.getString("email")
);
return token;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
} }

View File

@@ -57,7 +57,7 @@ public class FUAuthenticator extends AbstractAccountAuthenticator {
final String password = am.getPassword(account); final String password = am.getPassword(account);
if (password != null) { if (password != null) {
try { try {
authToken = new UserLoginTask(account.name, password, authTokenType, null).execute((Void) null).get(); authToken = new UserLoginTask(account.name, password, authTokenType, mContext).execute((Void) null).get();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ExecutionException e) { } catch (ExecutionException e) {

View File

@@ -6,18 +6,13 @@ import android.accounts.AccountManager;
import android.animation.Animator; import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Intent;
import android.content.pm.PackageManager;
import androidx.annotation.NonNull;
import android.app.LoaderManager.LoaderCallbacks; import android.app.LoaderManager.LoaderCallbacks;
import android.content.CursorLoader; import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader; import android.content.Loader;
import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.ContactsContract; import android.provider.ContactsContract;
@@ -35,6 +30,7 @@ import android.widget.TextView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import androidx.annotation.NonNull;
import de.sebse.fuplanner.R; import de.sebse.fuplanner.R;
import static de.sebse.fuplanner.services.newkvv.UserLoginTask.PARAM_USER_PASS; import static de.sebse.fuplanner.services.newkvv.UserLoginTask.PARAM_USER_PASS;
@@ -205,7 +201,7 @@ public class FUAuthenticatorActivity extends AccountAuthenticatorActivity implem
private boolean isEmailValid(String email) { private boolean isEmailValid(String email) {
//TODO: Replace this with your own logic //TODO: Replace this with your own logic
return email.contains("@"); return true;//email.contains("@");
} }
private boolean isPasswordValid(String password) { private boolean isPasswordValid(String password) {

View File

@@ -2,12 +2,21 @@ package de.sebse.fuplanner.services.newkvv;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import de.sebse.fuplanner.R; import de.sebse.fuplanner.R;
import de.sebse.fuplanner.services.KVV.types.LoginToken;
import de.sebse.fuplanner.services.newkvv.network.Login;
import de.sebse.fuplanner.tools.logging.Logger;
/** /**
@@ -20,37 +29,56 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
* A dummy authentication store containing known user names and passwords. * A dummy authentication store containing known user names and passwords.
* TODO: remove after connecting to a real authentication system. * TODO: remove after connecting to a real authentication system.
*/ */
private static final String[] DUMMY_CREDENTIALS = new String[]{ /*private static final String[] DUMMY_CREDENTIALS = new String[]{
"foo@example.com:hello", "bar@example.com:world" "foo@example.com:hello", "bar@example.com:world"
}; };*/
static final String PARAM_USER_PASS = "PARAM_USER_PASS"; static final String PARAM_USER_PASS = "PARAM_USER_PASS";
private final String mEmail; private final String mEmail;
private final String mPassword; private final String mPassword;
private final Login mVolleyLogin;
private String mTokenType; private String mTokenType;
private Logger log = new Logger(this);
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
@Nullable @Nullable
private FUAuthenticatorActivity mActivity; private FUAuthenticatorActivity mActivity;
UserLoginTask(String email, String password, String tokenType, @Nullable FUAuthenticatorActivity activity) { UserLoginTask(String email, String password, String tokenType, @NotNull Context context) {
mEmail = email; mEmail = email;
mPassword = password; mPassword = password;
mTokenType = tokenType; mTokenType = tokenType;
mActivity = activity; mVolleyLogin = new Login(context);
if (context instanceof FUAuthenticatorActivity)
mActivity = (FUAuthenticatorActivity) context;
} }
@Override @Override
protected String doInBackground(Void... params) { protected String doInBackground(Void... params) {
// TODO: attempt authentication against a network service. // TODO: attempt authentication against a network service.
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<LoginToken> login = new AtomicReference<>();
mVolleyLogin.doLogin(mEmail, mPassword, success -> {
mVolleyLogin.testLoginToken(success, success1 -> {
login.set(success);
latch.countDown();
}, error -> latch.countDown());
}, error -> latch.countDown());
try { try {
// Simulate network access. latch.await();
Thread.sleep(2000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
return null; e.printStackTrace();
} }
for (String credential : DUMMY_CREDENTIALS) { log.d(login.get());
if (login.get() == null) {
return null;
} else {
return login.get().toJsonString();
}
/*for (String credential : DUMMY_CREDENTIALS) {
String[] pieces = credential.split(":"); String[] pieces = credential.split(":");
if (pieces[0].equals(mEmail)) { if (pieces[0].equals(mEmail)) {
// Account exists, return true if the password matches. // Account exists, return true if the password matches.
@@ -59,7 +87,7 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
} }
// TODO: register the new account here. // TODO: register the new account here.
return null; return null;*/
} }
@Override @Override

View File

@@ -0,0 +1,297 @@
package de.sebse.fuplanner.services.newkvv.network;
import android.content.Context;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.sebse.fuplanner.services.KVV.types.LoginToken;
import de.sebse.fuplanner.tools.network.HTTPService;
import de.sebse.fuplanner.tools.network.NetworkCallback;
import de.sebse.fuplanner.tools.network.NetworkError;
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
public class Login extends HTTPService {
public Login(Context context) {
super(context);
}
public void testLoginToken(@NotNull LoginToken token, @NotNull NetworkCallback<LoginToken> callback, @NotNull NetworkErrorCallback errorCallback) {
get(String.format("https://kvv.imp.fu-berlin.de/direct/profile/%s.json", token.getUsername()), token.getCookies(), response -> {
String body = response.getParsed();
if (body == null) {
errorCallback.onError(new NetworkError(100172, 403, "Testing login failed!"));
return;
}
try {
JSONObject json = new JSONObject(body);
String displayName = json.getString("displayName");
String email = json.getString("email");
token.setAdditionals(displayName, email);
callback.onResponse(token);
} catch (JSONException e) {
errorCallback.onError(new NetworkError(100171, 403, "Cannot parse profile!"));
}
}, error -> errorCallback.onError(new NetworkError(100170, error.networkResponse.statusCode, "Testing login failed!")));
}
public void doLogin(String username, String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback error) {
startKVVSession(success -> {
String kvvJSESSIONID = success.get("JSESSIONID");
getSAMLRequest(kvvJSESSIONID, success1 -> startIdentSession(success1.get("Location"), success11 -> {
String identJSESSIONID = success11.get("JSESSIONID");
String ident_idp_authn_lc_key = success11.get("_idp_authn_lc_key");
String identROUTEID = success11.get("ROUTEID");
loginIdent(true, username, password, identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, success111 -> loginIdent(false, username, password, identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, success11112 -> {
String ident_idp_session = success11112.get("_idp_session");
getSAMLResponse(identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, ident_idp_session, success1111 -> loginKVV(success1111.get("RelayState"), success1111.get("SAMLResponse"), kvvJSESSIONID, success111112 -> {
LoginToken token = new LoginToken(username, success111112.get("shibsessionKey"), success111112.get("shibsessionName"), kvvJSESSIONID);
finishKVVlogin(token, success11111 -> callback.onResponse(token), error);
}, error), error);
}, error), error);
}, error), error);
}, error);
}
/*
GET https://kvv.imp.fu-berlin.de/portal/login
-> JSESSIONID 5c10406f-588c-4c16-96e9-c80d115417de.tomcat1
*/
private void startKVVSession(final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
get("https://kvv.imp.fu-berlin.de/portal/login", null, response -> {
String cookies = response.getHeaders().get("Set-Cookie");
if (cookies==null) {
errorCallback.onError(new NetworkError(100101, -1, "Error on starting KVV session!"));
return;
}
HashMap<String, String> object;
try {
object = getCookie(cookies, new String[]{"JSESSIONID"});
} catch (NoSuchFieldException e) {
errorCallback.onError(new NetworkError(100102, -1, "Error on starting KVV session!"));
return;
}
callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100100, error.networkResponse.statusCode, "Error on starting KVV session!")));
}
/*
GET https://kvv.imp.fu-berlin.de/sakai-login-tool/container
<- JSESSIONID
-> (Location-Header) https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO
?SAMLRequest=fZLLb.....Q8yre3X1IHwkJKE0Mnpy/V9TH4A
&RelayState=ss:mem:7ea01e29157b8bd906f7002176.....0d1a505f2c8bf
*/
private void getSAMLRequest(String JSESSIONID, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
HashMap<String, String> cookies = new HashMap<>();
cookies.put("JSESSIONID", JSESSIONID);
get("https://kvv.imp.fu-berlin.de/sakai-login-tool/container", cookies, response -> {
String location = response.getHeaders().get("Location");
if (location==null) {
errorCallback.onError(new NetworkError(100111, -1, "Error on getting SAML request!"));
return;
}
HashMap<String, String> object = new HashMap<>();
object.put("Location", location);
callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100110, error.networkResponse.statusCode, "Error on getting SAML request!")));
}
/*
GET https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO
?SAMLRequest=fZLLbsIwEEV/JfI+cWJAUIsgpbAoEi2IpF10UznxUKw6dupxaPn7hkdb2LD29bkzRzNGUeuGZ63fmjV8toA++K61QX58SEnrDLcCFXIjakDuK55njwvOopg3znpbWU2CDBGcV9ZMrcG2BpeD26kKnteLlGy9b5BT+rHbRapuok0bluC0MpEEmm9VWVoNfhshWnpgM7pa5gUJZt0wyogD9h+iJBiv/P6aomQTbtqSdhNtlIYzZg1SOag8zfMlCeazlLyNqpHsy1gO2V1fVsNBMuqJoUyAJaxXDUaiiyG2MDfohfEpYXEyDJM4ZKxgCe/FPI5fSbA6L36vjFTm/bal8hRC/lAUq/C02gs4PK7VBchkfHDNj8Xuwv5trPhVTiY3BeOf4DG96DmVNvypA89nK6tVtQ8yre3X1IHwkJKE0Mnpy/V9TH4A
&RelayState=ss:mem:7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf
-> JSESSIONID C4B6A428BA1F50746235D03F5D107A57
-> _idp_authn_lc_key 57a6ae26067f374cc3d0ccfc47e27b04b47752d2a3d4eb2782af0d3994535395
-> ROUTEID .1
*/
private void startIdentSession(String url, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
get(url, null, response -> {
String cookies = response.getHeaders().get("Set-Cookie");
if (cookies==null) {
errorCallback.onError(new NetworkError(100121, -1, "Error on starting Ident session!"));
return;
}
HashMap<String, String> object;
try {
object = getCookie(cookies, new String[]{"JSESSIONID", "_idp_authn_lc_key", "ROUTEID"});
} catch (NoSuchFieldException e) {
errorCallback.onError(new NetworkError(100122, -1, "Error on starting Ident session!"));
return;
}
callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100120, error.networkResponse.statusCode, "Error on starting Ident session!")));
}
/*
POST https://identity.fu-berlin.de/idp-fub/Authn/UserPassword
<- j_username seedorf96
<- j_password neinhieristpatrick
<- (Header-"Content-Type") application/x-www-form-urlencoded
<- JSESSIONID
<- _idp_authn_lc_key
<- ROUTEID
-> _idp_session OTMuMTkzLjg1LjMz|LQ==|OGYxOWI4MjA2NTQ4YWUwYzJkOWM4Mjk4YzcwZDMwZmJiZjBmMTdmMzkyZGU2OWIwY2JkNmZlNjlmNTRmNzBlMQ==|wLlzQal7VqyntmG2vLNn06wt8wQ=
*/
private void loginIdent(final boolean first, String username, String password, String JSESSIONID, String _idp_authn_lc_key, String ROUTEID, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
HashMap<String, String> cookies = new HashMap<>();
cookies.put("JSESSIONID", JSESSIONID);
cookies.put("_idp_authn_lc_key", _idp_authn_lc_key);
cookies.put("ROUTEID", ROUTEID);
HashMap<String, String> body = new HashMap<>();
body.put("j_username", username);
body.put("j_password", password);
post("https://identity.fu-berlin.de/idp-fub/Authn/UserPassword", cookies, body, response -> {
if (first) {
callback.onResponse(new HashMap<>());
return;
}
String cookies1 = response.getHeaders().get("Set-Cookie");
if (cookies1 ==null) {
errorCallback.onError(new NetworkError(100131, -1, "Error on logging in to Identity Server!"));
return;
}
HashMap<String, String> object;
try {
object = getCookie(cookies1, new String[]{"_idp_session"});
} catch (NoSuchFieldException e) {
errorCallback.onError(new NetworkError(100132, -1, "Error on logging in to Identity Server!"));
return;
}
callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100130, error.networkResponse.statusCode, "Error on logging in to Identity Server!")));
}
/*
GET https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO
<- JSESSIONID
<- _idp_authn_lc_key
<- ROUTEID
<- _idp_session
-> (BODY) RelayState 7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf
-> (BODY) SAMLResponse PD94bWwgdmVyc2lvbj0...........wvc2FtbDJwOlJlc3BvbnNlPg==
*/
private void getSAMLResponse(String JSESSIONID, String _idp_authn_lc_key, String ROUTEID, String _idp_session, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
HashMap<String, String> cookies = new HashMap<>();
cookies.put("JSESSIONID", JSESSIONID);
cookies.put("_idp_authn_lc_key", _idp_authn_lc_key);
cookies.put("ROUTEID", ROUTEID);
cookies.put("_idp_session", _idp_session);
get("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO", cookies, response -> {
String body = response.getParsed();
if (body == null) {
errorCallback.onError(new NetworkError(100143, -1, "Error on getting SAML response!"));
return;
}
HashMap<String, String> object = new HashMap<>();
Pattern pattern = Pattern.compile("ss&#x3a;mem&#x3a;([0-9a-f]+)");
Matcher matcher = pattern.matcher(body);
if (!matcher.find()) {
errorCallback.onError(new NetworkError(100142, -1, "Error on getting SAML response!"));
return;
}
object.put("RelayState", "ss:mem:"+matcher.group(1));
pattern = Pattern.compile("name=\"SAMLResponse\" value=\"([0-9a-zA-Z+]+=*)");
matcher = pattern.matcher(body);
if (!matcher.find()) {
errorCallback.onError(new NetworkError(100141, -1, "Error on getting SAML response!"));
return;
}
object.put("SAMLResponse", matcher.group(1));
callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100140, error.networkResponse.statusCode, "Error on getting SAML response!")));
}
/*
POST https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST
<- RelayState 7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf
<- SAMLResponse PD94bWwgdmVyc2lvbj0...........wvc2FtbDJwOlJlc3BvbnNlPg==
<- JSESSIONID
-> _shibsession_64656661756c7468747470733a2f2f6b76762e696d702e66752d6265726c696e2e64652f73686962626f6c657468
_b1912c5a03d733a80bd3fee772bf68d4
*/
private void loginKVV(String RelayState, String SAMLResponse, String JSESSIONID, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
HashMap<String, String> cookies = new HashMap<>();
cookies.put("JSESSIONID", JSESSIONID);
HashMap<String, String> body = new HashMap<>();
body.put("RelayState", RelayState);
body.put("SAMLResponse", SAMLResponse);
post("https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST", cookies, body, response -> {
String cookies1 = response.getHeaders().get("Set-Cookie");
if (cookies1 ==null) {
errorCallback.onError(new NetworkError(100151, -1, "Error on starting KVV session!"));
return;
}
HashMap<String, String> object = new HashMap<>();
Pattern pattern = Pattern.compile("(_shibsession_[0-9a-f]+)=([^;]+);");
Matcher matcher = pattern.matcher(cookies1);
if (!matcher.find()) {
errorCallback.onError(new NetworkError(100152, -1, "Error on starting Ident session!"));
}
object.put("shibsessionKey", matcher.group(1));
object.put("shibsessionName", matcher.group(2));
callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100150, error.networkResponse.statusCode, "Error on starting Ident session!")));
}
/*
GET https://kvv.imp.fu-berlin.de/sakai-login-tool/container
<- JSESSIONID
<- _shibsession_64656661756c7468747470733a2f2f6b76762e696d702e66752d6265726c696e2e64652f73686962626f6c657468
_b1912c5a03d733a80bd3fee772bf68d4
*/
private void finishKVVlogin(LoginToken loginToken, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
get("https://kvv.imp.fu-berlin.de/sakai-login-tool/container", loginToken.getCookies(), response -> callback.onResponse(new HashMap<>()), error -> errorCallback.onError(new NetworkError(100160, error.networkResponse.statusCode, "Cannot finish login process!")));
}
private String getCookie(String cookies, String name) throws NoSuchFieldException {
Pattern pattern = Pattern.compile(name+"=([^;]+);");
Matcher matcher = pattern.matcher(cookies);
if (!matcher.find()) {
log.e("GETcookie failed", name);
log.e("GETcookie failed", cookies);
throw new NoSuchFieldException();
}
return matcher.group(1);
}
private HashMap<String, String> getCookie(String cookies, String[] names) throws NoSuchFieldException {
HashMap<String, String> result = new HashMap<>();
for (String name: names) {
result.put(name,this.getCookie(cookies, name));
}
return result;
}
}

View File

@@ -31,7 +31,7 @@ public class HTTPService {
private final EventListener<VolleyError> errorResponseListener = new EventListener<>(); private final EventListener<VolleyError> errorResponseListener = new EventListener<>();
private final EventListener<Result> successResponseListener = new EventListener<>(); private final EventListener<Result> successResponseListener = new EventListener<>();
protected HTTPService(Context context) { public HTTPService(Context context) {
this.mContext = context; this.mContext = context;
requestQueue = Volley.newRequestQueue(context, new BetterHurlStack(false)); requestQueue = Volley.newRequestQueue(context, new BetterHurlStack(false));
} }