Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
96   178   11   24
12   125   0.15   4
4     3.5  
1    
 
 
  TestIt       Line # 22 96 11 86.6% 0.8660714
 
No Tests
 
1    /*
2    * TestIt.java
3    *
4    * Created on 30 March 2007, 22:25
5    *
6    * To change this template, choose Tools | Template Manager
7    * and open the template in the editor.
8    */
9   
10    package issrg.test.isSufficient;
11   
12    import issrg.pba.AuthzTokenParser;
13    import issrg.pba.Subject;
14    import issrg.pba.rbac.*;
15    import issrg.pba.rbac.x509.RepositoryACPolicyFinder;
16    import java.io.FileOutputStream;
17    import java.io.PrintStream;
18    /**
19    *
20    * @author anhnt
21    */
 
22    public class TestIt {
23   
24    private issrg.utils.repository.VirtualRepository repository;
25    private issrg.pba.repository.AuthzTokenRepository tokenRepository;
26   
27    private iaik.x509.X509Certificate x509;
28    private issrg.security.DefaultSecurity ds;
29    private issrg.pba.rbac.SignatureVerifier sv;
30   
31   
32    private RoleHierarchyPolicy roleHierarchyPolicy;
33    private issrg.pba.rbac.policies.AllocationPolicy allocationPolicy;
34    private AuthzTokenParser parser;
35    private RepositoryACPolicyFinder finder;
36    private PermisRBAC rbac;
37    private String separator;
38   
39    /** Creates a new instance of TestIt */
 
40  2 toggle public TestIt(String[] args) {
41  2 try {
42    // org.apache.log4j.Logger root = Logger.getRootLogger();
43    // root.setLevel(Level.DEBUG);
44    // BasicConfigurator.configure();
45  2 separator = System.getProperty("file.separator");
46  2 CustomisePERMIS.setAttributeCertificateAttribute("attributeCertificateAttribute");
47    // CustomisePERMIS.setUserCertificateAttribute("userCertificate;binary");
48  2 CustomisePERMIS.configureX509Flavour();
49   
50  2 repository = new issrg.utils.repository.VirtualRepository();
51    // x509 = new iaik.x509.X509Certificate(new java.io.FileInputStream(RootPKC));
52    // ds = new issrg.security.PKCS12Security();
53    // ds.setRootCA((byte[])null);
54    // ds.setPKCRepository(new issrg.security.PKCRepository(repository));
55    // sv = new issrg.pba.rbac.SimpleSignatureVerifier(null);
56  2 java.io.InputStream io = new java.io.FileInputStream(args[1].concat(separator).concat("policy.ace"));
57  2 byte[] ac = new byte[io.available()];
58  2 io.read(ac);
59  2 repository.populate("cn=soa,ou=admin,o=permis,c=gb", CustomisePERMIS.getAttributeCertificateAttribute(), ac);
60  2 finder = new issrg.pba.rbac.x509.RepositoryACPolicyFinder(repository, "19.04.2005", new LDAPDNPrincipal("cn=soa,ou=admin,o=permis,c=gb"), null);
61  2 parser = CustomisePERMIS.getAuthTokenParser();
62  2 parser.setAuthTokenParsingRules(finder.getParsedPolicy().getAuthTokenParsingRules());
63  2 tokenRepository = new issrg.simplePERMIS.SimplePERMISAuthzTokenRepository(repository, parser);
64  2 rbac = new PermisRBAC(finder,repository, parser);
65    }catch (Exception e) {}
66    }
67   
 
68  1 toggle public void doTest1(String[] args) {
69  1 try {
70  1 java.io.InputStream io = new java.io.FileInputStream(args[1].concat(separator).concat("disTest1.ace"));
71  1 byte[] ac = new byte[io.available()];
72  1 io.read(ac);
73  1 repository.populate("cn=dis,ou=admin,o=permis,c=gb",CustomisePERMIS.getAttributeCertificateAttribute(), ac);
74  1 io = new java.io.FileInputStream(args[1].concat(separator).concat("aa1Test1.ace"));
75  1 ac = new byte[io.available()];
76  1 io.read(ac);
77  1 repository.populate("cn=aa1,ou=staff,o=permis,c=gb",CustomisePERMIS.getAttributeCertificateAttribute(), ac);
78   
79  1 io = new java.io.FileInputStream(args[1].concat(separator).concat("aa2Test1.ace"));
80  1 ac = new byte[io.available()];
81  1 io.read(ac);
82  1 repository.populate("cn=aa2,ou=staff,o=permis,c=gb",CustomisePERMIS.getAttributeCertificateAttribute(), ac);
83   
84  1 Subject s = rbac.getCreds(new LDAPDNPrincipal("cn=aa1,ou=staff,o=permis,c=gb"));
85  1 System.out.println("Attriute of " + s.getHolder().getName() + " is: " + s.exportCreds().toString());
86  1 if (rbac.decision(s, new PermisAction("open"), new PermisTarget("cn=door,c=gb", null), null)) {
87  1 System.out.println("Action is allowed");
88  0 } else System.out.println("Action is NOT allowed");
89   
90  1 s = rbac.getCreds(new LDAPDNPrincipal("cn=aa2,ou=staff,o=permis,c=gb"));
91  1 System.out.println("Attriute of " + s.getHolder().getName() + " is: " + s.exportCreds().toString());
92  1 if (rbac.decision(s, new PermisAction("open"), new PermisTarget("cn=door,c=gb", null), null)) {
93  0 System.out.println("Action is allowed");
94  1 } else System.out.println("Action is NOT allowed");
95   
96   
97   
98   
99  0 }catch (Exception e){e.printStackTrace();}
100    }
 
101  1 toggle public void doTest2(String[] args) {
102  1 try {
103  1 java.io.InputStream io = new java.io.FileInputStream(args[1].concat(separator).concat("aa1Test2.ace"));
104  1 byte[] ac = new byte[io.available()];
105  1 io.read(ac);
106  1 repository.populate("cn=aa1,ou=staff,o=permis,c=gb",CustomisePERMIS.getAttributeCertificateAttribute(), ac);
107   
108  1 io = new java.io.FileInputStream(args[1].concat(separator).concat("disTest2.ace"));
109  1 ac = new byte[io.available()];
110  1 io.read(ac);
111  1 repository.populate("cn=dis,ou=admin,o=permis,c=gb",CustomisePERMIS.getAttributeCertificateAttribute(), ac);
112   
113  1 io = new java.io.FileInputStream(args[1].concat(separator).concat("aa2Test2.ace"));
114  1 ac = new byte[io.available()];
115  1 io.read(ac);
116  1 repository.populate("cn=aa2,ou=staff,o=permis,c=gb",CustomisePERMIS.getAttributeCertificateAttribute(), ac);
117   
118  1 io = new java.io.FileInputStream(args[1].concat(separator).concat("aa3Test2.ace"));
119  1 ac = new byte[io.available()];
120  1 io.read(ac);
121  1 repository.populate("cn=aa3,ou=staff,o=permis,c=gb",CustomisePERMIS.getAttributeCertificateAttribute(), ac);
122   
123  1 io = new java.io.FileInputStream(args[1].concat(separator).concat("aa4Test2.ace"));
124  1 ac = new byte[io.available()];
125  1 io.read(ac);
126  1 repository.populate("cn=aa4,ou=staff,o=permis,c=gb",CustomisePERMIS.getAttributeCertificateAttribute(), ac);
127   
128   
129  1 Subject s = rbac.getCreds(new LDAPDNPrincipal("cn=aa2,ou=staff,o=permis,c=gb"));
130  1 System.out.println("Attriute of " + s.getHolder().getName() + " is: " + s.exportCreds().toString());
131  1 if (rbac.decision(s, new PermisAction("open"), new PermisTarget("cn=door,c=gb", null), null)) {
132  1 System.out.println("Action is allowed");
133  0 } else System.out.println("Action is NOT allowed");
134   
135  1 s = rbac.getCreds(new LDAPDNPrincipal("cn=aa3,ou=staff,o=permis,c=gb"));
136  1 System.out.println("Attriute of " + s.getHolder().getName() + " is: " + s.exportCreds().toString());
137  1 if (rbac.decision(s, new PermisAction("open"), new PermisTarget("cn=door,c=gb", null), null)) {
138  0 System.out.println("Action is allowed");
139  1 } else System.out.println("Action is NOT allowed");
140   
141   
142  1 s = rbac.getCreds(new LDAPDNPrincipal("cn=aa4,ou=staff,o=permis,c=gb"));
143  1 System.out.println("Attriute of " + s.getHolder().getName() + " is: " + s.exportCreds().toString());
144  1 if (rbac.decision(s, new PermisAction("open"), new PermisTarget("cn=door,c=gb", null), null)) {
145  0 System.out.println("Action is allowed");
146  1 } else System.out.println("Action is NOT allowed");
147   
148  1 System.out.println("Now remove aa4's attribute, issue a new attribute to him and test again ");
149   
150  1 repository.remove("cn=aa4,ou=staff,o=permis,c=gb");
151  1 io = new java.io.FileInputStream(args[1].concat(separator).concat("aa4NewTest2.ace"));
152  1 ac = new byte[io.available()];
153  1 io.read(ac);
154  1 repository.populate("cn=aa4,ou=staff,o=permis,c=gb",CustomisePERMIS.getAttributeCertificateAttribute(), ac);
155   
156  1 s = rbac.getCreds(new LDAPDNPrincipal("cn=aa4,ou=staff,o=permis,c=gb"));
157  1 System.out.println("Attriute of " + s.getHolder().getName() + " is: " + s.exportCreds().toString());
158  1 if (rbac.decision(s, new PermisAction("open"), new PermisTarget("cn=door,c=gb", null), null)) {
159  1 System.out.println("Action is allowed");
160  0 } else System.out.println("Action is NOT allowed");
161   
162  0 }catch (Exception e){e.printStackTrace();}
163    }
164   
 
165  1 toggle public static void main (String[] args) {
166    //String[] args = {"/home/anhnt/work/build/src/issrg/test/isSufficient/"};
167  1 System.setProperty("line.separator", "\r\n");
168  1 try {
169  1 System.setOut(new PrintStream(new FileOutputStream(args[0])));
170  0 } catch (Exception e) { e.printStackTrace();}
171  1 System.setErr(System.out);
172  1 TestIt test1 = new TestIt(args);
173  1 TestIt test2 = new TestIt(args);
174  1 test1.doTest1(args);
175  1 test2.doTest2(args);
176  1 System.out.close();
177    }
178    }