DefaultValidityPeriodBehaviour | Line # 39 | 21 | 7 | 75% |
0.75
|
(1) | |||
Result | |||
0.6944444
|
issrg.test.ds.TestDS.testIssuing issrg.test.ds.TestDS.testIssuing | 1 PASS | |
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 | /** | |
35 | * This class implements the default behaviour of the ValidityPeriod when | |
36 | * computing intersections of two periods. | |
37 | */ | |
38 | ||
39 | public abstract class DefaultValidityPeriodBehaviour extends SubsetCredentials implements ValidityPeriod { | |
40 | ||
41 | 6667 | protected DefaultValidityPeriodBehaviour() { |
42 | } | |
43 | ||
44 | /** | |
45 | * This method checks if this ValidityPeriod contains the given Credentials. | |
46 | * It makes sense to pass only ValidityPeriod to this method, but it can | |
47 | * handle other Credentials, too. Bascially, it checks that the notBefore | |
48 | * of the given ValidityPeriod is not earlier than notBefore of this | |
49 | * ValidityPeriod, and that notAfter is not later than notAfter of this | |
50 | * ValidityPeriod. If the given Credentials is not a ValidityPeriod, the | |
51 | * contains method of the superclass is called. | |
52 | * | |
53 | * @param c - the Credentials object that must be contained in this | |
54 | * ValidityPeriod | |
55 | * @return true, if the given Credentials is a ValidityPeriod and is fully | |
56 | * contained in this ValidityPeriod; if it is not a ValidityPeriod, the | |
57 | * behaviour is defined by the superclass (calls the contains method of the | |
58 | * superclass); otherwise it is false. | |
59 | */ | |
60 | 1555 | public boolean contains(issrg.pba.Credentials c){ |
61 | //System.out.println("\n\n\t******** CONTAINS ******\n\t"+this+"\n\t"+c); //*********** | |
62 | ||
63 | 1555 | boolean b; |
64 | ||
65 | 1555 | if (c==null){ |
66 | 0 | b=false; |
67 | 1555 | }else if (!(c instanceof ValidityPeriod)){ |
68 | 0 | b=super.contains(c); |
69 | 1555 | }else if (c instanceof AdjustedValidityPeriod){ |
70 | 0 | b=contains(((AdjustedValidityPeriod)c).adjust(this)); |
71 | }else{ | |
72 | ||
73 | 1555 | ValidityPeriod vp = (ValidityPeriod)c; |
74 | 1555 | java.util.Date time = getNotBefore(); |
75 | 1555 | boolean before = time==null || (vp.getNotBefore()!=null && !time.after(vp.getNotBefore())); // this is before vp, if this starts at -oo, or if vp is the same or after time (vp doesn't start at -oo, in particular) |
76 | 1555 | time = getNotAfter(); |
77 | 1555 | boolean after = time==null || (vp.getNotAfter()!=null && !time.before(vp.getNotAfter())); // this is after vp, if this ends at +oo, or if vp is the same or before time (vp doesn't end at +oo, in particular) |
78 | ||
79 | 1555 | b = before && after; |
80 | } | |
81 | ||
82 | //System.out.println("\t"+b); //************** | |
83 | 1555 | return b; |
84 | } | |
85 | ||
86 | /** | |
87 | * This method computes an intersection of this ValidityPeriod with the | |
88 | * given Credentials. It makes sense only to intersect the ValidityPeriod with | |
89 | * other ValidityPeriods, but other Credentials are supported. Basically, it | |
90 | * ensures that the result of intersection provides a stricter ValidityPeriod | |
91 | * than this ValidityPeriod and the provided ValidityPeriod. | |
92 | * | |
93 | * @param c - the ValidityPeriod to intersect with; if it is not a | |
94 | * ValidityPeriod, the result is determined by the inherited intersection | |
95 | * method | |
96 | * @return the ValidityPeriod that is the intersection of this and the given | |
97 | * ValidityPeriod | |
98 | */ | |
99 | 4068 | public issrg.pba.Credentials intersection(issrg.pba.Credentials c){ |
100 | //System.out.println("\n\t*** INTERSECTION ***\n\t"+this+"\n\t"+c); //***** | |
101 | ||
102 | 4068 | if (c==null){ |
103 | //return null; | |
104 | 4068 | }else if (!(c instanceof ValidityPeriod)){ |
105 | 0 | c=super.intersection(c); |
106 | 4068 | }else if (c instanceof AdjustedValidityPeriod){ |
107 | 244 | c=((AdjustedValidityPeriod)c).intersection(this); // if this is AdjustedValidityPeriod, it will never get here |
108 | 3824 | }else c=new IntersectionValidityPeriod(this, (ValidityPeriod)c); |
109 | ||
110 | //System.out.println("\n\tresult: "+c); //***** | |
111 | 4068 | return c; |
112 | } | |
113 | } | |
114 |
|