private boolean validateJsonConf() throws IOException, ProcessingException {
   JsonNode schemaNode =
       JsonLoader.fromFile(new File("src/main/resources/ConfigurationSchema.json"));
   JsonSchemaFactory schemaFactory = JsonSchemaFactory.byDefault();
   /*
   Here we consume the original jsonConfigReader in the process of validation and recreate a Reader from JsonNode
   then assign it back to the jsonConfigReader, if the validation succeed.
   Can we improve this logic?
    */
   if (schemaFactory.getSyntaxValidator().schemaIsValid(schemaNode)) {
     JsonSchema jsonSchema = schemaFactory.getJsonSchema(schemaNode);
     JsonNode topologyConfig = JsonLoader.fromReader(jsonConfigReader);
     ProcessingReport report = jsonSchema.validate(topologyConfig);
     if (report.isSuccess()) {
       log.info("Validation succeeded... ");
       log.info(report.toString());
       jsonConfigReader =
           new InputStreamReader(new ByteArrayInputStream(topologyConfig.toString().getBytes()));
       return true;
     } else {
       log.error("Validation failed...");
       log.error(report.toString());
       throw new RuntimeException(
           "Configuration file validation failed, Please recheck configuration file and try again");
     }
   } else {
     log.error("Json configuration schema is not valid ");
     log.error("Terminate the process .....");
     throw new RuntimeException("Json Configuration schema is not valid");
   }
 }
Beispiel #2
0
  public static Result post() throws IOException {

    Resource user = Resource.fromJson(JSONForm.parseFormData(request().body().asFormUrlEncoded()));
    Map<String, Object> scope = new HashMap<>();

    ProcessingReport report = user.validate();
    user.put("mbox_sha1sum", Account.getEncryptedEmailAddress(user));
    if (mConf.getBoolean("user.email.unique")) {
      ensureEmailUnique(user, report);
    }
    if (!report.isSuccess()) {
      scope.put("countries", Countries.list(currentLocale));
      scope.put("user", user);
      return badRequest(
          render(
              "Registration",
              "UserIndex/index.mustache",
              scope,
              JSONForm.generateErrorReport(report)));
    }

    newsletterSignup(user);
    user.remove("email");
    mBaseRepository.addResource(user);

    List<Map<String, Object>> messages = new ArrayList<>();
    HashMap<String, Object> message = new HashMap<>();
    message.put("level", "success");
    message.put("message", i18n.get("user_registration_feedback"));
    messages.add(message);
    return ok(render("Registration", "feedback.mustache", scope, messages));
  }
Beispiel #3
0
  public static Result sendToken() {
    Resource user = Resource.fromJson(JSONForm.parseFormData(request().body().asFormUrlEncoded()));
    ProcessingReport report = user.validate();
    if (!report.isSuccess()) {
      return badRequest(
          render(
              "Request Token",
              "Secured/token.mustache",
              user,
              JSONForm.generateErrorReport(report)));
    }
    String token = Account.createTokenFor(user);
    sendTokenMail(user, token);

    List<Map<String, Object>> messages = new ArrayList<>();
    HashMap<String, Object> message = new HashMap<>();
    message.put("level", "success");
    message.put("message", i18n.get("user_token_request_feedback"));
    messages.add(message);
    return ok(render("Request Token", "feedback.mustache", user, messages));
  }