Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
42   185   13   14
14   71   0.36   3
3     5  
1    
 
 
  SimplePERMISPolicyFinder       Line # 64 42 13 42.4% 0.42372882
 
No Tests
 
1   
2    /*
3    * Copyright (c) 2006, University of Kent
4    * All rights reserved.
5    *
6    * Redistribution and use in source and binary forms, with or without
7    * modification, are permitted provided that the following conditions are met:
8    *
9    * Redistributions of source code must retain the above copyright notice, this
10    * list of conditions and the following disclaimer.
11    *
12    * Redistributions in binary form must reproduce the above copyright notice,
13    * this list of conditions and the following disclaimer in the documentation
14    * and/or other materials provided with the distribution.
15    *
16    * 1. Neither the name of the University of Kent nor the names of its
17    * contributors may be used to endorse or promote products derived from this
18    * software without specific prior written permission.
19    *
20    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23    * PURPOSE ARE DISCLAIMED.
24    *
25    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32    * POSSIBILITY OF SUCH DAMAGE.
33    *
34    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
35    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
36    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
37    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
38    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
39    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
40    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
41    * SERIOUS FAULTS, IN THIS SOFTWARE.
42    *
43    * 5. This license is governed, except to the extent that local laws
44    * necessarily apply, by the laws of England and Wales.
45    *
46    * Author : Gansen Zhao <gz7@kent.ac.uk> and Romain Laborde <rl59@kent.ac.uk>
47    *
48    */
49   
50    package issrg.simplePERMIS;
51   
52    import issrg.SAWS.SAWSServer;
53    import java.io.*;
54    import issrg.pba.rbac.*;
55    import org.apache.log4j.Logger;
56   
57    /**
58    *
59    * This class implements the PolicyFinder interface, and provides loading a policy
60    * from a plain text XML file.
61    *
62    * @author Romain & Gansen
63    */
 
64    public class SimplePERMISPolicyFinder extends PolicyFinder {
65   
66   
67    /**
68    * Creates a new instance of SimpleSAMPolicyFinder based on the specified file
69    * and the CustomisePERMIS object.
70    * @param filePath A string representing the file path name of the XML policy file.
71    * It shall suffice to help the system to locate the policy file uniquely. Some systems
72    * allow both relative file path and absolute file path.
73    */
74    private Logger logger = Logger.getLogger("issrg.simplePERMIS.SimplePERMISPolicyFinder");
 
75  10 toggle public SimplePERMISPolicyFinder(String filePath) throws IOException, Throwable{
76   
77  10 this.filepath=filePath;
78  10 String xmlPolicy = fileIntoString(filePath);
79    //System.out.println(xmlPolicy);
80    // if the file cannot be read
81  0 if (xmlPolicy == null) return;
82   
83  10 try{
84    //System.out.println("Constructor of SimplePERMISPolicyFinder");
85   
86  10 xmlPolicy = this.removeSystemTag(xmlPolicy);
87  10 if (logger.isDebugEnabled()){
88  0 logger.debug("Policy Finder Policy:\n" + xmlPolicy);
89    }
90    //System.out.println("xmlpolicy : " +xmlPolicy);
91   
92  10 parsedPolicy = new issrg.pba.rbac.xmlpolicy.XMLPolicyParser(xmlPolicy);
93    }
94    catch(Throwable th){
95  0 throw th;
96    }
97  10 accessPolicy = new issrg.pba.rbac.policies.AccessPolicy(parsedPolicy.getAccessRules());
98    //tokenParser.setAuthTokenParsingRules(parsedPolicy.getAuthTokenParsingRules());
99  10 allocationPolicy = new issrg.pba.rbac.policies.AllocationPolicy(
100    //tokenParser,
101    parsedPolicy.getAssignmentRules()
102    );
103   
104    }
105   
106    //Bassem: for SATLevel
 
107  0 toggle public SimplePERMISPolicyFinder(String filePath, int SATLevel) throws IOException, Throwable{
108  0 this.filepath=filePath;
109  0 this.satLevel=SATLevel;
110  0 if(satLevel>SAWSLogLevelConstant.NO_INFO)
111  0 sawsServer=new SAWSServer();
112   
113  0 String xmlPolicy = fileIntoString(filePath);
114    //System.out.println(xmlPolicy);
115    // if the file cannot be read
116  0 if (xmlPolicy == null) return;
117   
118   
119  0 if((satLevel>SAWSLogLevelConstant.NO_INFO)&& (sawsServer!=null)){
120    //Bassem: should add the policy information
121  0 StartedRecord rec2=new StartedRecord(xmlPolicy);
122  0 sawsServer.sendLogRecord(rec2.toBytes());
123    // System.out.println("Writing Started succeeded to a SAWS server");
124    }
125  0 try{
126    //System.out.println("Constructor of SimplePERMISPolicyFinder");
127   
128  0 xmlPolicy = this.removeSystemTag(xmlPolicy);
129   
130    //System.out.println("xmlpolicy : " +xmlPolicy);
131   
132  0 parsedPolicy = new issrg.pba.rbac.xmlpolicy.XMLPolicyParser(xmlPolicy);
133    }
134    catch(Throwable th){
135   
136    //Bassem: added for SAWS log
137  0 if((satLevel>SAWSLogLevelConstant.POLICY_CHANGE)&& sawsServer!=null){
138  0 sawsServer.sendLogRecord(new ExceptionSAWSRecord(th.toString()).toBytes());
139    //should close the log here since no PF object will be created, so this cannot be managed by the application
140  0 sawsServer.closeLog();
141   
142    }
143   
144  0 throw th;
145    }
146  0 accessPolicy = new issrg.pba.rbac.policies.AccessPolicy(parsedPolicy.getAccessRules());
147    //tokenParser.setAuthTokenParsingRules(parsedPolicy.getAuthTokenParsingRules());
148  0 allocationPolicy = new issrg.pba.rbac.policies.AllocationPolicy(
149    //tokenParser,
150    parsedPolicy.getAssignmentRules()
151    );
152   
153    }
154   
155   
156   
157    /**
158    * This method converts a file that contains plain XML policy into a
159    * in-memory string.
160    * @param fileName The file path name of the file that is supposed to be loaded
161    * into the in-memory string. The file is supposed to be a plain text file that
162    * in XML format containing the policy.
163    * @return A string that contains the text in the specified file.
164    */
 
165  10 toggle private static String fileIntoString(String fileName) throws IOException{
166  10 char myString[]=null;
167  10 try {
168  10 File sourceFile = new File(fileName);
169  10 long lengthSF = sourceFile.length();
170  10 myString = new char[(int)lengthSF];
171  10 FileReader f = new FileReader(sourceFile);
172  10 int i = 0;
173  20 while (i < lengthSF) {
174  10 i = i + f.read(myString, i, (int)lengthSF - i);
175    }
176    }
177    catch (IOException e) {
178   
179  0 throw e;
180    }
181  10 return new String(myString);
182    }
183   
184   
185    }