1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.security.authorization; |
21 |
|
|
22 |
|
import java.util.concurrent.Callable; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Provider; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.context.Execution; |
30 |
|
import org.xwiki.context.ExecutionContext; |
31 |
|
import org.xwiki.model.reference.DocumentReference; |
32 |
|
import org.xwiki.security.authorization.AuthorExecutor; |
33 |
|
|
34 |
|
import com.xpn.xwiki.XWikiConstant; |
35 |
|
import com.xpn.xwiki.XWikiContext; |
36 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
37 |
|
|
38 |
|
|
39 |
|
@link |
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
44 |
|
@Component |
45 |
|
@Singleton |
46 |
|
|
47 |
|
|
|
|
| 95.5% |
Uncovered Elements: 2 (44) |
Complexity: 11 |
Complexity Density: 0.38 |
|
48 |
|
public class DefaultAuthorExecutor implements AuthorExecutor |
49 |
|
{ |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@version |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
55 |
|
private final class DefaultAuthorExecutorContext implements AutoCloseable |
56 |
|
{ |
57 |
|
private XWikiDocument currentSecureDocument; |
58 |
|
|
59 |
|
private Object xwikiContextDropPermissionHack; |
60 |
|
|
61 |
|
private Object documentDropPermissionHack; |
62 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
63 |
82147 |
private DefaultAuthorExecutorContext()... |
64 |
|
{ |
65 |
|
|
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
82013 |
@Override... |
69 |
|
public void close() throws Exception |
70 |
|
{ |
71 |
82012 |
after(this); |
72 |
|
} |
73 |
|
} |
74 |
|
|
75 |
|
@Inject |
76 |
|
private Provider<XWikiContext> xcontextProvider; |
77 |
|
|
78 |
|
@Inject |
79 |
|
private Execution execution; |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 3 |
Complexity Density: 1 |
|
81 |
82008 |
@Override... |
82 |
|
public <V> V call(Callable<V> callable, DocumentReference authorReference) throws Exception |
83 |
|
{ |
84 |
81994 |
try (AutoCloseable context = before(authorReference)) { |
85 |
82006 |
return callable.call(); |
86 |
|
} |
87 |
|
} |
88 |
|
|
|
|
| 95.7% |
Uncovered Elements: 1 (23) |
Complexity: 4 |
Complexity Density: 0.24 |
|
89 |
82130 |
@Override... |
90 |
|
public AutoCloseable before(DocumentReference authorReference) |
91 |
|
{ |
92 |
82138 |
DefaultAuthorExecutorContext suContext; |
93 |
|
|
94 |
82141 |
XWikiContext xwikiContext = this.xcontextProvider.get(); |
95 |
|
|
96 |
82166 |
if (xwikiContext != null) { |
97 |
82155 |
suContext = new DefaultAuthorExecutorContext(); |
98 |
|
|
99 |
|
|
100 |
82145 |
suContext.currentSecureDocument = (XWikiDocument) xwikiContext.get(XWikiDocument.CKEY_SDOC); |
101 |
82156 |
XWikiDocument secureDocument = new XWikiDocument(new DocumentReference( |
102 |
82154 |
authorReference != null ? authorReference.getWikiReference().getName() : "xwiki", "SUSpace", "SUPage")); |
103 |
82162 |
secureDocument.setContentAuthorReference(authorReference); |
104 |
82151 |
secureDocument.setAuthorReference(authorReference); |
105 |
82151 |
secureDocument.setCreatorReference(authorReference); |
106 |
82148 |
xwikiContext.put(XWikiDocument.CKEY_SDOC, secureDocument); |
107 |
|
|
108 |
|
|
109 |
82164 |
suContext.xwikiContextDropPermissionHack = xwikiContext.remove(XWikiConstant.DROPPED_PERMISSIONS); |
110 |
|
|
111 |
|
|
112 |
82148 |
ExecutionContext econtext = this.execution.getContext(); |
113 |
82166 |
if (econtext != null) { |
114 |
82156 |
suContext.documentDropPermissionHack = econtext.getProperty(XWikiConstant.DROPPED_PERMISSIONS); |
115 |
82154 |
econtext.removeProperty(XWikiConstant.DROPPED_PERMISSIONS); |
116 |
|
} |
117 |
|
} else { |
118 |
2 |
suContext = null; |
119 |
|
} |
120 |
|
|
121 |
82152 |
return suContext; |
122 |
|
} |
123 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
124 |
82159 |
@Override... |
125 |
|
public void after(AutoCloseable context) |
126 |
|
{ |
127 |
82160 |
XWikiContext xwikiContext = this.xcontextProvider.get(); |
128 |
|
|
129 |
82168 |
if (xwikiContext != null) { |
130 |
82160 |
DefaultAuthorExecutorContext internalContext = (DefaultAuthorExecutorContext) context; |
131 |
|
|
132 |
|
|
133 |
82153 |
xwikiContext.put(XWikiDocument.CKEY_SDOC, internalContext.currentSecureDocument); |
134 |
|
|
135 |
|
|
136 |
82163 |
if (internalContext.xwikiContextDropPermissionHack != null) { |
137 |
767 |
xwikiContext.put(XWikiConstant.DROPPED_PERMISSIONS, internalContext.xwikiContextDropPermissionHack); |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
82159 |
if (internalContext.documentDropPermissionHack != null) { |
142 |
1 |
ExecutionContext econtext = this.execution.getContext(); |
143 |
1 |
econtext.setProperty(XWikiConstant.DROPPED_PERMISSIONS, internalContext.documentDropPermissionHack); |
144 |
|
} |
145 |
|
} |
146 |
|
} |
147 |
|
} |