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");
   }
 }
  @Override
  public void validate(
      final Processor<FullData, FullData> processor,
      final ProcessingReport report,
      final MessageBundle bundle,
      final FullData data)
      throws ProcessingException {
    final SchemaTree tree = data.getSchema();
    final JsonPointer schemaPointer = tree.getPointer();
    final JsonNode schemas = tree.getNode().get(keyword);
    final int size = schemas.size();
    final ObjectNode fullReport = FACTORY.objectNode();

    int nrSuccess = 0;
    ListProcessingReport subReport;
    JsonPointer ptr;
    FullData newData;

    for (int index = 0; index < size; index++) {
      subReport = new ListProcessingReport(report.getLogLevel(), LogLevel.FATAL);
      ptr = schemaPointer.append(JsonPointer.of(keyword, index));
      newData = data.withSchema(tree.setPointer(ptr));
      processor.process(subReport, newData);
      fullReport.put(ptr.toString(), subReport.asJson());
      if (subReport.isSuccess()) nrSuccess++;
    }

    if (nrSuccess == 0)
      report.error(
          newMsg(data, bundle, "err.common.schema.noMatch")
              .putArgument("nrSchemas", size)
              .put("reports", fullReport));
  }
Beispiel #3
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 #4
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));
  }
Beispiel #5
0
 private static void ensureEmailUnique(Resource user, ProcessingReport aReport) {
   String aEmail = user.get("mbox_sha1sum").toString();
   if ((!mBaseRepository
       .getResourcesByContent("Person", "mbox_sha1sum", aEmail, true)
       .isEmpty())) {
     ProcessingMessage message = new ProcessingMessage();
     message.setMessage("This e-mail address is already registered");
     ObjectNode instance = new ObjectNode(JsonNodeFactory.instance);
     instance.put("pointer", "/mbox_sha1sum");
     message.put("instance", instance);
     try {
       aReport.error(message);
     } catch (ProcessingException e) {
       e.printStackTrace();
     }
   }
 }