View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.controllers.sessions;
12  
13  import javax.servlet.http.HttpServletRequest;
14  import javax.servlet.http.HttpServletResponse;
15  
16  import org.apache.catalina.Context;
17  import org.springframework.beans.factory.annotation.Value;
18  import org.springframework.stereotype.Controller;
19  import org.springframework.web.bind.ServletRequestUtils;
20  import org.springframework.web.bind.annotation.RequestMapping;
21  import org.springframework.web.servlet.ModelAndView;
22  
23  import psiprobe.controllers.AbstractContextHandlerController;
24  import psiprobe.model.ApplicationSession;
25  import psiprobe.tools.ApplicationUtils;
26  import psiprobe.tools.SecurityUtils;
27  
28  /**
29   * Retrieves the list of attributes for given session.
30   */
31  @Controller
32  public class ListSessionAttributesController extends AbstractContextHandlerController {
33  
34    @RequestMapping(path = "/attributes.htm")
35    @Override
36    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
37        throws Exception {
38      return super.handleRequest(request, response);
39    }
40  
41    @Override
42    protected ModelAndView handleContext(String contextName, Context context,
43        HttpServletRequest request, HttpServletResponse response) throws Exception {
44  
45      boolean privileged = SecurityUtils.hasAttributeValueRole(getServletContext());
46      boolean calcSize =
47          privileged && ServletRequestUtils.getBooleanParameter(request, "size", false);
48      String sid = ServletRequestUtils.getStringParameter(request, "sid");
49  
50      ApplicationSession appSession = ApplicationUtils
51          .getApplicationSession(context.getManager().findSession(sid), calcSize, true);
52  
53      if (appSession != null) {
54        appSession.setAllowedToViewValues(privileged);
55        return new ModelAndView(getViewName(), "session", appSession);
56      }
57      return new ModelAndView(getViewName());
58    }
59  
60    @Value("attributes")
61    @Override
62    public void setViewName(String viewName) {
63      super.setViewName(viewName);
64    }
65  
66  }