1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.security.internal; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.inject.Provider; |
25 |
|
import javax.inject.Singleton; |
26 |
|
|
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
29 |
|
import org.xwiki.model.reference.WikiReference; |
30 |
|
import org.xwiki.security.authorization.Right; |
31 |
|
|
32 |
|
import com.xpn.xwiki.XWikiContext; |
33 |
|
|
34 |
|
|
35 |
|
@link |
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
40 |
|
@Component |
41 |
|
@Singleton |
|
|
| 74.4% |
Uncovered Elements: 10 (39) |
Complexity: 12 |
Complexity Density: 0.52 |
|
42 |
|
public class DefaultXWikiBridge implements XWikiBridge |
43 |
|
{ |
44 |
|
|
45 |
|
@Inject |
46 |
|
@Named("user") |
47 |
|
private DocumentReferenceResolver<String> resolver; |
48 |
|
|
49 |
|
@Inject |
50 |
|
private Provider<XWikiContext> xcontextProvider; |
51 |
|
|
52 |
|
|
53 |
|
private WikiReference mainWikiReference; |
54 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
55 |
80 |
@Override... |
56 |
|
public WikiReference getMainWikiReference() |
57 |
|
{ |
58 |
80 |
if (mainWikiReference == null) { |
59 |
80 |
mainWikiReference = new WikiReference(xcontextProvider.get().getMainXWiki()); |
60 |
|
} |
61 |
80 |
return mainWikiReference; |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
16324 |
@Override... |
65 |
|
public boolean isWikiReadOnly() |
66 |
|
{ |
67 |
16324 |
return xcontextProvider.get().getWiki().isReadOnly(); |
68 |
|
} |
69 |
|
|
|
|
| 73.3% |
Uncovered Elements: 4 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
70 |
6448 |
@Override... |
71 |
|
public boolean needsAuthentication(Right right) |
72 |
|
{ |
73 |
6448 |
XWikiContext context = xcontextProvider.get(); |
74 |
6448 |
String prefName = "authenticate_" + right.getName(); |
75 |
|
|
76 |
6448 |
String value = context.getWiki().getXWikiPreference(prefName, "", context); |
77 |
6448 |
Boolean result = checkNeedsAuthValue(value); |
78 |
6448 |
if (result != null) { |
79 |
0 |
return result; |
80 |
|
} |
81 |
|
|
82 |
6448 |
value = context.getWiki().getSpacePreference(prefName, "", context).toLowerCase(); |
83 |
6449 |
result = checkNeedsAuthValue(value); |
84 |
6449 |
if (result != null) { |
85 |
0 |
return result; |
86 |
|
} |
87 |
|
|
88 |
6449 |
return false; |
89 |
|
} |
90 |
|
|
|
|
| 64.3% |
Uncovered Elements: 5 (14) |
Complexity: 6 |
Complexity Density: 0.75 |
|
91 |
12897 |
private Boolean checkNeedsAuthValue(String value)... |
92 |
|
{ |
93 |
12898 |
if (value != null && !value.equals("")) { |
94 |
50 |
if (value.toLowerCase().equals("yes")) { |
95 |
0 |
return true; |
96 |
|
} |
97 |
50 |
try { |
98 |
0 |
if (Integer.parseInt(value) > 0) { |
99 |
0 |
return true; |
100 |
|
} |
101 |
|
} catch (NumberFormatException e) { |
102 |
50 |
return null; |
103 |
|
} |
104 |
|
} |
105 |
12847 |
return null; |
106 |
|
} |
107 |
|
} |