Skip to content

Commit

Permalink
[SYNCOPE-1791] Improving Audit conf management
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Dec 12, 2023
1 parent 920f51d commit 6e9d930
Show file tree
Hide file tree
Showing 19 changed files with 599 additions and 488 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public abstract class EventSelectionPanel extends Panel {

private final Set<String> selected = new HashSet<>();

public EventSelectionPanel(final String id, final EventCategory eventCategoryTO, final IModel<List<String>> model) {
public EventSelectionPanel(final String id, final EventCategory eventCategory, final IModel<List<String>> model) {
super(id);
setOutputMarkupId(true);

List<String> events = getEvents(eventCategoryTO);
List<String> events = getEvents(eventCategory);

// needed to avoid model reset: model have to be managed into SelectedEventsPanel
selected.addAll(model.getObject());
Expand All @@ -64,21 +64,21 @@ public EventSelectionPanel(final String id, final EventCategory eventCategoryTO,

@Override
protected void onUpdate(final AjaxRequestTarget target) {
Set<String> toBeRemoved = new HashSet<>();
Set<String> toBeAdded = new HashSet<>();

getEvents(eventCategoryTO).forEach(event -> {
String eventString = AuditLoggerName.buildEvent(
eventCategoryTO.getType(),
eventCategoryTO.getCategory(),
eventCategoryTO.getSubcategory(),
Set<AuditLoggerName> toBeRemoved = new HashSet<>();
Set<AuditLoggerName> toBeAdded = new HashSet<>();

getEvents(eventCategory).forEach(event -> {
AuditLoggerName auditLoggerName = new AuditLoggerName(
eventCategory.getType(),
eventCategory.getCategory(),
eventCategory.getSubcategory(),
event,
AuditElements.Result.SUCCESS);

if (successGroup.getModelObject().contains(eventString)) {
toBeAdded.add(eventString);
if (successGroup.getModelObject().contains(auditLoggerName.toString())) {
toBeAdded.add(auditLoggerName);
} else {
toBeRemoved.add(eventString);
toBeRemoved.add(auditLoggerName);
}
});

Expand Down Expand Up @@ -113,13 +113,13 @@ protected void populateItem(final ListItem<String> item) {
@Override
protected void populateItem(final ListItem<String> item) {
item.add(new Check<>("successCheck",
new Model<>(AuditLoggerName.buildEvent(
eventCategoryTO.getType(),
eventCategoryTO.getCategory(),
eventCategoryTO.getSubcategory(),
item.getModelObject(),
AuditElements.Result.SUCCESS)),
successGroup));
new Model<>(AuditLoggerName.buildEvent(
eventCategory.getType(),
eventCategory.getCategory(),
eventCategory.getSubcategory(),
item.getModelObject(),
AuditElements.Result.SUCCESS)),
successGroup));
}
};
successGroup.add(successView);
Expand All @@ -131,21 +131,21 @@ protected void populateItem(final ListItem<String> item) {

@Override
protected void onUpdate(final AjaxRequestTarget target) {
Set<String> toBeRemoved = new HashSet<>();
Set<String> toBeAdded = new HashSet<>();

getEvents(eventCategoryTO).forEach(event -> {
String eventString = AuditLoggerName.buildEvent(
eventCategoryTO.getType(),
eventCategoryTO.getCategory(),
eventCategoryTO.getSubcategory(),
Set<AuditLoggerName> toBeRemoved = new HashSet<>();
Set<AuditLoggerName> toBeAdded = new HashSet<>();

getEvents(eventCategory).forEach(event -> {
AuditLoggerName auditLoggerName = new AuditLoggerName(
eventCategory.getType(),
eventCategory.getCategory(),
eventCategory.getSubcategory(),
event,
AuditElements.Result.FAILURE);

if (failureGroup.getModelObject().contains(eventString)) {
toBeAdded.add(eventString);
if (failureGroup.getModelObject().contains(auditLoggerName.toString())) {
toBeAdded.add(auditLoggerName);
} else {
toBeRemoved.add(eventString);
toBeRemoved.add(auditLoggerName);
}
});

Expand All @@ -169,13 +169,13 @@ protected void onUpdate(final AjaxRequestTarget target) {
@Override
protected void populateItem(final ListItem<String> item) {
item.add(new Check<>("failureCheck",
new Model<>(AuditLoggerName.buildEvent(
eventCategoryTO.getType(),
eventCategoryTO.getCategory(),
eventCategoryTO.getSubcategory(),
item.getModelObject(),
AuditElements.Result.FAILURE)),
failureGroup));
new Model<>(AuditLoggerName.buildEvent(
eventCategory.getType(),
eventCategory.getCategory(),
eventCategory.getSubcategory(),
item.getModelObject(),
AuditElements.Result.FAILURE)),
failureGroup));
}
};
failureGroup.add(failureView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
*/
package org.apache.syncope.client.console.events;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.apache.syncope.client.ui.commons.Constants;
import org.apache.syncope.common.lib.types.AuditLoggerName;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.event.Broadcast;
Expand Down Expand Up @@ -51,18 +53,18 @@ public SelectedEventsPanel(final String id, final IModel<List<String>> model) {
add(selectionContainer);

ListMultipleChoice<String> selectedEvents =
new ListMultipleChoice<>("selectedEvents", new ListModel<>(), model) {

private static final long serialVersionUID = 1226677544225737338L;

@Override
protected void onComponentTag(final ComponentTag tag) {
super.onComponentTag(tag);
tag.remove("size");
tag.remove("multiple");
tag.put("size", 5);
}
};
new ListMultipleChoice<>("selectedEvents", new ListModel<>(), model) {

private static final long serialVersionUID = 1226677544225737338L;

@Override
protected void onComponentTag(final ComponentTag tag) {
super.onComponentTag(tag);
tag.remove("size");
tag.remove("multiple");
tag.put("size", 5);
}
};
selectedEvents.setMaxRows(5);
selectedEvents.setChoiceRenderer(new IChoiceRenderer<>() {

Expand Down Expand Up @@ -103,12 +105,13 @@ public void onEvent(final IEvent<?> event) {
EventSelectionChanged eventSelectionChanged = (EventSelectionChanged) event.getPayload();

eventSelectionChanged.getToBeRemoved().
forEach(toBeRemoved -> model.getObject().remove(toBeRemoved));
forEach(toBeRemoved -> model.getObject().remove(toBeRemoved.toString()));

eventSelectionChanged.getToBeAdded().stream().
filter(toBeAdded -> !model.getObject().contains(toBeAdded)).
forEach(toBeAdded -> model.getObject().add(toBeAdded));
filter(toBeAdded -> !model.getObject().contains(toBeAdded.toString())).
forEach(toBeAdded -> model.getObject().add(toBeAdded.toString()));

Collections.sort(model.getObject());
eventSelectionChanged.getTarget().add(selectionContainer);
}
}
Expand Down Expand Up @@ -137,14 +140,15 @@ public static class EventSelectionChanged {

private final AjaxRequestTarget target;

private final Set<String> toBeRemoved;
private final Set<AuditLoggerName> toBeRemoved;

private final Set<String> toBeAdded;
private final Set<AuditLoggerName> toBeAdded;

public EventSelectionChanged(
final AjaxRequestTarget target,
final Set<String> toBeAdded,
final Set<String> toBeRemoved) {
final Set<AuditLoggerName> toBeAdded,
final Set<AuditLoggerName> toBeRemoved) {

this.target = target;
this.toBeAdded = toBeAdded;
this.toBeRemoved = toBeRemoved;
Expand All @@ -154,11 +158,11 @@ public AjaxRequestTarget getTarget() {
return target;
}

public Set<String> getToBeRemoved() {
public Set<AuditLoggerName> getToBeRemoved() {
return toBeRemoved;
}

public Set<String> getToBeAdded() {
public Set<AuditLoggerName> getToBeAdded() {
return toBeAdded;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.client.console.commons.DirectoryDataProvider;
import org.apache.syncope.client.console.commons.IdRepoConstants;
Expand All @@ -44,7 +45,9 @@
import org.apache.syncope.client.ui.commons.Constants;
import org.apache.syncope.client.ui.commons.wizards.AjaxWizard;
import org.apache.syncope.common.lib.SyncopeClientException;
import org.apache.syncope.common.lib.audit.EventCategory;
import org.apache.syncope.common.lib.to.NotificationTO;
import org.apache.syncope.common.lib.types.AuditElements;
import org.apache.syncope.common.lib.types.IdRepoEntitlement;
import org.apache.wicket.PageReference;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand All @@ -53,6 +56,7 @@
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
Expand All @@ -77,6 +81,18 @@ public class NotificationDirectoryPanel
@SpringBean
protected SchemaRestClient schemaRestClient;

protected final IModel<List<EventCategory>> eventCategories = new LoadableDetachableModel<List<EventCategory>>() {

private static final long serialVersionUID = 4659376149825914247L;

@Override
protected List<EventCategory> load() {
// cannot notify about WA events
return auditRestClient.listEvents().stream().
filter(c -> c.getType() != AuditElements.EventCategoryType.WA).collect(Collectors.toList());
}
};

protected final BaseModal<String> utilityModal = new BaseModal<>(Constants.OUTER);

public NotificationDirectoryPanel(
Expand All @@ -97,10 +113,10 @@ public NotificationDirectoryPanel(
addNewItemPanelBuilder(new NotificationWizardBuilder(
new NotificationTO(),
notificationRestClient,
auditRestClient,
anyTypeRestClient,
implementationRestClient,
schemaRestClient,
eventCategories,
pageRef), true);

initResultTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.syncope.client.console.panels.search.SearchClause;
import org.apache.syncope.client.console.panels.search.UserSearchPanel;
import org.apache.syncope.client.console.rest.AnyTypeRestClient;
import org.apache.syncope.client.console.rest.AuditRestClient;
import org.apache.syncope.client.console.rest.ImplementationRestClient;
import org.apache.syncope.client.console.rest.NotificationRestClient;
import org.apache.syncope.client.console.rest.SchemaRestClient;
Expand All @@ -45,6 +44,7 @@
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDropDownChoicePanel;
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
import org.apache.syncope.common.lib.SyncopeClientException;
import org.apache.syncope.common.lib.audit.EventCategory;
import org.apache.syncope.common.lib.to.AnyTypeTO;
import org.apache.syncope.common.lib.to.DerSchemaTO;
import org.apache.syncope.common.lib.to.ImplementationTO;
Expand Down Expand Up @@ -78,30 +78,30 @@ public class NotificationWizardBuilder extends BaseAjaxWizardBuilder<Notificatio

protected final NotificationRestClient notificationRestClient;

protected final AuditRestClient auditRestClient;

protected final AnyTypeRestClient anyTypeRestClient;

protected final ImplementationRestClient implementationRestClient;

protected final SchemaRestClient schemaRestClient;

protected final IModel<List<EventCategory>> eventCategories;

public NotificationWizardBuilder(
final NotificationTO notificationTO,
final NotificationRestClient notificationRestClient,
final AuditRestClient auditRestClient,
final AnyTypeRestClient anyTypeRestClient,
final ImplementationRestClient implementationRestClient,
final SchemaRestClient schemaRestClient,
final IModel<List<EventCategory>> eventCategories,
final PageReference pageRef) {

super(new NotificationWrapper(notificationTO), pageRef);

this.notificationRestClient = notificationRestClient;
this.auditRestClient = auditRestClient;
this.anyTypeRestClient = anyTypeRestClient;
this.implementationRestClient = implementationRestClient;
this.schemaRestClient = schemaRestClient;
this.eventCategories = eventCategories;
}

@Override
Expand Down Expand Up @@ -182,7 +182,7 @@ public Events(final NotificationWrapper modelObject) {

add(new EventCategoryPanel(
"eventSelection",
auditRestClient.listEvents(),
eventCategories.getObject(),
new PropertyModel<>(modelObject.getInnerObject(), "events")) {

private static final long serialVersionUID = 6429053774964787735L;
Expand Down
Loading

0 comments on commit 6e9d930

Please sign in to comment.