source: swig/java/ProverTest.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 ProverTest {
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: ProverTest <keystore> <issuer> <roletype> <principal>");
19            System.out.println("    runs the query issuer.roletype <-?- principal and prints the result"
20);
21            System.exit(1);
22        }
23
24        String keystore=args[0];
25        String iname=args[1];
26        String roletype=args[2];
27        String pname=args[3];
28
29        Context ctxt = new Context();
30
31        ctxt.load_directory(keystore);
32
33/*
34role="[keyid:${pID}].role:delicious"
35principal="[keyid:${cID}]"
36*/
37        String ifname=iname+"_ID.pem";
38        String pfname=pname+"_ID.pem";
39
40        ID iID=new ID(ifname);
41        ID pID=new ID(pfname);
42
43        String ikeyid=iID.id_keyid();
44        String pkeyid=pID.id_keyid();
45
46        String role="[keyid:"+ikeyid+"].role:"+roletype;
47        String principal="[keyid:"+pkeyid+"]";
48
49        AttributeVector credentials = ctxt.query(role, principal);
50
51        long sz=credentials.size();
52 
53        if(sz > 0)
54            System.out.println("prover success!!");
55        else
56            System.out.println("prover failed!!");
57
58        for(int i=0; i<sz; i++) {
59            Attribute c=credentials.get(i);
60            System.out.println(c.head_string()+"<- "+c.tail_string());
61        }
62
63        ctxt.free_context_now();
64        System.out.println("ProverTest okay.");
65    }
66}
Note: See TracBrowser for help on using the repository browser.