X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Foutput%2Ftemplate%2FForm.java;h=3f7ab6d1d06750fdeb7789e7a77149df39ec43c6;hb=4d9a171beff072b638c4b2724f51b3192064b155;hp=83a96f3813ad6bdb0c20bbc817f73f5eb2287b35;hpb=63a050b637aef27c32d84a2a62b91cd4b8276398;p=gigi.git diff --git a/src/org/cacert/gigi/output/template/Form.java b/src/org/cacert/gigi/output/template/Form.java index 83a96f38..3f7ab6d1 100644 --- a/src/org/cacert/gigi/output/template/Form.java +++ b/src/org/cacert/gigi/output/template/Form.java @@ -4,13 +4,11 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.Map; -import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.cacert.gigi.GigiApiException; import org.cacert.gigi.localisation.Language; -import org.cacert.gigi.pages.Page; import org.cacert.gigi.util.RandomToken; /** @@ -73,7 +71,6 @@ public abstract class Form implements Outputable { } else { out.println("
"); } - failed = false; outputContent(out, l, vars); out.print(""); - } - out.print("
"); - if (contents.length == 0) { - out.print(Page.translate(req, text)); - } else { - out.print(String.format(Page.translate(req, text), contents)); - } - out.println("
"); - } - - protected void outputErrorPlain(PrintWriter out, String text) { - if ( !failed) { - failed = true; - out.println("
"); - } - out.print("
"); - out.print(text); - out.println("
"); - } - - public boolean isFailed(PrintWriter out) { - if (failed) { - out.println("
"); - } - return failed; - } - protected String getCSRFToken() { return csrf; } @@ -140,6 +104,7 @@ public abstract class Form implements Outputable { * @throws CSRFException * if no CSRF-token is found or the token is wrong. */ + @SuppressWarnings("unchecked") public static T getForm(HttpServletRequest req, Class target) throws CSRFException { String csrf = req.getParameter(CSRF_FIELD); if (csrf == null) { @@ -149,10 +114,17 @@ public abstract class Form implements Outputable { if (hs == null) { throw new CSRFException(); } - Form f = (Form) hs.getAttribute("form/" + target.getName() + "/" + csrf); + Object f = hs.getAttribute("form/" + target.getName() + "/" + csrf); if (f == null) { throw new CSRFException(); } + if ( !(f instanceof Form)) { + throw new CSRFException(); + } + if ( !target.isInstance(f)) { + throw new CSRFException(); + } + // Dynamic Cast checked by previous if statement return (T) f; }