f06b57c69df07dc9286bd9d496f2ef0bffb0359f
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / wayf / SessionWayfCache.java
1 package edu.internet2.middleware.shibboleth.wayf;
2
3 import javax.servlet.http.HttpServletRequest;
4 import javax.servlet.http.HttpServletResponse;
5 import javax.servlet.http.HttpSession;
6
7 /**
8  * Implementation of <code>WayfCache</code> that uses Java Servlet Sessions to cache
9  * user selections.
10  * 
11  * @author Walter Hoehn wassa&#064;columbia.edu
12  */
13
14 public class SessionWayfCache extends WayfCacheBase implements WayfCache {
15
16         /**
17          * @see WayfCache#addHsToCache(HttpServletRequest)
18          */
19         public void addHsToCache(
20                 String handleService,
21                 HttpServletRequest req,
22                 HttpServletResponse res) {
23                         
24                 HttpSession session = req.getSession(true);
25                 session.setMaxInactiveInterval(7200);
26                 session.setAttribute("selectedHandleService", handleService);
27         }
28
29         /**
30          * @see WayfCache#deleteHsFromCache(HttpServletRequest)
31          */
32         public void deleteHsFromCache(
33                 HttpServletRequest req,
34                 HttpServletResponse res) {
35                         
36                 HttpSession session = req.getSession(false);
37                 if (session != null) {
38                         session.removeAttribute("selectedHandleService");
39                 }
40         }
41
42         /**
43          * @see WayfCache#getCachedHS(HttpServletRequest)
44          */
45         public String getCachedHS(HttpServletRequest req) {
46                 
47                 HttpSession session = req.getSession(false);
48                 if (session == null) {
49                         return null;
50                 }
51                 return (String) session.getAttribute("selectedHandleService");
52         }
53 }