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