1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.rest.setup; |
35 |
|
|
36 |
|
import info.magnolia.cms.security.SecuritySupport; |
37 |
|
import info.magnolia.cms.security.User; |
38 |
|
import info.magnolia.cms.security.UserManager; |
39 |
|
import info.magnolia.module.InstallContext; |
40 |
|
import info.magnolia.module.delta.AbstractTask; |
41 |
|
import info.magnolia.module.delta.TaskExecutionException; |
42 |
|
import info.magnolia.objectfactory.Components; |
43 |
|
|
44 |
|
|
45 |
|
@link |
46 |
|
|
|
|
| 78.6% |
Uncovered Elements: 3 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
47 |
|
class RemoveRoleFromUserTask extends AbstractTask { |
48 |
|
private final String username; |
49 |
|
private final String rolename; |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
51 |
4 |
RemoveRoleFromUserTask(String taskName, String username, String rolename) {... |
52 |
4 |
super(taskName, String.format("Remove role %s from user %s", rolename, username)); |
53 |
4 |
this.username = username; |
54 |
4 |
this.rolename = rolename; |
55 |
|
} |
56 |
|
|
|
|
| 66.7% |
Uncovered Elements: 3 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
57 |
3 |
@Override... |
58 |
|
public void execute(InstallContext ctx) throws TaskExecutionException { |
59 |
3 |
UserManager userManager = Components.getComponent(SecuritySupport.class).getUserManager(); |
60 |
3 |
User user = userManager.getUser(username); |
61 |
3 |
if (user == null) { |
62 |
0 |
ctx.warn(String.format("User \"%s\" not found, can't add the \"%s\" role.", username, rolename)); |
63 |
|
} else { |
64 |
|
|
65 |
|
|
66 |
3 |
try { |
67 |
3 |
userManager.removeRole(user, rolename); |
68 |
|
} catch (UnsupportedOperationException e) { |
69 |
0 |
ctx.warn(String.format("Can't remove role \"%s\" from user \"%s\" due to an unsupported operation exception. This is most likely the case if the users are managed externally.", rolename, username)); |
70 |
|
} |
71 |
|
} |
72 |
|
} |
73 |
|
} |
74 |
|
|