source: examples/example_scripts/java/prover_test.java @ e3c7769

mei_rt2mei_rt2_fix_1
Last change on this file since e3c7769 was e3c7769, checked in by Mei <mei@…>, 12 years ago

1) wrap up java interface with swig/jni/abac linkup
2) java regression tests
3) update doc related to new java implmentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import java.io.*;
2import java.util.*;
3
4import net.deterlab.abac.*;
5
6/**
7 * Simple test of the swig generated JNI for libabac. Loads credentials
8 * from keystore and runs a query against them.
9 */
10public class prover_test {
11
12    static {
13        System.loadLibrary("jABAC");
14    }
15
16    public static void main(String[] args) throws IOException {
17        if (args.length != 4) {
18            System.out.println("Usage: prover_test <keystore> <issuer> <roletype> <principal>");
19            System.out.println("    runs the query issuer.role <-?- principal and prints the result"
20);
21            System.exit(1);
22        }
23
24        Context ctxt = new Context();
25
26        String keystore=args[0];
27        String iname=args[1];
28        String roletype=args[2];
29        String pname=args[3];
30
31/*
32role="[keyid:${pID}].role:delicious"
33principal="[keyid:${cID}]"
34*/
35        String ifname=iname+"_ID.pem";
36        String pfname=pname+"_ID.pem";
37
38        ID iID=new ID(ifname);
39        ID pID=new ID(pfname);
40
41        String ikeyid=iID.id_keyid();
42        String pkeyid=pID.id_keyid();
43
44        String role="[keyid:"+ikeyid+"].role:"+roletype;
45        String principal="[keyid:"+pkeyid+"]";
46
47        ctxt.load_directory(keystore);
48
49        /* what is in prolog db
50        ctxt.dump_yap_db(); */
51
52        AttributeVector credentials = ctxt.query(role, principal);
53
54        long sz=credentials.size();
55 
56        if(sz > 0)
57            System.out.println("prover success!!");
58        else
59            System.out.println("prover failed!!");
60
61        for(int i=0; i<sz; i++) {
62            Attribute c=credentials.get(i);
63            System.out.println(c.head_string()+"<- "+c.tail_string());
64        }
65
66        ctxt.free_context_now();
67        System.out.println("done, main from prover_test.java");
68    }
69}
Note: See TracBrowser for help on using the repository browser.