request = mock(H.Request.class); response = mock(H.Response.class); session = new H.Session(); jobManager = mock(AppJobManager.class); eventBus = mock(EventBus.class);
session = new H.Session();
session.load(KEY_EXPIRATION, String.valueOf(expiration)); } else { String s = session.get(KEY_EXPIRATION); long oldTimestamp = null == s ? -1 : Long.parseLong(s); long newTimestamp = expiration; session = new H.Session(); } else { if (oldTimestamp < now) { session = new H.Session(); session.put(KEY_EXPIRE_INDICATOR, true); } else { session.remove(KEY_EXPIRE_INDICATOR); boolean skipUpdateExpiration = S.eq(pingPath, request.url()); if (skipUpdateExpiration) { session.put(KEY_EXPIRATION, newTimestamp);
session = new H.Session();
session.load(KEY_EXPIRATION, String.valueOf(expiration)); } else { String s = session.get(KEY_EXPIRATION); long oldTimestamp = null == s ? -1 : Long.parseLong(s); long newTimestamp = expiration; session = new H.Session(); } else { if (oldTimestamp < now) { session = new H.Session(); session.put(KEY_EXPIRE_INDICATOR, true); } else { session.remove(KEY_EXPIRE_INDICATOR); boolean skipUpdateExpiration = S.eq(pingPath, request.url()); if (skipUpdateExpiration) { session.put(KEY_EXPIRATION, newTimestamp);
public H.Session resolveSession(H.Request request, ActionContext context) { String encodedSession = mapper.readSession(request); context.encodedSessionToken = encodedSession; if (null == encodedSession) { return new H.Session(); } H.Session session = codec.decodeSession(encodedSession, request); if (sessionTimeout <= 0) { // session never timeout return session; } // check if session has been logged out String id = session.id(); if (null != logoutSessionCache.get(id)) { session = new H.Session(); } return session; }
@Override public final H.Session parseTicket(T ticket) { Map<String, String> payload = new HashMap<>(); String id = deserialize(ticket, payload); if (null == payload) { return null; } H.Session session = new H.Session(); $.setField("id", session, id); if (payload.isEmpty()) { return session; } for (Map.Entry<String, String> entry : payload.entrySet()) { session.put(entry.getKey(), entry.getValue()); } return session; } }
private void preventDoubleSubmission(ActionContext context) { if (null == dspToken) { return; } H.Request req = context.req(); if (req.method().safe()) { return; } String tokenValue = context.paramVal(dspToken); if (S.blank(tokenValue)) { return; } H.Session session = context.session(); String cacheKey = S.concat("DSP-", dspToken); String cached = session.cached(cacheKey); if (S.eq(tokenValue, cached)) { throw Conflict.get(); } session.cacheFor1Min(cacheKey, tokenValue); }
@Override public <T> T get(String key) { ActionContext actionContext = ActionContext.current(); if (null != actionContext) { H.Session session = actionContext.session(); T t = session.cached(key); if (null != t) { session.cache(key, t, TTL); } return t; } CliContext cliContext = CliContext.current(); if (null != cliContext) { CliSession cliSession = cliContext.session(); return cliSession.attribute(key); } return null; }
/** * Add an object into cache by key with expiration time specified * * @param key * the key to index the object within the cache * @param obj * the object to be cached * @param expiration * the seconds after which the object will be evicted from the cache */ public void cache(String key, Object obj, int expiration) { H.Session session = this.session; if (null != session) { session.cache(key, obj, expiration); } else { app().cache().put(key, obj, expiration); } }
private void preventDoubleSubmission(ActionContext context) { if (null == dspToken) { return; } H.Request req = context.req(); if (req.method().safe()) { return; } String tokenValue = context.paramVal(dspToken); if (S.blank(tokenValue)) { return; } H.Session session = context.session(); String cacheKey = S.concat("DSP-", dspToken); String cached = session.cached(cacheKey); if (S.eq(tokenValue, cached)) { throw Conflict.get(); } session.cacheFor1Min(cacheKey, tokenValue); }
/** * Add an object into cache by key. The key will be used in conjunction with session id if * there is a session instance * * @param key * the key to index the object within the cache * @param obj * the object to be cached */ public void cache(String key, Object obj) { H.Session sess = session(); if (null != sess) { sess.cache(key, obj); } else { app().cache().put(key, obj); } }
/** * Return cached object by key. The key will be concatenated with * current session id when fetching the cached object * * @param key * @param <T> * the object type * @return the cached object */ public <T> T cached(String key) { H.Session sess = session(); if (null != sess) { return sess.cached(key); } else { return app().cache().get(key); } }
@Override public final H.Session parseTicket(T ticket) { Map<String, String> payload = new HashMap<>(); String id = deserialize(ticket, payload); if (null == payload) { return null; } H.Session session = new H.Session(); $.setField("id", session, id); if (payload.isEmpty()) { return session; } for (Map.Entry<String, String> entry : payload.entrySet()) { session.put(entry.getKey(), entry.getValue()); } return session; } }
@Override public String encodeSession(H.Session session) { if (null == session) { return null; } boolean sessionChanged = session.changed(); if (!sessionChanged && (session.empty() || !sessionWillExpire)) { // Nothing changed and no cookie-expire or empty, consequently send nothing back. return null; } session.id(); // ensure session ID is generated if (sessionWillExpire && !session.contains(KEY_EXPIRATION)) { // session get cleared before session.put(KEY_EXPIRATION, $.ms() + ttlInMillis); } return populateToken(jwt.newToken(), session).toString(jwt); }
@Override public <T> T get(String key) { ActionContext actionContext = ActionContext.current(); if (null != actionContext) { H.Session session = actionContext.session(); T t = session.cached(key); if (null != t) { session.cache(key, t, TTL); } return t; } CliContext cliContext = CliContext.current(); if (null != cliContext) { CliSession cliSession = cliContext.session(); return cliSession.attribute(key); } return null; }
@Override public String encodeSession(H.Session session) { if (null == session) { return null; } boolean sessionChanged = session.changed(); if (!sessionChanged && (session.empty() || !sessionWillExpire)) { // Nothing changed and no cookie-expire or empty, consequently send nothing back. return null; } session.id(); // ensure session ID is generated if (sessionWillExpire && !session.contains(KEY_EXPIRATION)) { // session get cleared before session.put(KEY_EXPIRATION, $.ms() + ttlInMillis); } return dissolveIntoCookieContent(session, true); }
/** * Add an object into cache by key with expiration time specified * * @param key * the key to index the object within the cache * @param obj * the object to be cached * @param expiration * the seconds after which the object will be evicted from the cache */ public void cache(String key, Object obj, int expiration) { H.Session session = this.session; if (null != session) { session.cache(key, obj, expiration); } else { app().cache().put(key, obj, expiration); } }
public H.Session resolveSession(H.Request request, ActionContext context) { String encodedSession = mapper.readSession(request); context.encodedSessionToken = encodedSession; if (null == encodedSession) { return new H.Session(); } H.Session session = codec.decodeSession(encodedSession, request); if (sessionTimeout <= 0) { // session never timeout return session; } // check if session has been logged out String id = session.id(); if (null != logoutSessionCache.get(id)) { session = new H.Session(); } return session; }