Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
93   270   32   23.25
54   139   0.38   4
4     8.75  
1    
 
 
  SimplePERMISACPolicyFinder       Line # 61 93 32 60.9% 0.6092715
 
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.pba.*;
48    import issrg.pba.rbac.*;
49    import java.security.Principal;
50    import org.apache.log4j.Logger;
51    import issrg.SAWS.*; // added for MSoD
52   
53    /**
54    * This is a simple Policy Finder that can be instantiated from an instance of
55    * an X.509 Attribute Certificate. It is useful to extend from: collect the
56    * Attribute Certificates, then invoke initPolicyFromACArray to initialise the
57    * Policy Finder.
58    *
59    * @author gansen
60    */
 
61    public class SimplePERMISACPolicyFinder extends PolicyFinder{
62    private Logger logger = Logger.getLogger("issrg.pba.rbac.x509.SimplePERMISACPolicyFinder");
63    private issrg.pba.AuthzTokenParser tokenParser=CustomisePERMIS.getAuthTokenParser();
64   
 
65  14 toggle protected SimplePERMISACPolicyFinder(){
66  14 super();
67    }
68   
69    /**
70    * This constructor builds a Policy Finder given an AC, the identifier of
71    * the policy and the identity of the policy issuer. Only if the AC holds
72    * the required policy construction succeeds. This constructor invokes the
73    * initPolicyFromACArray directly, see that method description for
74    * additional details.
75    *
76    * @param acBinary - the array of byte arrays, each representing a
77    * BER-encoded or Base64 encoding of a BER-encoded X.509 AC
78    * @param policyID - the identifier of the policy to use
79    * @param SOA - the Principal naming the issuer of the policy (must be the
80    * Holder and Issuer of the self-signed Attribute Certificate)
81    * @param SV - the SignatureVerifier to use; if null, digital signatures on
82    * the ACs are not checked (NOT RECOMMENDED FOR PRODUCTION DEPLOYMENTS!)
83    */
 
84  0 toggle public SimplePERMISACPolicyFinder(byte[] acBinary, String PolicyId, Principal SOA,
85    SignatureVerifier SV) throws PbaException {
86  0 this();
87  0 initPolicyFromACArray(new byte[][]{acBinary}, PolicyId, SOA, SV);
88    }
89   
90    //Bassem: added to input log level
 
91  0 toggle public SimplePERMISACPolicyFinder(byte[] acBinary, String PolicyId, Principal SOA,
92    SignatureVerifier SV, int SATLevel) throws PbaException {
93  0 this();
94  0 satLevel=SATLevel;
95  0 initPolicyFromACArray(new byte[][]{acBinary}, PolicyId, SOA, SV);
96    }
97    /**
98    * This method looks for the right policy among an array of X.509 Attribute
99    * Certificates. The policy is identified by its Policy ID (OID in PERMIS
100    * XML) and the name of the issuer of the policy. The signatures on the
101    * ACs are validated using the SignatureVerifier provided, if any.
102    *
103    * @param acBinary - the array of byte arrays, each representing a
104    * BER-encoded or Base64 encoding of a BER-encoded X.509 AC
105    * @param policyID - the identifier of the policy to use
106    * @param SOA - the Principal naming the issuer of the policy (must be the
107    * Holder and Issuer of the self-signed Attribute Certificate)
108    * @param SV - the SignatureVerifier to use; if null, digital signatures on
109    * the ACs are not checked (NOT RECOMMENDED FOR PRODUCTION DEPLOYMENTS!)
110    */
111   
 
112  14 toggle protected void initPolicyFromACArray(byte[][] acBinary, String policyID, Principal SOA,
113    SignatureVerifier SV) throws PbaException{
114  14 this.policyOID=policyID.intern();
115  14 this.sv=SV;
116   
117    //Bassem
118  14 this.soa=SOA.getName();
119    // added for MSoD
120    //Bassem: should create a SAWS if MSoDpolicy exists or if SATlevel>No-info
121  14 if(sawsServer==null){
122  10 if(satLevel>SAWSLogLevelConstant.NO_INFO){
123    //Bassem:
124  0 System.out.println("creating a saws server in simpleACpolicyFinder because of loglevels");
125  0 sawsServer = new SAWSServer();
126    }
127    }
128   
129   
130   
131  14 issrg.utils.repository.TokenLocator soaTokenLocator=new issrg.pba.repository.UserEntry(SOA);
132   
133  14 try{
134  14 issrg.pba.PolicyParser pp = null;
135  14 Throwable lastError = null; // this variable keeps the errors encountered during parsing the attributes
136   
137  14 String message = "No ACs have been provided";
138   
139  14 boolean selfSignedExists = false;
140  14 boolean signatureVerified = false;
141  14 boolean policyAttrExists = false;
142  14 boolean correctPolicyOID = false;
143  14 byte[] byteAC=null;
144  14 issrg.ac.AttributeCertificate ac=null;
145   
146  14 if (acBinary!=null && acBinary.length>0){
147   
148  14 policy_found:
149  14 for (int i=0; i<acBinary.length; i++){
150  14 try{
151  14 byteAC=acBinary[i];
152  14 ac = issrg.ac.AttributeCertificate.guessEncoding(byteAC);
153   
154  14 if (!(SOA.equals(new LDAPDNPrincipal(issrg.ac.Util.generalNamesToString(ac.getACInfo().getHolder().getEntityName())))
155  14 && SOA.equals(new LDAPDNPrincipal(issrg.ac.Util.generalNamesToString(ac.getACInfo().getIssuer().getV1Form()==null?ac.getACInfo().getIssuer().getV2Form().getIssuerName():ac.getACInfo().getIssuer().getV1Form()))))){
156    // not self-issued and is not issued by the SOA
157  0 continue; // pick next AC
158    }
159    }catch(Exception e){
160    //error occurs, we just ignore and search for the next one
161  0 lastError=lastError==null ? e : new issrg.utils.ExceptionPairException(lastError, e);
162  0 continue;
163    }
164   
165  14 if((satLevel>SAWSLogLevelConstant.NO_INFO)&& (sawsServer!=null)){
166    //Bassem: should add the policy information
167  4 StartedRecord rec2=new StartedRecord(ac.toString());
168  4 sawsServer.sendLogRecord(rec2.toBytes());
169    // System.out.println("Writing Starting Policy succeeded to SAWS server");
170    }
171  14 selfSignedExists = true;
172  14 signatureVerified = false;
173  14 if (SV!=null) {
174  9 try{
175  9 if (!SV.checkSignature(ac.getToBeSignedByteArray(byteAC),
176    (byte[])ac.getSignatureValue().getValue(),
177    ac.getSignatureAlgorithm().getAlgorithm().getID(),
178  0 soaTokenLocator)) continue;
179    }catch(PbaException pe){
180  0 lastError=lastError==null ? (Exception)pe : (Exception)new issrg.utils.ExceptionPairException(lastError, pe);
181  0 continue;
182    }
183    }
184   
185  14 signatureVerified = true;
186   
187  14 policyAttrExists = false;
188   
189  14 java.util.Vector attributes = ac.getACInfo().getAttributes();
190  14 for (int j=attributes.size(); j-->0; ){
191  14 issrg.ac.Attribute a = (issrg.ac.Attribute)attributes.get(j);
192  14 if (a.getType().intern() == issrg.ac.attributes.PMIXMLPolicy.PMI_XML_POLICY_ATTRIBUTE_OID){ // a-ha! :-)
193  14 policyAttrExists = true;
194  14 correctPolicyOID = false;
195   
196  14 java.util.Vector values = a.getValues();
197  14 for (int k=values.size(); k-->0; ){ // looking for the needed Policy there
198  14 try{
199  14 issrg.ac.attributes.PMIXMLPolicy pmiPolicy = new issrg.ac.attributes.PMIXMLPolicy((issrg.ac.AttributeValue)values.get(k));
200  14 pp = new issrg.pba.rbac.xmlpolicy.XMLPolicyParser(removeSystemTag(pmiPolicy.getPolicy()));
201  14 if (pp.getPolicyID().intern()==policyOID){
202   
203  14 correctPolicyOID = true;
204  14 if (logger.isDebugEnabled()){
205  0 logger.debug("Policy Finder Policy:\n"+pmiPolicy.getPolicy());
206    }
207  14 break policy_found;
208    }
209    }catch (Throwable th){
210  0 lastError=lastError==null ? th : new issrg.utils.ExceptionPairException(lastError, th);
211    }
212    }
213   
214    }
215  0 pp=null;
216    }
217    }
218   
219  0 if (!correctPolicyOID) message = "No valid AC with a pmiXMLPolicy attribute has a policy with OID "+policyOID;
220  0 if (!policyAttrExists) message = "Found no valid AC with a pmiXMLPolicy attribute";
221  0 if (!signatureVerified) message = "Signature verification failed on all self-signed ACs";
222  0 if (!selfSignedExists) message = "Found no self-signed AC (issuer=holder=SOA)";
223    }
224   
225  14 if (pp==null){ // then there was some error during processing the bunch of ACs
226  0 PbaException exx= new PbaException(message, lastError);
227    //Bassem: added for SAWS log
228  0 if((satLevel>SAWSLogLevelConstant.POLICY_CHANGE)&& sawsServer!=null)
229  0 sawsServer.sendLogRecord(new ExceptionSAWSRecord(exx).toBytes());
230  0 throw exx;
231    }
232   
233  14 this.parsedPolicy=pp;
234   
235   
236   
237   
238   
239  14 if (pp.getMSoDSet() != null) {
240  4 RetainedADI retainedADI = new RetainedADI(); // to be initialised further by logs
241    //Bassem: new SAWSServer if SAWSServer=null, that is, it is not created above
242  4 if(sawsServer==null){
243  0 System.out.println("creating a saws server in simpleACpolicyFinder because of MSoDPolicy");
244  0 sawsServer = new SAWSServer();
245    }
246   
247  4 msodPolicySet = new issrg.pba.rbac.policies.MSoDPolicySet(pp.getMSoDSet(), retainedADI, sawsServer, pp);
248    }
249   
250  14 allocationPolicy=new issrg.pba.rbac.policies.AllocationPolicy(pp.getAssignmentRules());
251   
252    //The following was changed for MSoD ***************************
253  14 if (msodPolicySet == null)
254  10 accessPolicy = new issrg.pba.rbac.policies.AccessPolicy(pp.getAccessRules());
255    else
256  4 accessPolicy = new issrg.pba.rbac.policies.AccessPolicy(pp.getAccessRules(), msodPolicySet);
257   
258   
259    }catch (Throwable th){
260  0 PbaException exx= new PbaException(" Policy finder Could not initialise", th);
261    //Bassem: added for SAWS log
262  0 if((satLevel>SAWSLogLevelConstant.POLICY_CHANGE)&& sawsServer!=null){
263  0 sawsServer.sendLogRecord(new ExceptionSAWSRecord(exx).toBytes());
264    //should close the log here since no PF object will be created, so this cannot be managed by the application
265  0 sawsServer.closeLog();
266    }
267  0 throw exx;
268    }
269    }
270    }