aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java
new file mode 100644
index 0000000..e3c8269
--- /dev/null
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java
@@ -0,0 +1,47 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.web.helper;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.pdfas.exceptions.web.SessionExpiredException;
+import at.gv.egiz.pdfas.web.session.SessionAttributes;
+
+/**
+ * @author wprinz
+ *
+ */
+public class SessionHelper
+{
+ /**
+ * The log.
+ */
+ private static Log log = LogFactory.getLog(SessionHelper.class);
+
+ public static Object getSession(HttpServletRequest request) throws SessionExpiredException
+ {
+
+ HttpSession session = request.getSession(false);
+ if (session == null)
+ {
+ String msg = "There is no session associated with this request."; //$NON-NLS-1$
+ log.error(msg);
+ throw new SessionExpiredException(msg);
+ }
+
+ Object sessionObject = session.getAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION);
+ if (sessionObject == null)
+ {
+ String msg = "Unable to find session data in session " + session.getId();
+ log.error(msg);
+ throw new SessionExpiredException(msg);
+ }
+
+ return sessionObject;
+ }
+}