source: examples/example_scripts/java/threaded_test.java @ accd63d

mei_rt2
Last change on this file since accd63d 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: 2.1 KB
Line 
1import java.io.*;
2import java.util.*;
3
4
5import 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
13public 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/*
34role="[keyid:${pID}].role:delicious"
35principal="[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        System.out.println("done, run from thread_test.java");
69    }
70
71    public static void main(String[] args) throws IOException {
72
73        if (args.length != 4) {
74            System.out.println("Usage: prover_test <keystore> <issuer> <roletype> <principal>");
75            System.out.println("    runs the query issuer.role <-?- principal and prints the result"
76);
77            System.exit(1);
78        }
79
80        keystore=args[0];
81        iname=args[1];
82        roletype=args[2];
83        pname=args[3];
84
85        (new Thread(new threaded_test(args))).start();
86    }
87}
Note: See TracBrowser for help on using the repository browser.