1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package com.xpn.xwiki.plugin.rightsmanager; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.slf4j.Logger; |
27 |
|
import org.slf4j.LoggerFactory; |
28 |
|
import org.xwiki.bridge.event.DocumentDeletedEvent; |
29 |
|
import org.xwiki.observation.EventListener; |
30 |
|
import org.xwiki.observation.event.Event; |
31 |
|
import org.xwiki.observation.remote.RemoteObservationManagerContext; |
32 |
|
|
33 |
|
import com.xpn.xwiki.XWikiContext; |
34 |
|
import com.xpn.xwiki.XWikiException; |
35 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
36 |
|
import com.xpn.xwiki.web.Utils; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
|
|
| 54.3% |
Uncovered Elements: 21 (46) |
Complexity: 14 |
Complexity Density: 0.47 |
|
44 |
|
public final class RightsManagerListener implements EventListener |
45 |
|
{ |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(RightsManagerListener.class); |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
private static final String NAME = "rightsmanager"; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
private static final List<Event> EVENTS = new ArrayList<Event>() |
60 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
3 |
{... |
62 |
3 |
add(new DocumentDeletedEvent()); |
63 |
|
} |
64 |
|
}; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
private static RightsManagerListener instance; |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
76 |
3 |
private RightsManagerListener()... |
77 |
|
{ |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
@return |
82 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
83 |
3 |
public static RightsManagerListener getInstance()... |
84 |
|
{ |
85 |
3 |
synchronized (RightsManagerListener.class) { |
86 |
3 |
if (instance == null) { |
87 |
3 |
instance = new RightsManagerListener(); |
88 |
|
} |
89 |
|
} |
90 |
|
|
91 |
3 |
return instance; |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
15 |
@Override... |
95 |
|
public String getName() |
96 |
|
{ |
97 |
15 |
return NAME; |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
3 |
@Override... |
101 |
|
public List<Event> getEvents() |
102 |
|
{ |
103 |
3 |
return EVENTS; |
104 |
|
} |
105 |
|
|
|
|
| 55% |
Uncovered Elements: 9 (20) |
Complexity: 6 |
Complexity Density: 0.43 |
|
106 |
31 |
@Override... |
107 |
|
public void onEvent(Event event, Object source, Object data) |
108 |
|
{ |
109 |
|
|
110 |
31 |
if (!Utils.getComponent(RemoteObservationManagerContext.class).isRemoteState()) { |
111 |
31 |
XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); |
112 |
31 |
XWikiContext context = (XWikiContext) data; |
113 |
|
|
114 |
31 |
String userOrGroupWiki = document.getDatabase(); |
115 |
31 |
String userOrGroupSpace = document.getSpace(); |
116 |
31 |
String userOrGroupName = document.getName(); |
117 |
|
|
118 |
31 |
if (document.getObject("XWiki.XWikiUsers") != null) { |
119 |
0 |
try { |
120 |
0 |
cleanDeletedUserOrGroup(userOrGroupWiki, userOrGroupSpace, userOrGroupName, true, context); |
121 |
|
} catch (XWikiException e) { |
122 |
0 |
LOGGER.warn("Error when cleaning for deleted user", e); |
123 |
|
} |
124 |
31 |
} else if (document.getObject("XWiki.XWikiGroups") != null) { |
125 |
0 |
try { |
126 |
0 |
cleanDeletedUserOrGroup(userOrGroupWiki, userOrGroupSpace, userOrGroupName, false, context); |
127 |
|
} catch (XWikiException e) { |
128 |
0 |
LOGGER.warn("Error when cleaning for deleted group", e); |
129 |
|
} |
130 |
|
} |
131 |
|
} |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
@param |
138 |
|
@param |
139 |
|
@param |
140 |
|
@param |
141 |
|
@param |
142 |
|
@throws |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
144 |
0 |
private void cleanDeletedUserOrGroupInLocalWiki(String userOrGroupWiki, String userOrGroupSpace,... |
145 |
|
String userOrGroupName, boolean user, XWikiContext context) throws XWikiException |
146 |
|
{ |
147 |
0 |
RightsManager.getInstance().removeUserOrGroupFromAllRights(userOrGroupWiki, userOrGroupSpace, userOrGroupName, |
148 |
|
user, context); |
149 |
0 |
context.getWiki().getGroupService(context).removeUserOrGroupFromAllGroups(userOrGroupWiki, userOrGroupSpace, |
150 |
|
userOrGroupName, context); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
@param |
157 |
|
@param |
158 |
|
@param |
159 |
|
@param |
160 |
|
@param |
161 |
|
@throws |
162 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
163 |
0 |
private void cleanDeletedUserOrGroup(String userOrGroupWiki, String userOrGroupSpace, String userOrGroupName,... |
164 |
|
boolean user, XWikiContext context) throws XWikiException |
165 |
|
{ |
166 |
0 |
List<String> wikiList = context.getWiki().getVirtualWikisDatabaseNames(context); |
167 |
|
|
168 |
0 |
String database = context.getWikiId(); |
169 |
0 |
try { |
170 |
0 |
for (String wikiName : wikiList) { |
171 |
0 |
context.setWikiId(wikiName); |
172 |
0 |
cleanDeletedUserOrGroupInLocalWiki(userOrGroupWiki, userOrGroupSpace, userOrGroupName, user, context); |
173 |
|
} |
174 |
|
} finally { |
175 |
0 |
context.setWikiId(database); |
176 |
|
} |
177 |
|
} |
178 |
|
} |