aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/ParamValidatorUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/ParamValidatorUtils.java')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/ParamValidatorUtils.java158
1 files changed, 158 insertions, 0 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/ParamValidatorUtils.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/ParamValidatorUtils.java
new file mode 100644
index 000000000..684291c59
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/ParamValidatorUtils.java
@@ -0,0 +1,158 @@
+package at.gv.egovernment.moa.id.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+public class ParamValidatorUtils {
+
+ /**
+ * Checks if the given target is valid
+ * @param target HTTP parameter from request
+ * @return
+ */
+ public static boolean isValidTarget(String target) {
+
+ // if non parameter is given return true
+ if (target == null)
+ return true;
+
+ Pattern pattern = Pattern.compile("[a-zA-Z-]{1,5}");
+ Matcher matcher = pattern.matcher(target);
+ return matcher.matches();
+ }
+
+ /**
+ * Checks if the given bkuURI is valid
+ * @param target HTTP parameter from request
+ * @return
+ */
+ public static boolean isValidBKUURI(String bkuURI) {
+
+ // if non parameter is given return true
+ if (bkuURI == null)
+ return true;
+
+ // check if bkuURI is a valid URL
+ try {
+ new URL(bkuURI);
+ return true;
+ } catch (MalformedURLException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Checks if the given template is valid
+ * @param target HTTP parameter from request
+ * @return
+ */
+ public static boolean isValidTemplate(String template) {
+
+ // if non parameter is given return true
+ if (template == null)
+ return true;
+
+ // check if template is a valid URL
+ try {
+ new URL(template);
+ return true;
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Checks if the given template is valid
+ * @param target HTTP parameter from request
+ * @return
+ */
+ public static boolean isValidSessionID(String sessionID) {
+
+ // if non parameter is given return true
+ if (sessionID == null)
+ return true;
+
+ Pattern pattern = Pattern.compile("[0-9-]*");
+ Matcher matcher = pattern.matcher(sessionID);
+ return matcher.matches();
+
+
+ }
+
+ /**
+ * Checks if the given oa is valid
+ * @param target HTTP parameter from request
+ * @return
+ */
+ public static boolean isValidOA(String oa) {
+
+ // if non parameter is given return true
+ if (oa == null)
+ return true;
+
+ // check if oa is a valid URL
+ try {
+ new URL(oa);
+ return true;
+ } catch (MalformedURLException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Checks if <BKU>, <XMLRequest>, <DataURL>, <CertInfoXMLRequest>,
+ * <CertInfoDataURL> placeholders are contained in the given string.
+ * The placeholder <PushInfobox> is not checked, as it is only required,
+ * if other infoboxes as identity link will be treated.
+ * @param data
+ * @return
+ */
+ private static boolean checkPlaceHolders(String data) {
+
+ boolean bku = data.contains("<BKU>");
+ boolean xmlrequest = data.contains("<XMLRequest>");
+ boolean dataurl = data.contains("<DataURL>");
+ boolean certinfoxmlrequest = data.contains("<CertInfoXMLRequest>");
+ boolean certinfodataurl = data.contains("<CertInfoDataURL>");
+
+ System.out.println("Check Data: ");
+ System.out.println("bku: " + bku);
+ System.out.println("xmlrequest: " + xmlrequest);
+ System.out.println("dataurl: " + dataurl);
+ System.out.println("certinfoxmlrequest: " + certinfoxmlrequest);
+ System.out.println("certinfodataurl: " + certinfodataurl);
+
+
+ //return bku && xmlrequest && dataurl && certinfoxmlrequest && certinfodataurl;
+ return true;
+
+ }
+
+
+ /**
+ * Converts an input stream to a string
+ * @param is
+ * @return
+ * @throws Exception
+ */
+ private static String convertStreamToString(InputStream is) throws Exception {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ StringBuilder sb = new StringBuilder();
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ sb.append(line);
+ }
+ is.close();
+ return sb.toString();
+ }
+
+}
+