7 Commits

Author SHA1 Message Date
Caesar2011
7d803777f8 Notifications added 2019-01-09 15:52:09 +01:00
Caesar2011
7cc0709133 New KVV login working 2019-01-09 14:58:08 +01:00
Caesar2011
21d247052d New KVV login preparation (works only via VPN or internal) 2019-01-09 01:22:13 +01:00
Caesar2011
57853eccf1 Sync notifications for announcements 2019-01-07 23:34:48 +01:00
Caesar2011
ceccd77f18 Periodic sync, reload from memory if outdated 2019-01-07 21:14:59 +01:00
Caesar2011
ae53e94108 Periodic sync, reload from memory if outdated 2019-01-07 14:59:48 +01:00
Caesar2011
786c001bbd unfinished code 2019-01-07 13:28:59 +01:00
23 changed files with 407 additions and 179 deletions

View File

@@ -7,8 +7,8 @@ android {
applicationId "de.sebse.fuplanner" applicationId "de.sebse.fuplanner"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 28 targetSdkVersion 28
versionCode 16 versionCode 19
versionName "1.3.5" versionName "1.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
@@ -34,7 +34,7 @@ dependencies {
}) })
implementation 'androidx.preference:preference:1.0.0' implementation 'androidx.preference:preference:1.0.0'
implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'com.android.volley:volley:1.1.0' implementation 'com.android.volley:volley:1.1.0'
//noinspection GradleDependency //noinspection GradleDependency
implementation 'com.google.android.gms:play-services-auth:15.0.0' implementation 'com.google.android.gms:play-services-auth:15.0.0'

View File

