source: examples/example_scripts/java/prover_test.java @ f89b991

mei_rt2
Last change on this file since f89b991 was 2e9455f, checked in by Mei <mei@…>, 11 years ago

1) added namespace
2) tweak ?This,
3) allowing linking role/oset as constraining conditions
4) adding access_tests regression testing that uses GENI's access policy
5) added couple multi contexts regression tests
6) add compression/uncompression calls to abac_encode_string/abac_decode_string
(libstrongwan only allows 512 char for attribute rule storage)
7) add attribute_now option to creddy that takes a whole char string for attribute
rule

  • Property mode set to 100644
File size: 1.7 KB
Line 
1
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        }
66
67        System.out.println("done, main from prover_test.java");
68        System.out.flush();
69    }
70}
Note: See TracBrowser for help on using the repository browser.