abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change
on this file since 90f939f was
31b67d5,
checked in by Mike Ryan <mikeryan@…>, 14 years ago
|
initial basic implementation of native java ABAC library
credentials must be loaded from text, there is no crypto
no support for intersections
this code was lifted from crudge, the credential visualizer
|
-
Property mode set to
100644
|
File size:
1.8 KB
|
Line | |
---|
1 | import java.io.*; |
---|
2 | |
---|
3 | import edu.uci.ics.jung.graph.*; |
---|
4 | |
---|
5 | import net.deterlab.abac.Credential; |
---|
6 | import net.deterlab.abac.CredentialGraph; |
---|
7 | import net.deterlab.abac.Query; |
---|
8 | import net.deterlab.abac.Role; |
---|
9 | |
---|
10 | /** |
---|
11 | * Simple test of the native Java implementation of ABAC. Loads credentials |
---|
12 | * from an rt0 file and runs a query against them. |
---|
13 | */ |
---|
14 | public class GraphTest { |
---|
15 | public static void main(String[] args) throws IOException { |
---|
16 | if (args.length < 3) { |
---|
17 | System.out.println("Usage: GraphTest <rt0 file> <role> <principal>"); |
---|
18 | System.out.println(" runs the query role <-?- principal and prints the result"); |
---|
19 | System.exit(1); |
---|
20 | } |
---|
21 | |
---|
22 | String role = args[1]; |
---|
23 | String prin = args[2]; |
---|
24 | |
---|
25 | CredentialGraph graph = new CredentialGraph(); |
---|
26 | |
---|
27 | BufferedReader reader = new BufferedReader(new FileReader(args[0])); |
---|
28 | String line; |
---|
29 | while ((line = reader.readLine()) != null) { |
---|
30 | // skip comments |
---|
31 | if (line.startsWith("#")) |
---|
32 | continue; |
---|
33 | |
---|
34 | String[] parts = line.split("\\s*<--?\\s*"); |
---|
35 | |
---|
36 | if (parts.length != 2) { |
---|
37 | System.out.println("Warning: funky line: " + line); |
---|
38 | continue; |
---|
39 | } |
---|
40 | |
---|
41 | Role head = new Role(parts[0]); |
---|
42 | Role tail = new Role(parts[1]); |
---|
43 | |
---|
44 | if (!head.is_role()) { |
---|
45 | System.out.println("Warning: invalid role in head position: " + line); |
---|
46 | continue; |
---|
47 | } |
---|
48 | |
---|
49 | Credential cred = new Credential(head, tail); |
---|
50 | graph.add_credential(cred); |
---|
51 | } |
---|
52 | |
---|
53 | // |
---|
54 | // run the query |
---|
55 | // |
---|
56 | |
---|
57 | Query q = graph.querier(); |
---|
58 | Graph<Role, Credential> ret = q.run(role, prin); |
---|
59 | for (Credential c : ret.getEdges()) |
---|
60 | System.out.println(c.toString()); |
---|
61 | } |
---|
62 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.