Package ninja.session
Interface Session
-
- All Known Implementing Classes:
SessionImpl
public interface Session
-
-
Field Summary
Fields Modifier and Type Field Description static StringAUTHENTICITY_KEYstatic StringEXPIRY_TIME_KEYstatic StringID_KEYstatic StringTIMESTAMP_KEY
-
Method Summary
All Methods Instance Methods Abstract 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.
-
-
-
Field Detail
-
AUTHENTICITY_KEY
static final String AUTHENTICITY_KEY
- See Also:
- Constant Field Values
-
ID_KEY
static final String ID_KEY
- See Also:
- Constant Field Values
-
TIMESTAMP_KEY
static final String TIMESTAMP_KEY
- See Also:
- Constant Field Values
-
EXPIRY_TIME_KEY
static final String EXPIRY_TIME_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
void init(Context context)
Has to be called initially. => maybe in the future as assisted inject.- Parameters:
context- The context of this session.
-
getId
String getId()
- Returns:
- id of a session.
-
getAuthenticityToken
String getAuthenticityToken()
- Returns:
- a authenticity token (may generate a new one if the session currently does not contain the token).
-
save
void save(Context context)
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.- Parameters:
context- The context from where to deduct a potentially existing session.
-
put
void put(String key, String value)
Puts key / value into the session. PLEASE NOTICE: If value == null the key will be removed!- Parameters:
key- Name of the key to store in the session.value- The value to store in the session
-
get
String get(String key)
Returns the value of the key or null.- Parameters:
key- Name of the key to retrieve.- Returns:
- The value of the key or null.
-
remove
String remove(String key)
Removes the value of the key and returns the value or null.- Parameters:
key- name of the key to remove- Returns:
- original value of the key we just removed
-
clear
void clear()
Removes all values from the session.
-
isEmpty
boolean isEmpty()
Returns true if the session is empty, e.g. does not contain anything else than the timestamp key.- Returns:
- true if session does not contain any values / false if it contains values.
-
setExpiryTime
void setExpiryTime(Long expiryTimeMs)
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.- Parameters:
expiryTimeMs- the expiry time in milliseconds, set to null to remove the expiry time from the session and use the application default.
-
-