From d298630f92308c462a5b7ae37942f92dcc4d4d21 Mon Sep 17 00:00:00 2001 From: Christian Maierhofer Date: Tue, 29 Mar 2016 14:44:12 +0200 Subject: added signature block positioning --- .../at/gv/egiz/simpleSigning/StartSignature.java | 102 ++++++++++++++++++++- .../egiz/simpleSigning/helper/SessionHelper.java | 63 +++++++++++++ 2 files changed, 164 insertions(+), 1 deletion(-) (limited to 'simpleSigning/src/main/java/at/gv') diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java index 70741ed..69f60d5 100644 --- a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java @@ -45,6 +45,12 @@ public class StartSignature extends HttpServlet { private static final String PARAM_QRCODE = "QRCODE"; private static final String PARAM_NEW = "NEW"; private static final String PARAM_NEW_V = "1"; + + private static final String PARAM_SIG_POS_X = "SIG_POS_X"; + private static final String PARAM_SIG_POS_Y = "SIG_POS_Y"; + private static final String PARAM_SIG_POS_P = "SIG_POS_P"; + private static final String PARAM_SIG_POS_W = "SIG_POS_W"; + private static final String PARAM_SIG_POS_F = "SIG_POS_F"; public StartSignature() { super(); @@ -138,6 +144,12 @@ public class StartSignature extends HttpServlet { String targetUrl = req.getParameter(PARAM_TARGETURL); String qrCodeData = req.getParameter(PARAM_QRCODE); String localeData = req.getParameter(PARAM_LOCALE); + + String sigPosX = req.getParameter(PARAM_SIG_POS_X); + String sigPosY = req.getParameter(PARAM_SIG_POS_Y); + String sigPosP = req.getParameter(PARAM_SIG_POS_P); + String sigPosW = req.getParameter(PARAM_SIG_POS_W); + String sigPosF = req.getParameter(PARAM_SIG_POS_F); // Step 1. Setup Parameters if (type != null) { @@ -200,6 +212,53 @@ public class StartSignature extends HttpServlet { } } + + //Position Params + if (sigPosX != null && !sigPosX.isEmpty()) { + if(isNumeric(sigPosX, req, resp)==false) + return; + // If we have a type set it + SessionHelper.setSigPosX(req, sigPosX); + + logger.trace("[" + req.getSession().getId() + + "]: setting SigPosX to: " + sigPosX); + } + if (sigPosY != null && !sigPosY.isEmpty()) { + if(isNumeric(sigPosY, req, resp)==false) + return; + // If we have a type set it + SessionHelper.setSigPosY(req, sigPosY); + + logger.trace("[" + req.getSession().getId() + + "]: setting SigPosY to: " + sigPosY); + } + if (sigPosP != null && !sigPosP.isEmpty()) { + if(isNumeric(sigPosP, req, resp)==false) + return; + // If we have a type set it + SessionHelper.setSigPosP(req, sigPosP); + + logger.trace("[" + req.getSession().getId() + + "]: setting SigPosP to: " + sigPosP); + } + if (sigPosW != null && !sigPosW.isEmpty()) { + if(isNumeric(sigPosW, req, resp)==false) + return; + // If we have a type set it + SessionHelper.setSigPosW(req, sigPosW); + + logger.trace("[" + req.getSession().getId() + + "]: setting SigPosW to: " + sigPosW); + } + if (sigPosF != null && !sigPosF.isEmpty()) { + if(isNumeric(sigPosF, req, resp)==false) + return; + // If we have a type set it + SessionHelper.setSigPosF(req, sigPosF); + + logger.trace("[" + req.getSession().getId() + + "]: setting SigPosF to: " + sigPosF); + } if ((SessionHelper.getContent(req) == null && SessionHelper .getDocument(req) == null) @@ -386,7 +445,27 @@ public class StartSignature extends HttpServlet { if (SessionHelper.getLocale(req) != null) { entry += ""; - } + } + if (SessionHelper.getSigPosX(req) != null){ + entry += ""; + } + if (SessionHelper.getSigPosY(req) != null){ + entry += ""; + } + if (SessionHelper.getSigPosP(req) != null){ + entry += ""; + } + if (SessionHelper.getSigPosW(req) != null){ + entry += ""; + } + if (SessionHelper.getSigPosF(req) != null){ + entry += ""; + } template = template.replace("##ADDITIONAL##", entry); @@ -415,4 +494,25 @@ public class StartSignature extends HttpServlet { .toError(req, resp, "Something went wrong", e.getMessage()); } } + + private static boolean isNumeric(String nr, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException + { + try + { + Double.parseDouble(nr); + } + catch(NumberFormatException e) + { + logger.error("[" + + req.getSession().getId() + + "]: Failed to generate signature Data!: Position Parameter is not numeric"); + PDFHelper.toError(req, resp, + "Failed to get signature Data", + "Position Parameter is not numeric"); + return false; + + } + return true; + + } } diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/helper/SessionHelper.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/helper/SessionHelper.java index bc86da6..0d06a36 100644 --- a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/helper/SessionHelper.java +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/helper/SessionHelper.java @@ -22,6 +22,12 @@ public class SessionHelper { private static final String SESSION_TYPE_PDF = "PDF"; private static final String SESSION_TYPE_BASE64 = "B64"; + private static final String SESSION_SIG_POS_X = "SESSION_SIG_POS_X"; + private static final String SESSION_SIG_POS_Y = "SESSION_SIG_POS_Y"; + private static final String SESSION_SIG_POS_P = "SESSION_SIG_POS_P"; + private static final String SESSION_SIG_POS_W = "SESSION_SIG_POS_W"; + private static final String SESSION_SIG_POS_F = "SESSION_SIG_POS_F"; + private static final Logger logger = LoggerFactory .getLogger(SessionHelper.class); @@ -171,4 +177,61 @@ public class SessionHelper { logger.info("Killing Session: " + request.getSession().getId()); request.getSession().invalidate(); } + + public static void setSigPosX(HttpServletRequest request, String value) { + request.getSession().setAttribute(SESSION_SIG_POS_X, value); + } + public static void setSigPosY(HttpServletRequest request, String value) { + request.getSession().setAttribute(SESSION_SIG_POS_Y, value); + } + public static void setSigPosP(HttpServletRequest request, String value) { + request.getSession().setAttribute(SESSION_SIG_POS_P, value); + } + public static void setSigPosW(HttpServletRequest request, String value) { + request.getSession().setAttribute(SESSION_SIG_POS_W, value); + } + public static void setSigPosF(HttpServletRequest request, String value) { + request.getSession().setAttribute(SESSION_SIG_POS_F, value); + } + + public static String getSigPosX(HttpServletRequest request) { + Object s = request.getSession().getAttribute(SESSION_SIG_POS_X); + if (s != null) { + return s.toString(); + } else { + return null; + } + } + public static String getSigPosY(HttpServletRequest request) { + Object s = request.getSession().getAttribute(SESSION_SIG_POS_Y); + if (s != null) { + return s.toString(); + } else { + return null; + } + } + public static String getSigPosP(HttpServletRequest request) { + Object s = request.getSession().getAttribute(SESSION_SIG_POS_P); + if (s != null) { + return s.toString(); + } else { + return null; + } + } + public static String getSigPosW(HttpServletRequest request) { + Object s = request.getSession().getAttribute(SESSION_SIG_POS_W); + if (s != null) { + return s.toString(); + } else { + return null; + } + } + public static String getSigPosF(HttpServletRequest request) { + Object s = request.getSession().getAttribute(SESSION_SIG_POS_F); + if (s != null) { + return s.toString(); + } else { + return null; + } + } } -- cgit v1.2.3