Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
23   161   6   2.88
10   53   0.57   8
8     1.62  
1    
 
 
  ExpirableCredentials       Line # 49 23 6 82.9% 0.8292683
 
  (1)
 
1    /*
2    * Copyright (c) 2000-2005, University of Salford
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    * Neither the name of the University of Salford 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    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29    * POSSIBILITY OF SUCH DAMAGE.
30    */
31   
32    package issrg.pba.rbac;
33   
34    import issrg.pba.Credentials;
35    import issrg.pba.rbac.SubsetCredentials;
36    import java.util.Date;
37   
38    /**
39    * This class is intended to provide expiration service, so that any given
40    * Credentials are constrained in the time dimension. The objects can embed
41    * any Credentials, and ExpirableCredentials will perform expiration checks
42    * when intersecting the credentials.
43    *
44    * <p>Note that the methods call the inherited methods to ensure that the other
45    * types of Credentials are handled correctly, e.g. SetOfSubsetsCredentials
46    * are intersected correctly.
47    */
48   
 
49    public class ExpirableCredentials extends SubsetCredentials{
50   
51    protected Credentials expirable;
52    protected ValidityPeriod when;
53   
 
54  0 toggle protected ExpirableCredentials() {
55    }
56   
57    /**
58    * This constructor builds a credential with Validity Period. If the
59    * credential is used
60    * outside the specified period, it will be ignored.
61    *
62    * @param expirable - the Credentials with which the Validity Period is
63    * associated
64    * @param vp - the ValidityPeriod of the Credentials; should not be null
65    */
 
66  13466 toggle public ExpirableCredentials(Credentials expirable,
67    ValidityPeriod vp){
68  13466 this.expirable = expirable;
69  13466 when = vp;//==null?new NowValidityPeriod():vp;
70    }
71   
72    /**
73    * This method checks if this ExpirableCredentials contains the other
74    * Credentials. If it is an ExpirableCredentials, then their embedded
75    * Credentials are tested, and the ValidityPeriods are tested separately;
76    * otherwise the inherited behaviour of the method determines the result.
77    *
78    * @param c - the Credentials that must be contained in this one
79    * @return true, if the embedded Credentials and the ValidityPeriod of this
80    * ExpirableCredentials contain the corresponding components of the given
81    * Credentials, if it is ExpirableCredentials; otherwise the inherited
82    * contains method is called to test if this ExpirableCredentials contains
83    * the given Credentials
84    */
 
85  5519 toggle public boolean contains(Credentials c){
86    //System.out.println("\n\t*** CONTAINS ***\n\t"+this+"\n\t"+c); //*******
87   
88  5519 boolean b;
89  5519 if (c instanceof ExpirableCredentials){
90  5517 if (when==null){
91  196 b=false;
92    }else{
93   
94  5321 ExpirableCredentials ec = (ExpirableCredentials)c;
95  5321 b=expirable.contains(ec.expirable) && when.contains(ec.when);
96    }
97  2 }else b=super.contains(c);
98   
99    //System.out.println("\n\tresult: "+b); //*******
100  5519 return b;
101    }
102   
103    /**
104    * This method builds an intersection of this ExpirableCredentials with the
105    * given Credentials. If it is an ExpirableCredentials, then the result is
106    * the ExpirableCredentials, consisting of the intersection of the embedded
107    * Credentials and their ValidityPeriods. Otherwise the inherited intersection
108    * method determines the result.
109    *
110    * @param c - the Credentials to intersect with
111    * @return Credentials that is the result of intersecting the embedded
112    * Credentials and the ValidityPeriods if the given Credentials is an
113    * ExpirableCredentials; otherwise, the inherited intersection method
114    * determines the result.
115    */
 
116  5030 toggle public Credentials intersection(Credentials c){
117    //System.out.println("\n\t*** INTERSECTION ***\n\t"+this+"\n\t"+c); //*******
118   
119  5030 Credentials c1;
120  5030 if (!(c instanceof ExpirableCredentials)){
121  0 c1=super.intersection(c);
122  5030 }else if (when==null){
123  0 c1=null;
124    }else{
125   
126  5030 ExpirableCredentials e=(ExpirableCredentials)c;
127   
128  0 if ((c1=expirable.intersection(e.expirable))!=null){
129  4068 c1=new ExpirableCredentials(c1, (ValidityPeriod)when.intersection(e.when));
130    }
131    }
132   
133    //System.out.println("\n\tresult: "+c1); //*******
134  5030 return c1;
135    }
136   
137    /**
138    * This method returns the ValidityPeriod associated with the embedded
139    * Credentials.
140    */
 
141  52 toggle public ValidityPeriod getValidityPeriod() {
142  52 return when;
143    }
144   
145    /**
146    * This method returns the Credentials embedded inside this object and
147    * associated with the ValidityPeriod.
148    */
 
149  136 toggle public Credentials getExpirable() {
150  136 return expirable;
151    }
152   
 
153  6543 toggle public Object clone(){
154  6543 return new ExpirableCredentials(this.expirable, this.when);
155    }
156   
 
157  7425 toggle public String toString(){
158  7425 return "<"+expirable+" "+when+">";
159    }
160    }
161