1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.pages;
20
21 import java.util.List;
22 import java.util.Objects;
23 import java.util.stream.Collectors;
24 import org.apache.syncope.client.console.BookmarkablePageLinkBuilder;
25 import org.apache.syncope.client.console.events.EventCategoryPanel;
26 import org.apache.syncope.client.console.events.SelectedEventsPanel;
27 import org.apache.syncope.client.console.rest.AuditRestClient;
28 import org.apache.syncope.common.lib.audit.EventCategory;
29 import org.apache.syncope.common.lib.types.AuditLoggerName;
30 import org.apache.syncope.common.lib.types.IdRepoEntitlement;
31 import org.apache.wicket.event.IEvent;
32 import org.apache.wicket.markup.html.WebMarkupContainer;
33 import org.apache.wicket.markup.html.form.Form;
34 import org.apache.wicket.model.IModel;
35 import org.apache.wicket.model.LoadableDetachableModel;
36 import org.apache.wicket.model.util.ListModel;
37 import org.apache.wicket.request.mapper.parameter.PageParameters;
38 import org.apache.wicket.spring.injection.annot.SpringBean;
39
40 public class Audit extends BasePage {
41
42 private static final long serialVersionUID = -1100228004207271271L;
43
44 @SpringBean
45 protected AuditRestClient auditRestClient;
46
47 protected final IModel<List<EventCategory>> eventCategories = new LoadableDetachableModel<List<EventCategory>>() {
48
49 private static final long serialVersionUID = 4659376149825914247L;
50
51 @Override
52 protected List<EventCategory> load() {
53 return auditRestClient.listEvents();
54 }
55 };
56
57 public Audit(final PageParameters parameters) {
58 super(parameters);
59
60 body.add(BookmarkablePageLinkBuilder.build("dashboard", "dashboardBr", Dashboard.class));
61
62 List<String> events = auditRestClient.list().stream().
63 filter(audit -> eventCategories.getObject().stream().
64 anyMatch(c -> audit.getType() == c.getType()
65 && Objects.equals(audit.getCategory(), c.getCategory())
66 && Objects.equals(audit.getSubcategory(), c.getSubcategory()))).
67 map(audit -> AuditLoggerName.buildEvent(
68 audit.getType(),
69 audit.getCategory(),
70 audit.getSubcategory(),
71 audit.getEvent(),
72 audit.getResult())).
73 sorted().
74 collect(Collectors.toList());
75
76 WebMarkupContainer content = new WebMarkupContainer("content");
77 content.setOutputMarkupId(true);
78
79 Form<?> form = new Form<>("auditForm");
80 content.add(form);
81
82 form.add(new EventCategoryPanel(
83 "auditPanel",
84 eventCategories.getObject(),
85 new ListModel<>(events)) {
86
87 private static final long serialVersionUID = 6113164334533550277L;
88
89 @Override
90 protected List<String> getListAuthRoles() {
91 return List.of(IdRepoEntitlement.AUDIT_LIST);
92 }
93
94 @Override
95 protected List<String> getChangeAuthRoles() {
96 return List.of(IdRepoEntitlement.AUDIT_SET);
97 }
98
99 @Override
100 public void onEventAction(final IEvent<?> event) {
101 if (event.getPayload() instanceof SelectedEventsPanel.EventSelectionChanged) {
102 SelectedEventsPanel.EventSelectionChanged eventSelectionChanged =
103 (SelectedEventsPanel.EventSelectionChanged) event.getPayload();
104
105 eventSelectionChanged.getToBeRemoved().forEach(auditRestClient::delete);
106
107 eventSelectionChanged.getToBeAdded().forEach(auditRestClient::enable);
108 }
109 }
110 });
111
112 body.add(content);
113 }
114 }