Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
22   136   7   4.4
10   44   0.5   5
5     2.2  
1    
 
 
  MMEPUnit       Line # 55 22 7 70.3% 0.7027027
 
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.policies;
46   
47   
48    /**
49    * This class represents a MMEP unit -- it includes a forbiddenCardinality and a privilege set
50    * which comprises several mutually exclusive privileges with the forbiddenCardinality.
51    *
52    * @author W.Xu
53    * @version 0.1
54    */
 
55    public class MMEPUnit {
56   
57    private int forbiddenCardinality;
58    private int matchCount = 0;
59    java.util.Vector mmep; // this is a vector of class UserAction
60    java.util.Vector mmepBackup;
61   
62    /**
63    * This constructor creates the MMEPUnit object.
64    *
65    * @params forbiddenCardinality is the forbidden cardinality of this MMEP unit.
66    * @params mmep is a vector of MMEP i.e. mutually exclusive privileges.
67    *
68    */
 
69  36 toggle public MMEPUnit(int forbiddenCardinality, java.util.Vector mmep) {
70  36 this.forbiddenCardinality = forbiddenCardinality;
71  36 this.mmep = mmep;
72    }
73   
74    /**
75    * This method returns the current match count of MMEP,
76    * i.e. until now, how many MMEP have been matched by the user actions this MMEP Unit.
77    */
 
78  38 toggle public int getMatchCount(){
79  38 return matchCount;
80    }
81   
82    /**
83    * This method starts a new matching between user actions and this MMEP unit.
84    */
 
85  38 toggle public void startMatch(){
86  38 mmepBackup = (java.util.Vector) mmep.clone();
87  38 matchCount = 0;
88    }
89   
90    /**
91    * This method compare mmep with the input user action and target,
92    * to determine if this action and target pair match any mmep privileges. Once matched, matchCount is increased by 1,
93    * and if matchCount reaches forbiddenCardinality, then this MMEP rule is broken by the user, true will be returned;
94    * otherwise, false will be returned.
95    *
96    * return true if this user action and target matches any one of the MMEP privilege and the forbeddenCardinality
97    * is reached; otherwise return false.
98    */
 
99  49 toggle public boolean MMEPMatches(String action, String target) {
100  49 if (mmepBackup == null) {
101  0 return false;
102    }
103   
104  112 for (int i=mmepBackup.size()-1; i>=0 ; --i ) {
105  97 UserAction ua = (UserAction) mmepBackup.get(i);
106  97 if ( (ua.getAction()).compareTo(action) == 0 && ua.getTarget().compareTo(target) ==0 ) { // they are equal
107  34 mmepBackup.remove(i);
108  34 matchCount++;
109  34 if (matchCount >= forbiddenCardinality) {
110    // System.out.println("rule broken " );
111  8 return true;
112    }
113  26 break;
114    }
115    }
116   
117  41 return false;
118    }
119   
120    /**
121    * This method is to output all the MMEP action information as a String. This is for testing purposes.
122    */
 
123  0 toggle public String toString(){
124    // testing code here
125  0 int size = mmep.size();
126  0 StringBuffer result = new StringBuffer();
127  0 for (int i = 0; i< size ; i++ ) {
128  0 UserAction ua = (UserAction) mmep.get(i);
129  0 result.append ( ua.toString() );
130    }
131   
132  0 return result.toString();
133    }
134   
135    }
136