+ public static <T extends Form> T getForm(HttpServletRequest req, Class<T> target) {
+ String csrf = req.getParameter("csrf");
+ if (csrf == null) {
+ throw new CSRFError();
+ }
+ HttpSession hs = req.getSession();
+ if (hs == null) {
+ throw new CSRFError();
+ }
+ Form f = (Form) hs.getAttribute("form/" + target.getName() + "/" + csrf);
+ return (T) f;
+ }
+
+ public static class CSRFError extends Error {