1 | import java.io.*; |
---|
2 | import java.util.*; |
---|
3 | |
---|
4 | |
---|
5 | import net.deterlab.abac.*; |
---|
6 | |
---|
7 | /** |
---|
8 | * Test swig generated JNI for libabac in threaded condition. |
---|
9 | * Multiple threads, each loads credentials from keystore and |
---|
10 | * runs a query against them. |
---|
11 | */ |
---|
12 | |
---|
13 | public class threaded_test implements Runnable { |
---|
14 | static String keystore; |
---|
15 | static String iname; |
---|
16 | static String roletype; |
---|
17 | static String pname; |
---|
18 | |
---|
19 | static { |
---|
20 | System.loadLibrary("jABAC"); |
---|
21 | } |
---|
22 | |
---|
23 | public void run(String[] args) { |
---|
24 | System.out.println("Hello from a thread!"); |
---|
25 | |
---|
26 | String _keystore=args[0]; |
---|
27 | String _iname=args[1]; |
---|
28 | String _roletype=args[2]; |
---|
29 | String _pname=args[3]; |
---|
30 | |
---|
31 | Context ctxt = new Context(); |
---|
32 | |
---|
33 | /* |
---|
34 | role="[keyid:${pID}].role:delicious" |
---|
35 | principal="[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 | ctxt.load_directory(keystore); |
---|
50 | |
---|
51 | /* what is in prolog db |
---|
52 | ctxt.dump_yap_db(); */ |
---|
53 | |
---|
54 | AttributeVector credentials = ctxt.query(role, principal); |
---|
55 | |
---|
56 | long sz=credentials.size(); |
---|
57 | |
---|
58 | if(sz > 0) |
---|
59 | System.out.println("prover success!!"); |
---|
60 | else |
---|
61 | System.out.println("prover failed!!"); |
---|
62 | |
---|
63 | for(int i=0; i<sz; i++) { |
---|
64 | Attribute c=credentials.get(i); |
---|
65 | System.out.println(c.head_string()+"<- "+c.tail_string()); |
---|
66 | } |
---|
67 | |
---|
68 | ctxt.free_context_now(); |
---|
69 | System.out.println("done, run from thread_test.java"); |
---|
70 | } |
---|
71 | |
---|
72 | public static void main(String[] args) throws IOException { |
---|
73 | |
---|
74 | if (args.length != 4) { |
---|
75 | System.out.println("Usage: prover_test <keystore> <issuer> <roletype> <principal>"); |
---|
76 | System.out.println(" runs the query issuer.role <-?- principal and prints the result" |
---|
77 | ); |
---|
78 | System.exit(1); |
---|
79 | } |
---|
80 | |
---|
81 | keystore=args[0]; |
---|
82 | iname=args[1]; |
---|
83 | roletype=args[2]; |
---|
84 | pname=args[3]; |
---|
85 | |
---|
86 | (new Thread(new threaded_test(args))).start(); |
---|
87 | } |
---|
88 | } |
---|