]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/server/jcr/mvc/OpenSessionInViewJcrInterceptor.java
Fix list mapping
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.jcr / src / main / java / org / argeo / server / jcr / mvc / OpenSessionInViewJcrInterceptor.java
1 package org.argeo.server.jcr.mvc;
2
3 import javax.jcr.Session;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.springframework.ui.ModelMap;
8 import org.springframework.web.context.request.RequestAttributes;
9 import org.springframework.web.context.request.WebRequest;
10 import org.springframework.web.context.request.WebRequestInterceptor;
11
12 public class OpenSessionInViewJcrInterceptor implements WebRequestInterceptor,
13 JcrMvcConstants {
14 private final static Log log = LogFactory
15 .getLog(OpenSessionInViewJcrInterceptor.class);
16
17 private Session session;
18
19 public void preHandle(WebRequest request) throws Exception {
20 if (log.isTraceEnabled())
21 log.trace("preHandle: " + request);
22 // Authentication auth = SecurityContextHolder.getContext()
23 // .getAuthentication();
24 // if (auth != null)
25 // log.debug("auth=" + auth + ", authenticated="
26 // + auth.isAuthenticated() + ", name=" + auth.getName());
27 // else
28 // log.debug("No auth");
29
30 // FIXME: find a safer way to initialize
31 // FIXME: not really needed to initialize here
32 // session.getRepository();
33 request.setAttribute(REQUEST_ATTR_SESSION, session,
34 RequestAttributes.SCOPE_REQUEST);
35 }
36
37 public void postHandle(WebRequest request, ModelMap model) throws Exception {
38 // if (log.isDebugEnabled())
39 // log.debug("postHandle: " + request);
40 }
41
42 public void afterCompletion(WebRequest request, Exception ex)
43 throws Exception {
44 if (log.isTraceEnabled())
45 log.trace("afterCompletion: " + request);
46 // FIXME: only close session that were open
47 session.logout();
48 }
49
50 public void setSession(Session session) {
51 this.session = session;
52 }
53
54 }