Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
31   158   15   15.5
14   64   0.52   2
2     8  
1    
 
 
  RepositoryACPolicyFinder       Line # 66 31 15 76.6% 0.7659575
 
No Tests
 
1    /*
2    * Copyright (c) 2006, University of Kent
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10    *
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14    *
15    * 1. Neither the name of the University of Kent nor the names of its
16    * contributors may be used to endorse or promote products derived from this
17    * software without specific prior written permission.
18    *
19    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22    * PURPOSE ARE DISCLAIMED.
23    *
24    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31    * POSSIBILITY OF SUCH DAMAGE.
32    *
33    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
34    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
35    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
36    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
37    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
38    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
39    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
40    * SERIOUS FAULTS, IN THIS SOFTWARE.
41    *
42    * 5. This license is governed, except to the extent that local laws
43    * necessarily apply, by the laws of England and Wales.
44    */
45    package issrg.pba.rbac.x509;
46   
47    import issrg.SAWS.SAWSServer;
48    import issrg.pba.PbaException;
49    import issrg.pba.rbac.CustomisePERMIS;
50    import issrg.pba.rbac.ExceptionSAWSRecord;
51    import issrg.pba.rbac.SAWSLogLevelConstant;
52    import issrg.pba.rbac.Record;
53    import issrg.pba.rbac.URLHandler;
54    import issrg.pba.rbac.SignatureVerifier;
55    import issrg.utils.repository.AttributeRepository;
56    import java.security.Principal;
57   
58    /**
59    * This PolicyFinder can locate a PERMIS policy in one of the ACs retrieved from
60    * the SOA's repository entry. To do that, it needs to know the SOA's
61    * entry name, the identifier of the policy (policy OID in PERMIS XML), the
62    * AttributeRepository and the SignatureVerifier.
63    *
64    * @author Sassa
65    */
 
66    public class RepositoryACPolicyFinder extends SimplePERMISACPolicyFinder{
67   
68    /**
69    * Given the inputs, it finds all the X.509 Attribute Certificates that
70    * are in the entry of the SOA and initialises the Policy Finder with that.
71    *
72    * @param attRep - the AttributeRepository with the SOA's entry in it
73    * containing the X.509 Attribute Certificates, one of which must have the
74    * PERMIS Policy
75    * @param PolicyId - the identifier of the Policy that must be loaded
76    * (Policy OID in PERMIS XML)
77    * @param SOA - the Principal naming the SOA's entry in the
78    * AttributeRepository
79    * @param SV - the SignatureVerifier to be used to validate the signatures
80    * on the X.509 Attribute Certificates; if null, no signature verification
81    * is performed
82    *
83    * @throws PbaException, if there was a problem loading the ACs, or if there
84    * was a problem to initialise the Policy Finder with the ACs that were
85    * found.
86    */
 
87  10 toggle public RepositoryACPolicyFinder(AttributeRepository attRep, String PolicyId, Principal SOA,
88    SignatureVerifier SV) throws PbaException {
89  10 super();
90  10 javax.naming.directory.Attribute policyACs=null;
91   
92  10 try{
93  10 policyACs = attRep.getAttribute(SOA, CustomisePERMIS.getAttributeCertificateAttribute());
94    }catch (issrg.utils.repository.RepositoryException re){
95  0 throw new PbaException("Could not retrieve the policies from repository", re);
96    }
97  10 byte [][] acArray=null;
98   
99  10 if (policyACs!=null && policyACs.size()>0){
100  10 acArray = new byte[policyACs.size()][];
101  20 for (int i=0; i<acArray.length; i++) {
102  10 try{
103  10 acArray[i]=(byte [])policyACs.get(i);
104    }catch(Exception e){
105    // ignore problems with the attributes
106    }
107    }
108    }
109    // acArray is null or is an array of byte arrays, each being an AC
110    // initPolicyFromACArray can deal with null arrays and with non-ACs
111   
112  10 initPolicyFromACArray(acArray, PolicyId, SOA, SV);
113    }
114   
115    //Bassem
 
116  4 toggle public RepositoryACPolicyFinder(AttributeRepository attRep, String PolicyId, Principal SOA,
117    SignatureVerifier SV, int SATLevel) throws PbaException{
118  4 super();
119  4 super.satLevel=SATLevel;
120  4 javax.naming.directory.Attribute policyACs=null;
121   
122    //should create SAWS server here in order to log the exceptions !!
123  4 if(sawsServer==null){
124  4 if(satLevel>SAWSLogLevelConstant.NO_INFO){
125    //Bassem:
126    // System.out.println("creating a saws server in RepositoryACpolicyFinder because of loglevels");
127  4 sawsServer = new SAWSServer();
128    }
129    }
130   
131  4 try{
132  4 policyACs = attRep.getAttribute(SOA, CustomisePERMIS.getAttributeCertificateAttribute());
133    }catch (issrg.utils.repository.RepositoryException re){
134  0 PbaException exx= new PbaException("Could not retrieve the policies from repository", re);
135    //Bassem: added for SAWS log
136  0 if((satLevel>SAWSLogLevelConstant.POLICY_CHANGE)&& sawsServer!=null)
137  0 sawsServer.sendLogRecord(new ExceptionSAWSRecord(exx).toBytes());
138  0 throw exx;
139    }
140  4 byte [][] acArray=null;
141   
142  4 if (policyACs!=null && policyACs.size()>0){
143  4 acArray = new byte[policyACs.size()][];
144  8 for (int i=0; i<acArray.length; i++) {
145  4 try{
146  4 acArray[i]=(byte [])policyACs.get(i);
147    }catch(Exception e){
148    // ignore problems with the attributes
149    }
150    }
151    }
152    // acArray is null or is an array of byte arrays, each being an AC
153    // initPolicyFromACArray can deal with null arrays and with non-ACs
154   
155  4 initPolicyFromACArray(acArray, PolicyId, SOA, SV);
156   
157    }
158    }