1 | |
---|
2 | import java.io.*; |
---|
3 | import java.util.*; |
---|
4 | |
---|
5 | import 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 | */ |
---|
11 | public 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 | /* |
---|
33 | role="[keyid:${pID}].role:delicious" |
---|
34 | principal="[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 | } |
---|
66 | |
---|
67 | ctxt.free_context_now(); |
---|
68 | System.out.println("done, main from prover_test.java"); |
---|
69 | } |
---|
70 | } |
---|