1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.error;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import org.springframework.beans.factory.annotation.Value;
17 import org.springframework.stereotype.Controller;
18 import org.springframework.web.bind.annotation.RequestMapping;
19 import org.springframework.web.servlet.ModelAndView;
20 import org.springframework.web.servlet.mvc.AbstractController;
21
22
23
24
25
26 @Controller
27 public class Error403Controller extends AbstractController {
28
29
30 private String viewName;
31
32
33 private String ajaxViewName;
34
35
36 private String ajaxExtension;
37
38
39
40
41
42
43 public String getViewName() {
44 return viewName;
45 }
46
47
48
49
50
51
52 @Value("errors/403")
53 public void setViewName(String viewName) {
54 this.viewName = viewName;
55 }
56
57
58
59
60
61
62 public String getAjaxViewName() {
63 return ajaxViewName;
64 }
65
66
67
68
69
70
71 @Value("errors/403_ajax")
72 public void setAjaxViewName(String ajaxViewName) {
73 this.ajaxViewName = ajaxViewName;
74 }
75
76
77
78
79
80
81 public String getAjaxExtension() {
82 return ajaxExtension;
83 }
84
85
86
87
88
89
90 @Value(".ajax")
91 public void setAjaxExtension(String ajaxExtension) {
92 this.ajaxExtension = ajaxExtension;
93 }
94
95 @RequestMapping(path = "/403.htm")
96 @Override
97 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
98 throws Exception {
99 return super.handleRequest(request, response);
100 }
101
102 @Override
103 protected ModelAndView handleRequestInternal(HttpServletRequest request,
104 HttpServletResponse response) throws Exception {
105
106 String originalUri = (String) request.getAttribute("jakarta.servlet.error.request_uri");
107 if (originalUri != null && originalUri.endsWith(ajaxExtension)) {
108 return new ModelAndView(ajaxViewName);
109 }
110 return new ModelAndView(viewName);
111 }
112
113 }