SubsetCredentials | Line # 44 | 17 | 7 | 76.5% |
0.7647059
|
(1) | |||
Result | |||
0.64705884
|
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 | import issrg.pba.Credentials; | |
35 | ||
36 | /** | |
37 | * This abstract class defines some basic behaviour, taking into account that | |
38 | * a SetOfSubsets class exists. | |
39 | * | |
40 | * @author A Otenko | |
41 | * @version 1.0 | |
42 | */ | |
43 | ||
44 | public abstract class SubsetCredentials implements Credentials { | |
45 | 23052 | protected SubsetCredentials() { |
46 | } | |
47 | ||
48 | /** | |
49 | * This method tells if the given set of credentials is contained within this | |
50 | * credentials object. If the credentials object is a SetOfSubsetsCredentials | |
51 | * it deploys its | |
52 | * <code>partOf</code> method. All of the subclasses should call this method, | |
53 | * if they do not handle a SetOfSubsetsCredentials. | |
54 | * | |
55 | * @param cred is the credential to compare | |
56 | * | |
57 | * @return true if the given credential is contained within this credential | |
58 | * | |
59 | * @see SetOfSubsetsCredentials | |
60 | */ | |
61 | 2 | public boolean contains(Credentials cred){ |
62 | 2 | if (cred instanceof SetOfSubsetsCredentials){ |
63 | 2 | return ((SetOfSubsetsCredentials)cred).partOf(this/*cred*/); //Tuan Anh: why Sassa used "cred" here? it always return true!! |
64 | } | |
65 | ||
66 | 0 | return false; |
67 | } | |
68 | ||
69 | /** | |
70 | * This method compares two credentials for equality. The result is equal to | |
71 | * <p><code>contains(cred) && cred.contains(this)</code>, | |
72 | * <p>if cred is | |
73 | * a credentials object. The result is always false if cred is not a | |
74 | * Credentials object. | |
75 | * | |
76 | * @param cred is the object to compare with | |
77 | * | |
78 | * @result true, if the objects are equal | |
79 | */ | |
80 | 6 | public boolean equals(Object cred){ |
81 | 6 | if (cred instanceof Credentials){ |
82 | 6 | Credentials c = (Credentials)cred; |
83 | 6 | return c.contains(this) && this.contains(c); |
84 | } | |
85 | ||
86 | 0 | return false; |
87 | } | |
88 | ||
89 | /** | |
90 | * This method implements the basic intersection rule: the intersection is | |
91 | * the biggest common part. In particular, if this object | |
92 | * contains | |
93 | * the other object, then the intersection is that object; if this object is | |
94 | * contained within the other object, then the intersection is this object. | |
95 | * Otherwise the intersection is null. | |
96 | * | |
97 | * @param cred is the credential to intersect with | |
98 | * | |
99 | * @return the Credential that is the intersection of the two | |
100 | */ | |
101 | 4939 | public Credentials intersection(Credentials cred){ |
102 | /* | |
103 | * | |
104 | * <p>TODO: do I change it to call some other protected method to determine the | |
105 | * actual intersection? | |
106 | */ | |
107 | 4939 | if (contains(cred)){ |
108 | 3481 | return cred; |
109 | } | |
110 | ||
111 | 1458 | if (cred.contains(this)){ |
112 | 496 | return this; |
113 | } | |
114 | ||
115 | 962 | return null; |
116 | } | |
117 | ||
118 | /** | |
119 | * This method implements the default behaviour for the union operation: the | |
120 | * union is the smallest set containing both objects. In particular, if | |
121 | * cred contains this object, then the result is cred; if this object | |
122 | * contains cred, then | |
123 | * the result is this. Otherwise the union is a SetOfSubsetsCredential, | |
124 | * containing both. | |
125 | * | |
126 | * @param cred is the credentials object to join with | |
127 | * | |
128 | * @return the Credentials object that is the union of the two | |
129 | */ | |
130 | 97 | public Credentials union(Credentials cred){ |
131 | 97 | if (contains(cred)){ |
132 | 0 | return this; |
133 | } | |
134 | ||
135 | 97 | if (cred.contains(this)){ |
136 | 0 | return cred; |
137 | } | |
138 | ||
139 | 97 | return new SetOfSubsetsCredentials(new Credentials []{this, cred}); |
140 | } | |
141 | ||
142 | /** | |
143 | * This method creates a copy of the credentials object. Requires | |
144 | * overriding in implementations of subclasses. | |
145 | */ | |
146 | public abstract Object clone(); | |
147 | } |
|