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 void
clear()
Removes all values from the session.String
get(String key)
Returns the value of the key or null.String
getAuthenticityToken()
Map<String,String>
getData()
String
getId()
void
init(Context context)
Has to be called initially.boolean
isEmpty()
Returns true if the session is empty, e.g.void
put(String key, String value)
Puts key / value into the session.String
remove(String key)
Removes the value of the key and returns the value or null.void
save(Context context)
To finally send this session to the user this method has to be called.void
setExpiryTime(Long expiryTimeMs)
Use an alternative expiry time, this can be used to implement a longer expiry time for 'remember me' style functionality.protected boolean
shouldExpire()
-
-
-
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:Session
Has 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:Session
Use 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:
setExpiryTime
in 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:
getAuthenticityToken
in 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:Session
To 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:Session
Puts 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:Session
Returns the value of the key or null.
-
remove
public String remove(String key)
Description copied from interface:Session
Removes the value of the key and returns the value or null.
-
clear
public void clear()
Description copied from interface:Session
Removes all values from the session.
-
isEmpty
public boolean isEmpty()
Description copied from interface:Session
Returns true if the session is empty, e.g. does not contain anything else than the timestamp key.
-
-