1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.security.authorization.internal; |
21 |
|
|
22 |
|
import java.util.Collection; |
23 |
|
import java.util.Set; |
24 |
|
|
25 |
|
import javax.inject.Singleton; |
26 |
|
|
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.security.GroupSecurityReference; |
29 |
|
import org.xwiki.security.UserSecurityReference; |
30 |
|
import org.xwiki.security.authorization.Right; |
31 |
|
import org.xwiki.security.authorization.RightSet; |
32 |
|
import org.xwiki.security.authorization.RuleState; |
33 |
|
import org.xwiki.security.authorization.SecurityRule; |
34 |
|
import org.xwiki.security.authorization.SecurityRuleEntry; |
35 |
|
|
36 |
|
import static org.xwiki.security.authorization.RuleState.ALLOW; |
37 |
|
import static org.xwiki.security.authorization.RuleState.UNDETERMINED; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
46 |
|
@Component |
47 |
|
@Singleton |
|
|
| 97.4% |
Uncovered Elements: 2 (78) |
Complexity: 19 |
Complexity Density: 0.43 |
|
48 |
|
public class DefaultAuthorizationSettler extends AbstractAuthorizationSettler |
49 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 5 |
Complexity Density: 0.31 |
|
50 |
6370 |
@Override... |
51 |
|
protected XWikiSecurityAccess settle(UserSecurityReference user, Collection<GroupSecurityReference> groups, |
52 |
|
SecurityRuleEntry entry, Policies policies) |
53 |
|
{ |
54 |
6371 |
Set<Right> enabledRights = Right.getEnabledRights(entry.getReference().getSecurityType()); |
55 |
6370 |
Set<Right> fromUser = new RightSet(); |
56 |
6371 |
Set<Right> allowed = new RightSet(); |
57 |
|
|
58 |
6371 |
XWikiSecurityAccess access = new XWikiSecurityAccess(); |
59 |
|
|
60 |
|
|
61 |
6370 |
for (Right right : enabledRights) { |
62 |
51100 |
for (SecurityRule rule : entry.getRules()) { |
63 |
74117 |
if (rule.match(right)) { |
64 |
7646 |
if (rule.getState() == ALLOW) { |
65 |
5638 |
allowed.add(right); |
66 |
|
} |
67 |
7646 |
resolveLevel(right, user, groups, rule, access, policies, fromUser); |
68 |
7646 |
if (access.get(right) == ALLOW) { |
69 |
1385 |
implyRights(right, access, enabledRights, policies, fromUser); |
70 |
|
} |
71 |
|
} |
72 |
|
} |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
6371 |
for (Right right : allowed) { |
77 |
5268 |
if (access.get(right) == UNDETERMINED) { |
78 |
4028 |
access.deny(right); |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
6371 |
return access; |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
@param |
89 |
|
@param |
90 |
|
@param |
91 |
|
@param |
92 |
|
@param |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
94 |
1385 |
private void implyRights(Right right, XWikiSecurityAccess access, Set<Right> enabledRights, Policies policies,... |
95 |
|
Set<Right> fromUser) |
96 |
|
{ |
97 |
1385 |
Set<Right> impliedRights = right.getImpliedRights(); |
98 |
1385 |
if (impliedRights != null) { |
99 |
363 |
for (Right enabledRight : enabledRights) { |
100 |
2767 |
if (impliedRights.contains(enabledRight)) { |
101 |
|
|
102 |
977 |
policies.set(enabledRight, right); |
103 |
977 |
if (fromUser.contains(enabledRight) == fromUser.contains(right)) { |
104 |
|
|
105 |
693 |
resolveConflict(ALLOW, enabledRight, access, policies); |
106 |
284 |
} else if (fromUser.contains(right)) { |
107 |
|
|
108 |
258 |
access.set(enabledRight, ALLOW); |
109 |
258 |
fromUser.add(enabledRight); |
110 |
|
} |
111 |
|
} |
112 |
|
} |
113 |
|
} |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
@link |
118 |
|
@link |
119 |
|
|
120 |
|
@param |
121 |
|
@param |
122 |
|
@param |
123 |
|
@param |
124 |
|
@param |
125 |
|
@param |
126 |
|
@param |
127 |
|
|
|
|
| 91.3% |
Uncovered Elements: 2 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
|
128 |
7646 |
private void resolveLevel(Right right, UserSecurityReference user, Collection<GroupSecurityReference> groups,... |
129 |
|
SecurityRule rule, XWikiSecurityAccess access, Policies policies, Set<Right> fromUser) |
130 |
|
{ |
131 |
7647 |
RuleState state = rule.getState(); |
132 |
|
|
133 |
7645 |
if (state == UNDETERMINED) { |
134 |
0 |
return; |
135 |
|
} |
136 |
|
|
137 |
7647 |
if (rule.match(user)) { |
138 |
2390 |
if (!fromUser.contains(right)) { |
139 |
|
|
140 |
2341 |
access.set(right, state); |
141 |
2341 |
fromUser.add(right); |
142 |
|
} else { |
143 |
|
|
144 |
49 |
resolveConflict(state, right, access, policies); |
145 |
|
} |
146 |
5257 |
} else if (!fromUser.contains(right)) { |
147 |
4730 |
for (GroupSecurityReference group : groups) { |
148 |
2634 |
if (rule.match(group)) { |
149 |
|
|
150 |
311 |
resolveConflict(state, right, access, policies); |
151 |
311 |
break; |
152 |
|
} |
153 |
|
} |
154 |
|
} |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
@param |
161 |
|
@param |
162 |
|
@param |
163 |
|
@param |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
165 |
1053 |
private void resolveConflict(RuleState state, Right right, XWikiSecurityAccess access, Policies policies)... |
166 |
|
{ |
167 |
1053 |
if (access.get(right) == UNDETERMINED) { |
168 |
256 |
access.set(right, state); |
169 |
256 |
return; |
170 |
|
} |
171 |
797 |
if (access.get(right) != state) { |
172 |
197 |
access.set(right, policies.getTieResolutionPolicy(right)); |
173 |
|
} |
174 |
|
} |
175 |
|
} |