source: examples/example_scripts/java/prover_test.java @ 20eaefe

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

1) tweak java examples

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