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 jakarta.servlet.http.HttpServletRequest;
14  import jakarta.servlet.http.HttpServletResponse;
15  
16  import org.apache.catalina.Context;
17  import org.apache.catalina.Manager;
18  import org.apache.catalina.Session;
19  import org.springframework.beans.factory.annotation.Value;
20  import org.springframework.stereotype.Controller;
21  import org.springframework.web.bind.ServletRequestUtils;
22  import org.springframework.web.bind.annotation.RequestMapping;
23  import org.springframework.web.servlet.ModelAndView;
24  import org.springframework.web.servlet.view.InternalResourceView;
25  
26  import psiprobe.controllers.AbstractTomcatContainerController;
27  
28  /**
29   * Expires a list of sessionIDs. Accepts a list of sid_webapp parameters that are expected to be in
30   * a form of "sid;webapp"
31   */
32  @Controller
33  public class ExpireSessionsController extends AbstractTomcatContainerController {
34  
35    @RequestMapping(path = "/app/expire_list.htm")
36    @Override
37    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
38        throws Exception {
39      return super.handleRequest(request, response);
40    }
41  
42    @Override
43    protected ModelAndView handleRequestInternal(HttpServletRequest request,
44        HttpServletResponse response) throws Exception {
45  
46      for (String sidWebApp : ServletRequestUtils.getStringParameters(request, "sid_webapp")) {
47        if (sidWebApp != null) {
48          String[] ss = sidWebApp.split(";", -1);
49          if (ss.length != 2) {
50            return new ModelAndView("errors/paramerror");
51          }
52          String sessionId = ss[0];
53          String appName = ss[1];
54          Context context = getContainerWrapper().getTomcatContainer().findContext(appName);
55          if (context == null) {
56            return new ModelAndView("errors/paramerror");
57          }
58          Manager manager = context.getManager();
59          Session session = manager.findSession(sessionId);
60          if (session != null && session.isValid()) {
61            session.expire();
62          }
63        }
64      }
65      return new ModelAndView(new InternalResourceView(getViewName()));
66    }
67  
68    @Value("/sessions.htm")
69    @Override
70    public void setViewName(String viewName) {
71      super.setViewName(viewName);
72    }
73  
74  }