aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java b/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java
new file mode 100644
index 0000000..5752838
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java
@@ -0,0 +1,48 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.web.helper;
+
+import javax.servlet.ServletException;
+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.knowcenter.wag.egov.egiz.web.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 = "The session is not found or no longer valid."; //$NON-NLS-1$
+ log.error(msg);
+ throw new SessionExpiredException(msg);
+ }
+
+ return sessionObject;
+ }
+}