Skip to content

Commit

Permalink
Added auto refresh after session expires (#3125)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioG70 committed Mar 15, 2024
1 parent 469a5a4 commit c4ae8eb
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public enum DateGranularity {
public static final String UI_DATE_TIME_FORMAT_UTC = "ui.dateTime.format.UTC";

public static final String UI_COOKIES_ACTIVE_PROPERTY = "ui.cookies.active";

public static final String UI_EXPIRED_SESSION_DETECTOR_ACTIVE = "ui.expired.session.detector.active";
public static final String UI_EXPIRED_SESSION_DETECTOR_TIME = "ui.expired.session.detector.time";

public static final String UI_GOOGLE_ANALYTICS_CODE_PROPERTY = "ui.google.analytics.code";
public static final String UI_GOOGLE_RECAPTCHA_CODE_PROPERTY = "ui.google.recaptcha.code";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.roda.wui.client.main;

import com.google.gwt.user.client.rpc.AsyncCallback;
import org.roda.core.data.v2.user.User;
import org.roda.wui.client.common.UserLogin;
import com.google.gwt.user.client.Timer;
import org.roda.wui.client.management.RecoverLogin;
import org.roda.wui.client.management.Register;
import org.roda.wui.client.welcome.Welcome;
import org.roda.wui.common.client.tools.HistoryUtils;

/**
* @author António Lindo <alindo@keep.pt>
*/
public class ExpiredSessionDetector {
private Timer timer;

public ExpiredSessionDetector() {
timer = new Timer() {
@Override
public void run() {
checkSessionStatus();
}
};
}

public void setScheduleTime(int time) {
timer.scheduleRepeating(time);
}

private boolean canGuestAccess() {
String path = HistoryUtils.getCurrentHistoryPath().get(0);
return path.equals(RecoverLogin.RESOLVER.getHistoryToken()) || path.equals(Login.RESOLVER.getHistoryToken())
|| path.equals(Theme.RESOLVER.getHistoryToken()) || path.equals(Register.RESOLVER.getHistoryToken())
|| path.equals(Welcome.RESOLVER.getHistoryToken());
}

public void checkSessionStatus() {
UserLogin.getInstance().getAuthenticatedUser(new AsyncCallback<User>() {
@Override
public void onFailure(Throwable caught) {
UserLogin.getInstance().showSuggestLoginDialog();
}

@Override
public void onSuccess(User user) {
if (user.isGuest()) {
if (!canGuestAccess()) {
HistoryUtils.newHistory(Welcome.RESOLVER);
UserLogin.getInstance().showSuggestLoginDialog();
}
}
}
}, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ public void init() {
JavascriptUtils.setCookieOptions(messages.cookiesMessage(), messages.cookiesDismisse(),
messages.cookiesLearnMore(), "#" + Theme.RESOLVER.getHistoryToken() + "/CookiesPolicy.html");
}

if (ConfigurationManager.getBoolean(true, RodaConstants.UI_EXPIRED_SESSION_DETECTOR_ACTIVE)) {
ExpiredSessionDetector expiredSessionDetector = new ExpiredSessionDetector();
expiredSessionDetector.setScheduleTime(ConfigurationManager.getInt(RodaConstants.UI_EXPIRED_SESSION_DETECTOR_TIME));
}

}

private void onHistoryChanged(String historyToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ ui.sharedProperties.whitelist.configuration.prefix = ui.dateTime
# cookie accept
ui.sharedProperties.whitelist.configuration.prefix = ui.cookies

# session expired detector
ui.sharedProperties.whitelist.configuration.prefix = ui.expired.session.detector

# google re-captcha and analytics
ui.sharedProperties.whitelist.configuration.property = ui.google.analytics.code
ui.sharedProperties.whitelist.configuration.property = ui.google.recaptcha.code
Expand Down Expand Up @@ -108,6 +111,11 @@ ui.sharedProperties.whitelist.configuration.prefix = ui.url
##########################################################################
ui.cookies.active = true

##########################################################################
# Expired session detector settings
##########################################################################
ui.expired.session.detector.active = true
ui.expired.session.detector.time = 1800000

##########################################################################
# Google Analytics settings
Expand Down

0 comments on commit c4ae8eb

Please sign in to comment.