1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import java.text.SimpleDateFormat;
17 import java.util.Date;
18
19 import org.springframework.stereotype.Controller;
20 import org.springframework.web.bind.ServletRequestUtils;
21 import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.servlet.ModelAndView;
23 import org.springframework.web.servlet.mvc.AbstractController;
24
25 import psiprobe.jsp.Functions;
26
27
28
29
30 @Controller
31 public class RememberVisibilityController extends AbstractController {
32
33
34 private final SimpleDateFormat sdf = new SimpleDateFormat("E, d-MMM-yyyy HH:mm:ss zz");
35
36 @RequestMapping(path = "/remember.ajax")
37 @Override
38 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
39 throws Exception {
40 return super.handleRequest(request, response);
41 }
42
43 @Override
44 protected ModelAndView handleRequestInternal(HttpServletRequest request,
45 HttpServletResponse response) throws Exception {
46
47 String cookieName = ServletRequestUtils.getStringParameter(request, "cn");
48 String state = ServletRequestUtils.getStringParameter(request, "state");
49 if (cookieName != null && state != null) {
50 cookieName = Functions.safeCookieName(cookieName);
51
52 response.addHeader("Set-Cookie",
53 cookieName + '=' + state + "; Expires="
54 + sdf.format(new Date(System.currentTimeMillis() + 315360000000L))
55 + "; Secure=true; HttpOnly=true");
56 }
57 return null;
58 }
59 }