Skip to content

Commit

Permalink
Session max age configuration in server and client. Removed hardcoded…
Browse files Browse the repository at this point in the history
… value
  • Loading branch information
vjrj committed Oct 23, 2017
1 parent 5f6d915 commit facf878
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
// TODO: Auto-generated Javadoc
/**
* The Class SignInAbstractPresenter.
*
*
* @param <V>
* the value type
* @param <Proxy_>
Expand Down Expand Up @@ -77,7 +77,7 @@ public abstract class SignInAbstractPresenter<V extends View, Proxy_ extends Pro

/**
* Instantiates a new sign in abstract presenter.
*
*
* @param eventBus
* the event bus
* @param view
Expand Down Expand Up @@ -109,7 +109,7 @@ public SignInAbstractPresenter(final EventBus eventBus, final View view, final P

/**
* Gets the goto token on cancel.
*
*
* @return the goto token on cancel
*/
public String getGotoTokenOnCancel() {
Expand All @@ -118,7 +118,7 @@ public String getGotoTokenOnCancel() {

/*
* (non-Javadoc)
*
*
* @see com.gwtplatform.mvp.client.PresenterWidget#getView()
*/
@Override
Expand Down Expand Up @@ -162,7 +162,7 @@ public void onClose() {

/**
* On sign in.
*
*
* @param userInfoDTO
* the user info dto
* @param gotoHomePage
Expand All @@ -172,7 +172,7 @@ public void onClose() {
*/
protected void onSignIn(final UserInfoDTO userInfoDTO, final boolean gotoHomePage, final String passwd) {
final String userHash = userInfoDTO.getUserHash();
cookiesManager.setAuthCookie(userHash);
cookiesManager.setAuthCookie(userHash, session.getInitData().getCookieMaxAge());
getView().reset();
session.setUserHash(userHash);
session.setCurrentUserInfo(userInfoDTO, passwd);
Expand Down Expand Up @@ -208,7 +208,7 @@ public void onChangeNotNeeded() {

/**
* Save autocomplete login data.
*
*
* @param nickOrEmail
* the nick or email
* @param password
Expand All @@ -226,7 +226,7 @@ public void setAskForLanguageChange(final boolean askForLanguageChange) {

/**
* Sets the goto token on cancel.
*
*
* @param gotoTokenOnCancel
* the new goto token on cancel
*/
Expand All @@ -236,7 +236,7 @@ public void setGotoTokenOnCancel(final String gotoTokenOnCancel) {

/**
* Sets the goto token on success.
*
*
* @param gotoTokenOnSuccess
* the new goto token on success
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public interface CookiesManager {
* @param userHash
* the new auth cookie
*/
void setAuthCookie(String userHash);
void setAuthCookie(String userHashh, int cookieMaxAge);

String getJettyCookie();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ public void setAnonCookie(final Boolean userRegister) {
* cc.kune.core.client.cookies.CookiesManager#setAuthCookie(java.lang.String)
*/
@Override
public void setAuthCookie(final String userHash) {
public void setAuthCookie(final String userHash, int cookieMaxAge) {
// http://code.google.com/p/google-web-toolkit-incubator/wiki/LoginSecurityFAQ
final Date exp = new Date(System.currentTimeMillis() + SessionConstants.SESSION_DURATION);

final Date exp = cookieMaxAge <= 0 ? null : new Date(System.currentTimeMillis() + cookieMaxAge * 1000);
boolean ssl = WindowUtils.isHttps();

Log.info("Received userhash: " + userHash);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/cc/kune/core/server/InitData.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ public class InitData {
/** The user tools. */
private List<ToolSimple> userTools;

private int cookieMaxAge;

public int getCookieMaxAge() {
return cookieMaxAge;
}

public void setCookieMaxAge(int cookieMaxAge) {
this.cookieMaxAge = cookieMaxAge;
}

/**
* Gets the avi embed object.
*
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/cc/kune/core/server/UserSessionManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
// @LogThis
/**
* The Class UserSessionManager.
*
*
* @author [email protected] (Vicente J. Ruiz Jurado)
*/
@Singleton
Expand All @@ -67,7 +67,7 @@ public class UserSessionManagerImpl implements UsersOnline, UserSessionManager {

/**
* Instantiates a new user session manager.
*
*
* @param userManager
* the manager
* @param userSessionProv
Expand All @@ -91,6 +91,9 @@ public UserSessionManagerImpl(final UserManager userManager,
final HashSessionManager hSessionManager = (HashSessionManager) jettySessionManager;
hSessionManager.setMaxInactiveInterval(-1);
hSessionManager.setSavePeriod(5);
// See @ServerModule in wave for setMaxAge (cookie max age) and
// "network.session_cookie_max_age" configuration parameter

// Delete sessions with problems http://jira.codehaus.org/browse/JETTY-1484
hSessionManager.setDeleteUnrestorableSessions(true);
hSessionManager.addEventListener(userSessionMonitor);
Expand All @@ -102,7 +105,7 @@ public UserSessionManagerImpl(final UserManager userManager,

/*
* (non-Javadoc)
*
*
* @see cc.kune.core.server.UserSessionManager#getHashFromSession()
*/
@Override
Expand Down Expand Up @@ -132,7 +135,7 @@ private HttpSession getSessionFromHash(final String userHash) {

/*
* (non-Javadoc)
*
*
* @see cc.kune.core.server.UserSessionManager#getUser()
*/
@Override
Expand All @@ -148,12 +151,12 @@ public User getUser() {

/*
* (non-Javadoc)
*
*
* @see cc.kune.core.server.notifier.UsersOnline#isOnline(java.lang.String)
*/
/*
* (non-Javadoc)
*
*
* @see cc.kune.core.server.UserSessionManager#isOnline(java.lang.String)
*/
@Override
Expand All @@ -169,7 +172,7 @@ public boolean isOnline(final String shortname) {

/*
* (non-Javadoc)
*
*
* @see cc.kune.core.server.UserSessionManager#isUserLoggedIn()
*/
@Override
Expand All @@ -184,7 +187,7 @@ public boolean isUserLoggedIn() {

/*
* (non-Javadoc)
*
*
* @see
* cc.kune.core.server.UserSessionManager#isUserNotLoggedIn(java.lang.String)
*/
Expand All @@ -195,7 +198,7 @@ public boolean isUserNotLoggedIn() {

/*
* (non-Javadoc)
*
*
* @see cc.kune.core.server.UserSessionManager#login(java.lang.Long,
* java.lang.String)
*/
Expand All @@ -208,7 +211,7 @@ public void login(final Long userId, final String newUserHash) {

/*
* (non-Javadoc)
*
*
* @see cc.kune.core.server.UserSessionManager#logout()
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.typesafe.config.Config;

import cc.kune.core.client.errors.DefaultException;
import cc.kune.core.server.InitData;
Expand All @@ -46,7 +47,6 @@
import cc.kune.core.server.manager.I18nLanguageManager;
import cc.kune.core.server.manager.LicenseManager;
import cc.kune.core.server.manager.SiteManager;
import cc.kune.core.server.manager.UserManager;
import cc.kune.core.server.mapper.KuneMapper;
import cc.kune.core.server.mbean.MBeanRegistry;
import cc.kune.core.server.properties.ChatProperties;
Expand Down Expand Up @@ -119,6 +119,8 @@ public class SiteManagerDefault implements SiteManager, SiteManagerDefaultMBean

private WaveIndexer waveIndexer;

private Config waveConfig;

/**
* Instantiates a new site rpc.
*
Expand Down Expand Up @@ -152,7 +154,7 @@ public SiteManagerDefault(final UserSessionManager userSessionManager,
final I18nLanguageManager languageManager, final I18nCountryManager countryManager,
final ServerToolRegistry serverToolRegistry, final MBeanRegistry mbeanRegistry,
final GroupManager groupManager, final I18nTranslationServiceMultiLang i18n, SiteManagers siteManagers,
WaveIndexer waveIndexer
WaveIndexer waveIndexer, Config waveConfig
) {
this.userSessionManager = userSessionManager;
this.userInfoService = userInfoService;
Expand All @@ -167,6 +169,7 @@ public SiteManagerDefault(final UserSessionManager userSessionManager,
this.i18n = i18n;
this.siteManagers = siteManagers;
this.waveIndexer = waveIndexer;
this.waveConfig = waveConfig;
// By default we don't collect which part of the client is untranslated
storeUntranslatedStrings = false;
mbeanRegistry.registerAsMBean(this, MBEAN_OBJECT_NAME);
Expand Down Expand Up @@ -297,7 +300,7 @@ private InitData loadInitData() {
data.setTutorialLanguages(kuneProperties.getList(KuneProperties.KUNE_TUTORIALS_LANGS));
data.setPublicSpaceVisible(kuneProperties.getBoolean(KuneProperties.PUBLIC_SPACE_VISIBLE));
data.setShowInDevelFeatures(kuneProperties.getBoolean(KuneProperties.SHOW_DEVEL_FEATURES));

data.setCookieMaxAge(waveConfig.getInt("network.session_cookie_max_age"));
return data;
}

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/cc/kune/core/shared/SessionConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// TODO: Auto-generated Javadoc
/**
* The Class SessionConstants.
*
*
* @author [email protected] (Vicente J. Ruiz Jurado)
*/
public final class SessionConstants {
Expand Down Expand Up @@ -64,10 +64,7 @@ public final class SessionConstants {
* the user is viewed as a newbie (so, more help is needed)
*/
public final static long MIN_SIGN_IN_FOR_NEWBIES = 10;
// session duration
/** The Constant SESSION_DURATION. */
public final static long SESSION_DURATION = A_DAY * 30; // four weeks login
// public final static long SESSION_DURATION = 10000; // For test

/** The Constant USERHASH. */
public final static String USERHASH = "k007userHash";

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/cc/kune/core/shared/dto/InitDataDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ public class InitDataDTO implements IsSerializable {
/** The user tools. */
private List<ToolSimpleDTO> userTools;

private int cookieMaxAge;

public int getCookieMaxAge() {
return cookieMaxAge;
}

public void setCookieMaxAge(int cookieMaxAge) {
this.cookieMaxAge = cookieMaxAge;
}

/**
* Instantiates a new inits the data dto.
*/
Expand Down
Loading

0 comments on commit facf878

Please sign in to comment.