@@ -1,6 +1,8 @@
package de.sebse.fuplanner; package de.sebse.fuplanner;
import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.content.ContentResolver;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
@@ -39,13 +41,15 @@ import de.sebse.fuplanner.fragments.moddetails.ModDetailFragment;
import de.sebse.fuplanner.services.canteen.CanteenBrowser; import de.sebse.fuplanner.services.canteen.CanteenBrowser;
import de.sebse.fuplanner.services.canteen.types.Canteen; import de.sebse.fuplanner.services.canteen.types.Canteen;
import de.sebse.fuplanner.services.canteen.types.CanteenListener; import de.sebse.fuplanner.services.canteen.types.CanteenListener;
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
import de.sebse.fuplanner.services.kvv.KVV; import de.sebse.fuplanner.services.kvv.KVV;
import de.sebse.fuplanner.services.kvv.KVVListener; import de.sebse.fuplanner.services.kvv.KVVListener;
import de.sebse.fuplanner.services.kvv.sync.KVVContentProvider;
import de.sebse.fuplanner.services.kvv.types.LoginToken; import de.sebse.fuplanner.services.kvv.types.LoginToken;
import de.sebse.fuplanner.services.kvv.types.Modules; import de.sebse.fuplanner.services.kvv.types.Modules;
import de.sebse.fuplanner.services.news.NewsManager; import de.sebse.fuplanner.services.news.NewsManager;
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
import de.sebse.fuplanner.tools.CustomAccountManager; import de.sebse.fuplanner.tools.CustomAccountManager;
import de.sebse.fuplanner.tools.CustomNotificationManager;
import de.sebse.fuplanner.tools.MainActivityListener; import de.sebse.fuplanner.tools.MainActivityListener;
import de.sebse.fuplanner.tools.NewAsyncQueue; import de.sebse.fuplanner.tools.NewAsyncQueue;
import de.sebse.fuplanner.tools.Preferences; import de.sebse.fuplanner.tools.Preferences;
@@ -136,6 +140,12 @@ public class MainActivity extends AppCompatActivity
changeFragment(getDefaultFragmentAfterLogout()); changeFragment(getDefaultFragmentAfterLogout());
}); });
} }
if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup)) {
registerSync();
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true);
}
CustomNotificationManager.createNotificationChannel(this);
} }
@Override @Override
@@ -158,8 +168,11 @@ public class MainActivity extends AppCompatActivity
changeFragment(getDefaultFragmentAfterLogout()); changeFragment(getDefaultFragmentAfterLogout());
} }
}); });
getKVV().modules().list().reloadIfOutdated();
} }
isPaused = false; isPaused = false;
//log.d("onResume", "send notification!");
//CustomNotificationManager.sendNotification(this, "Titel", "Neue Announcements!");
} }
@Override @Override
@@ -348,6 +361,20 @@ public class MainActivity extends AppCompatActivity
((TextView) header.findViewById(R.id.login_mail)).setText(email); ((TextView) header.findViewById(R.id.login_mail)).setText(email);
changeFragment(newFragment); changeFragment(newFragment);
registerSync();
}
private void registerSync() {
Account accountByType = mAccountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
log.d("registerSync", accountByType);
if (accountByType != null) {
ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true);
ContentResolver.addPeriodicSync(
accountByType,
KVVContentProvider.PROVIDER_NAME,
Bundle.EMPTY,
AccountGeneral.SYNC_INTERVAL);
}
} }
private void changeFragment(int newFragment) { private void changeFragment(int newFragment) {

View File

@@ -4,4 +4,5 @@ public class AccountGeneral {
public static final String ACCOUNT_TYPE = "de.sebse.fuplanner.fuauth"; public static final String ACCOUNT_TYPE = "de.sebse.fuplanner.fuauth";
public static final String AUTHTOKEN_TYPE_KVV = "KVV"; public static final String AUTHTOKEN_TYPE_KVV = "KVV";
public static final String AUTHTOKEN_TYPE_BLACKBOARD = "Blackboard"; public static final String AUTHTOKEN_TYPE_BLACKBOARD = "Blackboard";
public static final long SYNC_INTERVAL = 6 * 60 * 60; // defined in seconds
} }

View File

@@ -62,8 +62,14 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
mVolleyLogin.testLoginToken(success, success1 -> { mVolleyLogin.testLoginToken(success, success1 -> {
login.set(success); login.set(success);
latch.countDown(); latch.countDown();
}, error -> latch.countDown()); }, error -> {
}, error -> latch.countDown()); log.e(error);
latch.countDown();
});
}, error -> {
log.e(error);
latch.countDown();
});
try { try {
latch.await(); latch.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@@ -46,6 +46,16 @@ public class ModulesList extends HTTPService {
return null; return null;
} }
public void reloadIfOutdated() {
try {
if (mModules != null && mModules.isNewerVersionInStorage(getContext())) {
restore();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void find(String moduleID, NetworkCallback<Modules.Module> moduleNetworkCallback, NetworkErrorCallback errorCallback) { public void find(String moduleID, NetworkCallback<Modules.Module> moduleNetworkCallback, NetworkErrorCallback errorCallback) {
find(moduleID, moduleNetworkCallback, errorCallback, RETRY_COUNT); find(moduleID, moduleNetworkCallback, errorCallback, RETRY_COUNT);
} }
@@ -115,10 +125,10 @@ public class ModulesList extends HTTPService {
this.upgrade(success -> { this.upgrade(success -> {
if (this.mModules == null) if (this.mModules == null)
this.mModules = success; this.mModules = success;
else else if(this.mModules.updateList(success)) {
this.mModules.updateList(success);
mListener.onModuleListChange(); mListener.onModuleListChange();
store(); store();
}
callback.onResponse(this.mModules); callback.onResponse(this.mModules);
mQueue.next(); mQueue.next();
}, error -> { }, error -> {

View File

@@ -11,7 +11,7 @@ import androidx.annotation.Nullable;
public class KVVContentProvider extends ContentProvider { public class KVVContentProvider extends ContentProvider {
private static final String PROVIDER_NAME = "de.sebse.fuplanner.contentprovider.kvv.modules"; public static final String PROVIDER_NAME = "de.sebse.fuplanner.contentprovider.kvv.modules";
private static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/modules"); private static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/modules");
private static final int MODULE = 1; private static final int MODULE = 1;
private static final int MODULE_ID = 2; private static final int MODULE_ID = 2;

View File

@@ -8,20 +8,31 @@ import android.content.Context;
import android.content.SyncResult; import android.content.SyncResult;
import android.os.Bundle; import android.os.Bundle;
import com.android.volley.NetworkResponse; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import androidx.annotation.StringRes;
import de.sebse.fuplanner.R;
import de.sebse.fuplanner.services.kvv.KVV; import de.sebse.fuplanner.services.kvv.KVV;
import de.sebse.fuplanner.services.kvv.KVVListener; import de.sebse.fuplanner.services.kvv.KVVListener;
import de.sebse.fuplanner.services.kvv.types.LoginToken; import de.sebse.fuplanner.services.kvv.types.Announcement;
import de.sebse.fuplanner.services.kvv.types.Assignment;
import de.sebse.fuplanner.services.kvv.types.AssignmentList;
import de.sebse.fuplanner.services.kvv.types.Event;
import de.sebse.fuplanner.services.kvv.types.EventList;
import de.sebse.fuplanner.services.kvv.types.Grade;
import de.sebse.fuplanner.services.kvv.types.Modules; import de.sebse.fuplanner.services.kvv.types.Modules;
import de.sebse.fuplanner.services.kvv.types.Resource;
import de.sebse.fuplanner.tools.CustomAccountManager; import de.sebse.fuplanner.tools.CustomAccountManager;
import de.sebse.fuplanner.tools.CustomNotificationManager;
import de.sebse.fuplanner.tools.NewAsyncQueue;
import de.sebse.fuplanner.tools.UtilsDate;
import de.sebse.fuplanner.tools.logging.Logger; import de.sebse.fuplanner.tools.logging.Logger;
public class KVVSyncAdapter extends AbstractThreadedSyncAdapter { public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
private KVV mKVV; private KVV mKVV;
private Logger log = new Logger(this); private Logger log = new Logger(this);
private NewAsyncQueue mQueue = new NewAsyncQueue();
/** /**
* Set up the sync adapter * Set up the sync adapter
@@ -53,7 +64,12 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
return accountManager; return accountManager;
} }
}, context); }, context);
mKVV.account().restoreOnlineLogin(bool -> {}); mQueue.add(() -> {
mKVV.account().restoreOnlineLogin(bool -> {
log.d("login restored");
mQueue.next();
});
});
} }
/* /*
@@ -68,20 +84,78 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
String authority, String authority,
ContentProviderClient provider, ContentProviderClient provider,
SyncResult syncResult) { SyncResult syncResult) {
log.d("onPerformSync");
mQueue.add(() -> {
log.d("start syncing"); log.d("start syncing");
/*
* Put the data transfer code here.
*/
mKVV.modules().list().recv(success -> { mKVV.modules().list().recv(success -> {
Iterator<Modules.Module> iterator = success.latestSemesterIterator(); Iterator<Modules.Module> iterator = success.latestSemesterIterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Modules.Module module = iterator.next(); Modules.Module module = iterator.next();
log.d("sync module", module.title); log.d("sync module", module.title);
final ArrayList<Announcement> announcements = module.announcements;
final AssignmentList assignments = module.assignments;
final EventList events = module.events;
final ArrayList<Grade> gradebook = module.gradebook;
final ArrayList<Resource> resources = module.resources;
mKVV.modules().details().recv(module, success1 -> { mKVV.modules().details().recv(module, success1 -> {
if (success1.second) if (success1.second) {
log.d("Sync Successful for Module '"+module.title+"'!"); log.d("Sync Successful for Module '"+module.title+"'!");
}, log::e, true); sendNotifications(announcements, module.announcements, module.title, Announcement::getTitle, Announcement::getId,
R.string.announcement_updated, R.string.announcement_added, R.string.announcement_removed);
sendNotifications(assignments, module.assignments, module.title, Assignment::getTitle, Assignment::getId,
R.string.assignment_updated, R.string.assignment_added, R.string.assignment_removed);
sendNotifications(events, module.events, module.title, evt -> evt.getTitle()+" - "+UtilsDate.getModifiedDate(evt.getStartDate()), Event::getId,
R.string.event_updated, R.string.event_added, R.string.event_removed);
sendNotifications(gradebook, module.gradebook, module.title, Grade::getItemName, Grade::getItemName,
R.string.gradebook_updated, R.string.gradebook_added, R.string.gradebook_removed);
sendNotifications(resources, module.resources, module.title, Resource::getTitle, Resource::getUrl,
R.string.resource_updated, R.string.resource_added, R.string.resource_removed);
mQueue.next();
} }
}, log::e, true); }, msg -> {
log.e(msg);
mQueue.next();
}, true);
}
}, msg -> {
log.e(msg);
mQueue.next();
}, true);
log.d("finished");
});
}
private <T> void sendNotifications(Iterable<T> oldList, Iterable<T> newList, String title, StringInterface<T> titleInterface, StringInterface<T> idInterface, @StringRes int updateRes, @StringRes int addRes, @StringRes int removeRes) {
if (oldList == null || newList == null) {
return;
}
ArrayList<T> obsoletes = new ArrayList<T>();
for (T old: oldList) {
obsoletes.add(old);
}
for (T newEntry: newList) {
boolean found = false;
for (T oldEntry: oldList) {
if (idInterface.get(newEntry).equals(idInterface.get(oldEntry))) {
found = true;
if (newEntry.hashCode() != oldEntry.hashCode()) {
CustomNotificationManager.sendNotification(getContext(), getContext().getString(updateRes, title), titleInterface.get(newEntry));
}
obsoletes.remove(oldEntry);
break;
}
}
if (!found) {
CustomNotificationManager.sendNotification(getContext(), getContext().getString(addRes, title), titleInterface.get(newEntry));
}
}
for (T oldEntry: obsoletes) {
CustomNotificationManager.sendNotification(getContext(), getContext().getString(removeRes, title), titleInterface.get(oldEntry));
}
}
@FunctionalInterface
interface StringInterface<T> {
String get(T element);
} }
} }

View File

@@ -56,56 +56,35 @@ public class Login extends HTTPService {
public void doLogin(String username, String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback error) { public void doLogin(String username, String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback error) {
startKVVSession(success -> { step1(success1 -> {
String kvvJSESSIONID = success.get("JSESSIONID"); String samlLocation = success1.get("Location");
getSAMLRequest(kvvJSESSIONID, success1 -> startIdentSession(success1.get("Location"), success11 -> { step2(samlLocation, success2 -> {
String identJSESSIONID = success11.get("JSESSIONID"); String fuJSESSIONID = success2.get("JSESSIONID");
String ident_idp_authn_lc_key = success11.get("_idp_authn_lc_key"); step3(fuJSESSIONID, success3 -> {
String identROUTEID = success11.get("ROUTEID"); step4(username, password, fuJSESSIONID, success4 -> {
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 fuSHIBSession = success4.get("shib_idp_session");
String ident_idp_session = success11112.get("_idp_session"); String samlResponse = success4.get("SAMLResponse");
getSAMLResponse(identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, ident_idp_session, success1111 -> loginKVV(success1111.get("RelayState"), success1111.get("SAMLResponse"), kvvJSESSIONID, success111112 -> { step5(samlResponse, success5 -> {
LoginToken token = new LoginToken(username, success111112.get("shibsessionKey"), success111112.get("shibsessionName"), kvvJSESSIONID); String shibsessionKey = success5.get("shibsessionKey");
finishKVVlogin(token, success11111 -> callback.onResponse(token), error); String shibsessionName = success5.get("shibsessionName");
}, error), error); step6(shibsessionKey, shibsessionName, success6 -> {
}, error), error); String kvvJSESSIONID = success6.get("JSESSIONID");
}, error), error); LoginToken token = new LoginToken(username, shibsessionKey, shibsessionName, kvvJSESSIONID);
callback.onResponse(token);
}, error);
}, error);
}, error);
}, error);
}, error);
}, error); }, error);
} }
/* /*
GET https://kvv.imp.fu-berlin.de/portal/login 1= GET https://kvv.imp.fu-berlin.de/Shibboleth.sso/Login?entityID=https://identity.fu-berlin.de/idp-fub
-> JSESSIONID 5c10406f-588c-4c16-96e9-c80d115417de.tomcat1 -> Location-Header: https://identity.fu-berlin.de:9443/idp-fub-qa/profile/SAML2/Redirect/SSO?SAMLResponse=[SAMLResponse]&RelayState=[RelayState]
*/ */
private void startKVVSession(final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) { private void step1(final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
get("https://kvv.imp.fu-berlin.de/portal/login", null, response -> { get("https://kvv.imp.fu-berlin.de/Shibboleth.sso/Login?entityID=https://identity.fu-berlin.de/idp-fub", 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"); String location = response.getHeaders().get("Location");
if (location==null) { if (location==null) {
errorCallback.onError(new NetworkError(100111, -1, "Error on getting SAML request!")); errorCallback.onError(new NetworkError(100111, -1, "Error on getting SAML request!"));
@@ -118,133 +97,98 @@ public class Login extends HTTPService {
} }
/* /*
GET https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO 2= GET [Location-Header 1]
?SAMLRequest=fZLLbsIwEEV/JfI+cWJAUIsgpbAoEi2IpF10UznxUKw6dupxaPn7hkdb2LD29bkzRzNGUeuGZ63fmjV8toA++K61QX58SEnrDLcCFXIjakDuK55njwvOopg3znpbWU2CDBGcV9ZMrcG2BpeD26kKnteLlGy9b5BT+rHbRapuok0bluC0MpEEmm9VWVoNfhshWnpgM7pa5gUJZt0wyogD9h+iJBiv/P6aomQTbtqSdhNtlIYzZg1SOag8zfMlCeazlLyNqpHsy1gO2V1fVsNBMuqJoUyAJaxXDUaiiyG2MDfohfEpYXEyDJM4ZKxgCe/FPI5fSbA6L36vjFTm/bal8hRC/lAUq/C02gs4PK7VBchkfHDNj8Xuwv5trPhVTiY3BeOf4DG96DmVNvypA89nK6tVtQ8yre3X1IHwkJKE0Mnpy/V9TH4A -> Set-Cookie: JSESSIONID=[JSESSION-FU]
&RelayState=ss:mem:7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf -> Location: /idp-fub-qa/profile/SAML2/Redirect/SSO?execution=e1s1
-> JSESSIONID C4B6A428BA1F50746235D03F5D107A57
-> _idp_authn_lc_key 57a6ae26067f374cc3d0ccfc47e27b04b47752d2a3d4eb2782af0d3994535395
-> ROUTEID .1
*/ */
private void startIdentSession(String url, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) { private void step2(String url, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
get(url, null, response -> { get(url, null, response -> {
String cookies = response.getHeaders().get("Set-Cookie"); String cookies = response.getHeaders().get("Set-Cookie");
if (cookies==null) { if (cookies==null) {
errorCallback.onError(new NetworkError(100121, -1, "Error on starting Ident session!")); errorCallback.onError(new NetworkError(100121, -1, "Error on starting FU session!"));
return; return;
} }
HashMap<String, String> object; HashMap<String, String> object;
try { try {
object = getCookie(cookies, new String[]{"JSESSIONID", "_idp_authn_lc_key", "ROUTEID"}); object = getCookie(cookies, new String[]{"JSESSIONID"});
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
errorCallback.onError(new NetworkError(100122, -1, "Error on starting Ident session!")); errorCallback.onError(new NetworkError(100122, -1, "Error on starting FU session!"));
return; return;
} }
callback.onResponse(object); callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100120, error.networkResponse.statusCode, "Error on starting Ident session!"))); }, error -> errorCallback.onError(new NetworkError(100120, error.networkResponse.statusCode, "Error on starting FU session!")));
} }
/* /*
POST https://identity.fu-berlin.de/idp-fub/Authn/UserPassword 3= GET [Location-Header 2]
<- j_username seedorf96 + Cookie: JSESSIONID=[JSESSION-FU]
<- 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) { private void step3(String JSESSIONID_FU, final NetworkCallback<Boolean> callback, final NetworkErrorCallback errorCallback) {
HashMap<String, String> cookies = new HashMap<>(); HashMap<String, String> cookies = new HashMap<>();
cookies.put("JSESSIONID", JSESSIONID); cookies.put("JSESSIONID", JSESSIONID_FU);
cookies.put("_idp_authn_lc_key", _idp_authn_lc_key); get("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO?execution=e1s1", cookies, response -> {
cookies.put("ROUTEID", ROUTEID); callback.onResponse(true);
}, error -> errorCallback.onError(new NetworkError(100130, error.networkResponse.statusCode, "Error starting login page!")));
}
/*
4= POST [Location-Header 2]
+ Body: j_username=[USERNAME]&j_password=[PASSWORD]&_eventId_proceed=
+ Header: Content-Type: application/x-www-form-urlencoded
+ Header: Referer: [Location-Header 2]
+ Cookie: JSESSIONID=[JSESSION-FU]
-> Set-Cookie: shib_idp_session=[SHIB-IDP-SESSION]
-> Body SAMLResponse-Input-value
*/
private void step4(String username, String password, String JSESSIONID_FU, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
HashMap<String, String> cookies = new HashMap<>();
cookies.put("JSESSIONID", JSESSIONID_FU);
HashMap<String, String> body = new HashMap<>(); HashMap<String, String> body = new HashMap<>();
body.put("j_username", username); body.put("j_username", username);
body.put("j_password", password); body.put("j_password", password);
post("https://identity.fu-berlin.de/idp-fub/Authn/UserPassword", cookies, body, response -> { body.put("_eventId_proceed", "");
if (first) { post("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO?execution=e1s1", cookies, body, response -> {
callback.onResponse(new HashMap<>());
return;
}
String cookies1 = response.getHeaders().get("Set-Cookie"); String cookies1 = response.getHeaders().get("Set-Cookie");
if (cookies1 ==null) { if (cookies1 ==null) {
errorCallback.onError(new NetworkError(100131, -1, "Error on logging in to Identity Server!")); errorCallback.onError(new NetworkError(100141, -1, "Error on logging in to FU Identity Server!"));
return; return;
} }
HashMap<String, String> object; HashMap<String, String> object;
try { try {
object = getCookie(cookies1, new String[]{"_idp_session"}); object = getCookie(cookies1, new String[]{"shib_idp_session"});
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
errorCallback.onError(new NetworkError(100132, -1, "Error on logging in to Identity Server!")); errorCallback.onError(new NetworkError(100142, -1, "Error on logging in to FU Identity Server!"));
return; return;
} }
callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100130, error.networkResponse.statusCode, "Error on logging in to Identity Server!")));
}
/* String content = response.getParsed();
GET https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO if (content == null) {
<- 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!")); errorCallback.onError(new NetworkError(100143, -1, "Error on getting SAML response!"));
return; return;
} }
Pattern pattern = Pattern.compile("name=\"SAMLResponse\" value=\"([0-9a-zA-Z+]+=*)");
HashMap<String, String> object = new HashMap<>(); Matcher matcher = pattern.matcher(content);
Pattern pattern = Pattern.compile("ss&#x3a;mem&#x3a;([0-9a-f]+)");
Matcher matcher = pattern.matcher(body);
if (!matcher.find()) { if (!matcher.find()) {
errorCallback.onError(new NetworkError(100142, -1, "Error on getting SAML response!")); errorCallback.onError(new NetworkError(100144, -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; return;
} }
object.put("SAMLResponse", matcher.group(1)); object.put("SAMLResponse", matcher.group(1));
callback.onResponse(object); callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100140, error.networkResponse.statusCode, "Error on getting SAML response!"))); }, error -> errorCallback.onError(new NetworkError(100145, error.networkResponse.statusCode, "Error on logging in to FU Identity Server!")));
} }
/* /*
POST https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST 5= POST https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST
<- RelayState 7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf + Body: SAMLResponse=[SAML-RESPONSE]
<- SAMLResponse PD94bWwgdmVyc2lvbj0...........wvc2FtbDJwOlJlc3BvbnNlPg== + Header: Content-Type: application/x-www-form-urlencoded
<- JSESSIONID -> Set-Cookie: _shibsession_[SESS-NR]: [SESS-VALUE]
-> _shibsession_64656661756c7468747470733a2f2f6b76762e696d702e66752d6265726c696e2e64652f73686962626f6c657468
_b1912c5a03d733a80bd3fee772bf68d4
*/ */
private void loginKVV(String RelayState, String SAMLResponse, String JSESSIONID, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) { private void step5(String SAMLResponse, 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<>(); HashMap<String, String> body = new HashMap<>();
body.put("RelayState", RelayState);
body.put("SAMLResponse", SAMLResponse); body.put("SAMLResponse", SAMLResponse);
post("https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST", cookies, body, response -> { post("https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST", null, body, response -> {
String cookies1 = response.getHeaders().get("Set-Cookie"); String cookies = response.getHeaders().get("Set-Cookie");
if (cookies1 ==null) { if (cookies ==null) {
errorCallback.onError(new NetworkError(100151, -1, "Error on starting KVV session!")); errorCallback.onError(new NetworkError(100151, -1, "Error on starting KVV session!"));
return; return;
} }
@@ -252,26 +196,41 @@ public class Login extends HTTPService {
Pattern pattern = Pattern.compile("(_shibsession_[0-9a-f]+)=([^;]+);"); Pattern pattern = Pattern.compile("(_shibsession_[0-9a-f]+)=([^;]+);");
Matcher matcher = pattern.matcher(cookies1); Matcher matcher = pattern.matcher(cookies);
if (!matcher.find()) { if (!matcher.find()) {
errorCallback.onError(new NetworkError(100152, -1, "Error on starting Ident session!")); errorCallback.onError(new NetworkError(100152, -1, "Error on starting KVV session!"));
} }
object.put("shibsessionKey", matcher.group(1)); object.put("shibsessionKey", matcher.group(1));
object.put("shibsessionName", matcher.group(2)); object.put("shibsessionName", matcher.group(2));
callback.onResponse(object); callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100150, error.networkResponse.statusCode, "Error on starting Ident session!"))); }, error -> errorCallback.onError(new NetworkError(100150, error.networkResponse.statusCode, "Error on starting KVV session!")));
} }
/* /*
GET https://kvv.imp.fu-berlin.de/sakai-login-tool/container 6= https://kvv.imp.fu-berlin.de/sakai-login-tool/container
<- JSESSIONID + Cookie: _shibsession_[SESS-NR]: [SESS-VALUE]
<- _shibsession_64656661756c7468747470733a2f2f6b76762e696d702e66752d6265726c696e2e64652f73686962626f6c657468 -> Set-Cookie: JSESSIONID: [JSESSION-KVV]
_b1912c5a03d733a80bd3fee772bf68d4
*/ */
private void finishKVVlogin(LoginToken loginToken, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) { private void step6(String shibsessionKey, String shibsessionName, 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!"))); HashMap<String, String> cookies = new HashMap<>();
cookies.put(shibsessionKey, shibsessionName);
get("https://kvv.imp.fu-berlin.de/sakai-login-tool/container", cookies, response -> {
String cookies1 = response.getHeaders().get("Set-Cookie");
if (cookies1 ==null) {
errorCallback.onError(new NetworkError(100161, -1, "Cannot finish login process!"));
return;
}
HashMap<String, String> object;
try {
object = getCookie(cookies1, new String[]{"JSESSIONID"});
} catch (NoSuchFieldException e) {
errorCallback.onError(new NetworkError(100162, -1, "Cannot finish login process!"));
return;
}
callback.onResponse(object);
}, error -> errorCallback.onError(new NetworkError(100160, error.networkResponse.statusCode, "Cannot finish login process!")));
} }

View File

@@ -28,7 +28,7 @@ public class Announcement implements Serializable {
return urls; return urls;
} }
private String getId() { public String getId() {
return id; return id;
} }

View File

@@ -22,7 +22,7 @@ public class Assignment implements Serializable {
this.instructions = instructions; this.instructions = instructions;
} }
private String getId() { public String getId() {
return id; return id;
} }

View File

@@ -2,6 +2,8 @@ package de.sebse.fuplanner.services.kvv.types;
import android.content.Context; import android.content.Context;
import com.google.android.gms.common.internal.Objects;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -25,8 +27,10 @@ import androidx.annotation.Nullable;
public class Modules implements Iterable<Modules.Module>, Serializable { public class Modules implements Iterable<Modules.Module>, Serializable {
private SortedListModule list; private SortedListModule list;
private final String mUsername; private final String mUsername;
private transient long mLastTimestamp = 0;
//private transient Logger log = new Logger(this); //private transient Logger log = new Logger(this);
private static final String FILE_NAME = "ModuleListSaving"; private static final String FILE_NAME = "ModuleListSaving";
private static final String FILE_NAME_TIMESTAMP = "ModuleListSavingTimestamp";
public Modules(String username) { public Modules(String username) {
this.mUsername = username; this.mUsername = username;
@@ -75,15 +79,38 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
Modules modules = (Modules) readObject; Modules modules = (Modules) readObject;
is.close(); is.close();
fis.close(); fis.close();
fis = context.openFileInput(FILE_NAME_TIMESTAMP);
is = new ObjectInputStream(fis);
modules.mLastTimestamp = is.readLong();
is.close();
fis.close();
return modules; return modules;
} }
public boolean isNewerVersionInStorage(Context context) throws IOException {
FileInputStream fis = context.openFileInput(FILE_NAME_TIMESTAMP);
ObjectInputStream is = new ObjectInputStream(fis);
boolean result = this.mLastTimestamp < is.readLong();
is.close();
fis.close();
return result;
}
public void save(Context context) throws IOException { public void save(Context context) throws IOException {
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE); FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
ObjectOutputStream os = new ObjectOutputStream(fos); ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(this); os.writeObject(this);
os.close(); os.close();
fos.close(); fos.close();
fos = context.openFileOutput(FILE_NAME_TIMESTAMP, Context.MODE_PRIVATE);
os = new ObjectOutputStream(fos);
this.mLastTimestamp = System.currentTimeMillis();
os.writeLong(this.mLastTimestamp);
os.close();
fos.close();
} }
public void delete(Context context) { public void delete(Context context) {
@@ -94,19 +121,36 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
return mUsername; return mUsername;
} }
public void updateList(Modules modules) { public boolean updateList(Modules modules) {
SortedListModule old = this.list; SortedListModule old = this.list;
this.list = modules.list; this.list = modules.list;
boolean isChanged = false;
for (Module oldModule : old) { for (Module oldModule : old) {
Module newModule = this.list.getById(oldModule.getID()); Module newModule = this.list.getById(oldModule.getID());
if (newModule != null) { if (newModule != null) {
if (!isChanged && !hashEquals(oldModule, newModule))
isChanged = true;
newModule.announcements = oldModule.announcements; newModule.announcements = oldModule.announcements;
newModule.assignments = oldModule.assignments; newModule.assignments = oldModule.assignments;
newModule.events = oldModule.events; newModule.events = oldModule.events;
newModule.gradebook = oldModule.gradebook; newModule.gradebook = oldModule.gradebook;
newModule.resources = oldModule.resources; newModule.resources = oldModule.resources;
} else {
isChanged = true;
} }
} }
if (this.list.size() != old.size())
isChanged = true;
return isChanged;
}
private boolean hashEquals(Module o1, Module o2) {
if (o1 == null && o2 == null)
return true;
else if (o1 == null || o2 == null)
return false;
else
return o1.hashCode() == o2.hashCode();
} }
public class Module implements Serializable { public class Module implements Serializable {
@@ -166,5 +210,10 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
"\ntype: "+type+ "\ntype: "+type+
"\nID: "+ID; "\nID: "+ID;
} }
@Override
public int hashCode() {
return Objects.hashCode(semester, lvNumber, title, lecturer, type, description, ID);
}
} }
} }

View File

@@ -122,6 +122,13 @@ public class CustomAccountManager {
return mAccountManager.getAccountsByType(accountType).length != 0; return mAccountManager.getAccountsByType(accountType).length != 0;
} }
public Account getAccountByType(String accountType) {
Account[] accountsByType = mAccountManager.getAccountsByType(accountType);
if (accountsByType.length > 0)
return accountsByType[0];
return null;
}
@FunctionalInterface @FunctionalInterface
public interface ActivityInterface { public interface ActivityInterface {
@Nullable @Nullable

View File

@@ -0,0 +1,57 @@
package de.sebse.fuplanner.tools;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import org.jetbrains.annotations.NotNull;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import de.sebse.fuplanner.MainActivity;
import de.sebse.fuplanner.R;
public class CustomNotificationManager {
private static final String CHANNEL_ID = "fuplanner-default";
//public static ArrayList<Integer> passedNotifications = new ArrayList<>();
public static void sendNotification(Context context, String textTitle, String textContent) {
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(textTitle)
.setContentText(textContent)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
int notificationId = (int) (System.currentTimeMillis() % Integer.MAX_VALUE);
notificationManager.notify(notificationId, mBuilder.build());
}
public static void createNotificationChannel(@NotNull Context context) {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = context.getString(R.string.channel_name);
String description = context.getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
}
}

View File

@@ -1,6 +1,7 @@
package de.sebse.fuplanner.tools; package de.sebse.fuplanner.tools;
import android.content.Context; import android.content.Context;
import androidx.annotation.ArrayRes; import androidx.annotation.ArrayRes;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@@ -20,4 +21,14 @@ public class Preferences {
String string = context.getResources().getString(key); String string = context.getResources().getString(key);
PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(string, value).apply(); PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(string, value).apply();
} }
public static boolean getBoolean(Context context, @StringRes int key) {
String string = context.getResources().getString(key);
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(string, false);
}
public static void setBoolean(Context context, @StringRes int key, boolean value) {
String string = context.getResources().getString(key);
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(string, value).apply();
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -92,4 +92,21 @@
<string name="error_incorrect_password">Das Passwort ist nicht korrekt.</string> <string name="error_incorrect_password">Das Passwort ist nicht korrekt.</string>
<string name="error_field_required">Pflichtfeld</string> <string name="error_field_required">Pflichtfeld</string>
<string name="kvv_sync">KVV-Synchronisation</string> <string name="kvv_sync">KVV-Synchronisation</string>
<string name="channel_name">Neue Daten verfügbar</string>
<string name="channel_description">Benachrichtigen, wenn neue Ankündigungen, Aufgaben, Noten oder Resourcen verfügbar sind</string>
<string name="announcement_updated">Ankündigung aktualisiert: %1$s</string>
<string name="assignment_updated">Aufgabe aktualisiert: %1$s</string>
<string name="event_updated">Event aktualisiert: %1$s</string>
<string name="gradebook_updated">Noteneintrag aktualisiert: %1$s</string>
<string name="resource_updated">Ressource aktualisiert: %1$s</string>
<string name="announcement_added">Neue Ankündigung: %1$s</string>
<string name="assignment_added">Neue Aufgabe: %1$</string>
<string name="event_added">Neues Event: %1$</string>
<string name="gradebook_added">Neuer Noteneintrag: %1$</string>
<string name="resource_added">Neue Ressource: %1$</string>
<string name="announcement_removed">Ankündigung entfernt: %1$s</string>
<string name="assignment_removed">Aufgabe entfernt: %1$s</string>
<string name="event_removed">Event entfernt: %1$s</string>
<string name="gradebook_removed">Noteneintrag entfernt: %1$s</string>
<string name="resource_removed">Ressource entfernt: %1$s</string>
</resources> </resources>

View File

@@ -8,4 +8,6 @@
<string name="pref_price_group_default" translatable="false">all</string> <string name="pref_price_group_default" translatable="false">all</string>
<string name="pref_last_visited_news" translatable="false">pref_last_visited_news</string> <string name="pref_last_visited_news" translatable="false">pref_last_visited_news</string>
<string name="pref_set_auto_sync_on_startup" translatable="false">pref_set_auto_sync_on_startup</string>
</resources> </resources>

View File

@@ -100,4 +100,21 @@
<string name="error_incorrect_password">This password is incorrect</string> <string name="error_incorrect_password">This password is incorrect</string>
<string name="error_field_required">This field is required</string> <string name="error_field_required">This field is required</string>
<string name="kvv_sync">KVV Synchronization</string> <string name="kvv_sync">KVV Synchronization</string>
<string name="channel_name">New data available</string>
<string name="channel_description">Notify when new announcements, assignments, grades or resources are available</string>
<string name="announcement_updated">Announcement updated: %1$s</string>
<string name="announcement_added">New announcement: %1$s</string>
<string name="announcement_removed">Announcement removed: %1$s</string>
<string name="assignment_updated">Assignment updated: %1$s</string>
<string name="assignment_added">New assignment: %1$s</string>
<string name="assignment_removed">Assignment removed: %1$s</string>
<string name="event_updated">Event updated: %1$s</string>
<string name="event_added">New event: %1$s</string>
<string name="event_removed">Event removed: %1$s</string>
<string name="gradebook_updated">Gradebook entry updated: %1$s</string>
<string name="gradebook_added">New gradebook entry: %1$s</string>
<string name="gradebook_removed">Gradebook entry removed: %1$s</string>
<string name="resource_updated">Resource updated: %1$s</string>
<string name="resource_added">New resource: %1$s</string>
<string name="resource_removed">Resource removed: %1$s</string>
</resources> </resources>

View File

@@ -17,12 +17,3 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit # This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
systemProp.http.proxyHost=proxy1-3.biotronik.int
systemProp.http.proxyPort=9090
systemProp.http.proxyUser=Sebastian%20Seedorf
systemProp.http.proxyPassword=1111ApoTheke
systemProp.https.proxyHost=proxy1-3.biotronik.int
systemProp.https.proxyPort=9090
systemProp.https.proxyUser=Sebastian%20Seedorf
systemProp.https.proxyPassword=1111ApoTheke