Package ninja.session
Class SessionImpl
- java.lang.Object
-
- ninja.session.SessionImpl
-
-
Field Summary
-
Fields inherited from interface ninja.session.Session
AUTHENTICITY_KEY, EXPIRY_TIME_KEY, ID_KEY, TIMESTAMP_KEY
-
-
Constructor Summary
Constructors Constructor Description SessionImpl(Crypto crypto, CookieEncryption encryption, NinjaProperties ninjaProperties, Clock clock)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all values from the session.Stringget(String key)Returns the value of the key or null.StringgetAuthenticityToken()Map<String,String>getData()StringgetId()voidinit(Context context)Has to be called initially.booleanisEmpty()Returns true if the session is empty, e.g.voidput(String key, String value)Puts key / value into the session.Stringremove(String key)Removes the value of the key and returns the value or null.voidsave(Context context)To finally send this session to the user this method has to be called.voidsetExpiryTime(Long expiryTimeMs)Use an alternative expiry time, this can be used to implement a longer expiry time for 'remember me' style functionality.protected booleanshouldExpire()
-
-
-
Constructor Detail
-
SessionImpl
@Inject public SessionImpl(Crypto crypto, CookieEncryption encryption, NinjaProperties ninjaProperties, Clock clock)
-
-
Method Detail
-
init
public void init(Context context)
Description copied from interface:SessionHas to be called initially. => maybe in the future as assisted inject.
-
shouldExpire
protected boolean shouldExpire()
-
setExpiryTime
public void setExpiryTime(Long expiryTimeMs)
Description copied from interface:SessionUse an alternative expiry time, this can be used to implement a longer expiry time for 'remember me' style functionality. The expiry time is persisted in the session.- Specified by:
setExpiryTimein interfaceSession- Parameters:
expiryTimeMs- the expiry time in milliseconds, set to null to remove the expiry time from the session and use the application default.
-
getAuthenticityToken
public String getAuthenticityToken()
- Specified by:
getAuthenticityTokenin interfaceSession- Returns:
- a authenticity token (may generate a new one if the session currently does not contain the token).
-
save
public void save(Context context)
Description copied from interface:SessionTo finally send this session to the user this method has to be called. It basically serializes the session into the header of the response.
-
put
public void put(String key, String value)
Description copied from interface:SessionPuts key / value into the session. PLEASE NOTICE: If value == null the key will be removed!
-
get
public String get(String key)
Description copied from interface:SessionReturns the value of the key or null.
-
remove
public String remove(String key)
Description copied from interface:SessionRemoves the value of the key and returns the value or null.
-
clear
public void clear()
Description copied from interface:SessionRemoves all values from the session.
-
isEmpty
public boolean isEmpty()
Description copied from interface:SessionReturns true if the session is empty, e.g. does not contain anything else than the timestamp key.
-
-