summaryrefslogtreecommitdiffstats
path: root/java/src/main/java/com/redhat/app/MappingApp.java
blob: 511a823cd0f025a08179552f2a7bd26e58505926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.redhat.app;


import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

import com.redhat.IdpMapping.InvalidTypeException;
import com.redhat.IdpMapping.IdpJson;
import com.redhat.IdpMapping.RuleProcessor;
import com.redhat.IdpMapping.InvalidRuleException;
import com.redhat.IdpMapping.UndefinedValueException;

class MappingApp {
  private static final Logger log = Logger.getLogger(MappingApp.class);


  private static String loadFile(String path) throws IOException {
    byte[] encoded = Files.readAllBytes(Paths.get(path));
    return new String(encoded, "UTF-8");
  }

  public static void main(String[] args) {
    BasicConfigurator.configure();
    log.info("Federated Mapping");

    String rulesFilename = args[0];
    String assertionFilename = "/home/jdennis/src/misc/federation_mapping/assertion-01.json";
    String assertionJson;
    Map<String, Object> mapped;
    IdpJson json = new IdpJson();
    RuleProcessor rp = null;

    try {
      rp = new RuleProcessor(Paths.get(rulesFilename), null); // FIXME, mappings parameter
      assertionJson = loadFile(assertionFilename);

    } catch (IOException e) {
      log.error(e);
      return;
    }
    try {
      mapped = rp.process(assertionJson);
      System.out.println(String.format("mapped=%s", mapped));
      if (mapped != null) {
        System.out.println(json.dumpJson(mapped));
      }
    } catch (InvalidRuleException | UndefinedValueException | InvalidTypeException e) {
      // e.printStackTrace();
      log.error(e);
    }
  }
}