diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2013-09-05 21:18:04 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2013-09-05 21:18:04 -0700 |
commit | 36970455d1fbb03a751cddbdbaa5bed334e58169 (patch) | |
tree | eee66ec85184a23c92c94a29edc6991eb94c6543 /src/com/p4square/grow/frontend/session/Sessions.java | |
parent | 283c4928081f82e3f6ef7a0f80aecf0bacb89dbe (diff) |
Moving Sessions to FMFacade. Adding transition from Assessment to Training.
Diffstat (limited to 'src/com/p4square/grow/frontend/session/Sessions.java')
-rw-r--r-- | src/com/p4square/grow/frontend/session/Sessions.java | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/src/com/p4square/grow/frontend/session/Sessions.java b/src/com/p4square/grow/frontend/session/Sessions.java deleted file mode 100644 index 58bb5f6..0000000 --- a/src/com/p4square/grow/frontend/session/Sessions.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2013 Jesse Morgan - */ - -package com.p4square.grow.frontend.session; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.Map; - -import org.restlet.Response; -import org.restlet.Request; -import org.restlet.data.CookieSetting; -import org.restlet.security.User; - -/** - * Singleton Session Manager. - * - * @author Jesse Morgan <jesse@jesterpm.net> - */ -public class Sessions { - private static final String COOKIE_NAME = "S"; - - private static final Sessions THE = new Sessions(); - public static Sessions getInstance() { - return THE; - } - - private final Map<String, Session> mSessions; - - private Sessions() { - mSessions = new ConcurrentHashMap<String, Session>(); - } - - public Session get(String sessionid) { - Session s = mSessions.get(sessionid); - - if (s != null && !s.isExpired()) { - s.touch(); - return s; - } - - return null; - } - - /** - * Get the Session associated with the Request. - * @return A session or null if no session is found. - */ - public Session get(Request request) { - final String cookie = request.getCookies().getFirstValue(COOKIE_NAME); - - if (cookie != null) { - return get(cookie); - } - - return null; - } - - public Session create(User user) { - if (user == null) { - throw new IllegalArgumentException("Can not create session for null user."); - } - - Session s = new Session(user); - mSessions.put(s.getId(), s); - - return s; - } - - /** - * Create a new Session and add the Session cookie to the response. - */ - public Session create(Request request, Response response) { - Session s = create(request.getClientInfo().getUser()); - - CookieSetting cookie = new CookieSetting(COOKIE_NAME, s.getId()); - cookie.setPath("/"); - - request.getCookies().add(cookie); - response.getCookieSettings().add(cookie); - - return s; - } -} |