Skip to content

Commit 9e04a65

Browse files
committed
[SYNCOPE-1946] Adding audit history features to Realm page
1 parent 75ecf27 commit 9e04a65

File tree

12 files changed

+81
-16
lines changed

12 files changed

+81
-16
lines changed

client/idrepo/console/src/main/java/org/apache/syncope/client/console/audit/AuditHistoryDetails.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,20 @@ protected Model<String> toJSON(final AuditEventTO auditEvent, final Class<T> ref
330330
}
331331

332332
try {
333-
String content;
333+
String content = null;
334334
if (auditEvent.getBefore() == null) {
335335
JsonNode output = MAPPER.readTree(auditEvent.getOutput());
336336
if (output.has("entity")) {
337337
content = output.get("entity").toPrettyString();
338-
} else {
338+
} else if ((!output.has("content") && output.get("content").isArray())) {
339339
content = output.toPrettyString();
340340
}
341341
} else {
342342
content = auditEvent.getBefore();
343343
}
344+
if (content == null || "null".equals(content)) {
345+
return Model.of();
346+
}
344347

345348
T entity = MAPPER.reader().
346349
with(StreamReadFeature.STRICT_DUPLICATE_DETECTION).

client/idrepo/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@
1818
*/
1919
package org.apache.syncope.client.console.pages;
2020

21+
import com.fasterxml.jackson.databind.json.JsonMapper;
2122
import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
2223
import java.io.Serializable;
2324
import java.util.List;
2425
import org.apache.syncope.client.console.BookmarkablePageLinkBuilder;
2526
import org.apache.syncope.client.console.SyncopeConsoleSession;
27+
import org.apache.syncope.client.console.audit.AuditHistoryModal;
2628
import org.apache.syncope.client.console.panels.Realm;
2729
import org.apache.syncope.client.console.panels.RealmChoicePanel;
2830
import org.apache.syncope.client.console.panels.RealmChoicePanel.ChosenRealm;
2931
import org.apache.syncope.client.console.rest.AnyTypeRestClient;
32+
import org.apache.syncope.client.console.rest.AuditRestClient;
3033
import org.apache.syncope.client.console.rest.RealmRestClient;
3134
import org.apache.syncope.client.console.tasks.TemplatesTogglePanel;
3235
import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
@@ -40,6 +43,8 @@
4043
import org.apache.syncope.common.lib.to.ProvisioningResult;
4144
import org.apache.syncope.common.lib.to.RealmTO;
4245
import org.apache.syncope.common.lib.to.TemplatableTO;
46+
import org.apache.syncope.common.lib.types.IdRepoEntitlement;
47+
import org.apache.syncope.common.lib.types.OpEvent;
4348
import org.apache.wicket.PageReference;
4449
import org.apache.wicket.ajax.AjaxRequestTarget;
4550
import org.apache.wicket.event.Broadcast;
@@ -56,6 +61,8 @@ public class Realms extends BasePage {
5661

5762
private static final long serialVersionUID = -1100228004207271270L;
5863

64+
protected static final JsonMapper MAPPER = JsonMapper.builder().findAndAddModules().build();
65+
5966
public static final String SELECTED_INDEX = "selectedIndex";
6067

6168
public static final String INITIAL_REALM = "initialRealm";
@@ -66,6 +73,9 @@ public class Realms extends BasePage {
6673
@SpringBean
6774
protected AnyTypeRestClient anyTypeRestClient;
6875

76+
@SpringBean
77+
protected AuditRestClient auditRestClient;
78+
6979
protected final TemplatesTogglePanel templates;
7080

7181
protected final RealmChoicePanel realmChoicePanel;
@@ -119,7 +129,7 @@ protected void onConfigure() {
119129
setFooterVisible(false);
120130
}
121131
};
122-
templateModal.size(Modal.Size.Large);
132+
templateModal.size(Modal.Size.Extra_large);
123133
content.add(templateModal);
124134

125135
modal.setWindowClosedCallback(target -> {
@@ -191,12 +201,6 @@ protected Content(final RealmTO realmTO, final List<AnyTypeTO> anyTypes, final i
191201
super("body", realmTO, anyTypes, selectedIndex, Realms.this.getPageReference());
192202
}
193203

194-
@Override
195-
protected void onClickTemplate(final AjaxRequestTarget target) {
196-
templates.setTargetObject(realmTO);
197-
templates.toggle(target, true);
198-
}
199-
200204
@Override
201205
protected void setWindowClosedReloadCallback(final BaseModal<?> modal) {
202206
modal.setWindowClosedCallback(target -> {
@@ -214,6 +218,12 @@ protected void setWindowClosedReloadCallback(final BaseModal<?> modal) {
214218
});
215219
}
216220

221+
@Override
222+
protected void onClickTemplate(final AjaxRequestTarget target) {
223+
templates.setTargetObject(realmTO);
224+
templates.toggle(target, true);
225+
}
226+
217227
@Override
218228
protected void onClickCreate(final AjaxRequestTarget target) {
219229
this.wizardBuilder.setParent(realmChoicePanel.getCurrentRealm());
@@ -237,6 +247,38 @@ public String getEventDescription() {
237247
});
238248
}
239249

250+
@Override
251+
protected void onClickAudit(final AjaxRequestTarget target, final RealmTO realmTO) {
252+
target.add(templateModal.setContent(new AuditHistoryModal<>(
253+
OpEvent.CategoryType.LOGIC,
254+
"RealmLogic",
255+
realmTO,
256+
IdRepoEntitlement.REALM_UPDATE,
257+
auditRestClient) {
258+
259+
private static final long serialVersionUID = -5819724478921691835L;
260+
261+
@Override
262+
protected void restore(final String json, final AjaxRequestTarget target) {
263+
try {
264+
RealmTO updated = MAPPER.readValue(json, RealmTO.class);
265+
realmRestClient.update(updated);
266+
267+
SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
268+
target.add(realmChoicePanel.reloadRealmTree(target));
269+
} catch (Exception e) {
270+
LOG.error("While restoring realm {}", realmTO.getKey(), e);
271+
SyncopeConsoleSession.get().onException(e);
272+
}
273+
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
274+
}
275+
}));
276+
277+
templateModal.header(new Model<>(getString("realm.auditHistory.title", new Model<>(realmTO))));
278+
279+
templateModal.show(true);
280+
}
281+
240282
@Override
241283
protected void onClickDelete(final AjaxRequestTarget target, final RealmTO realmTO) {
242284
try {

client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/Realm.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ public void onClick(final AjaxRequestTarget target, final PropagationStatus stat
234234

235235
protected abstract void onClickEdit(AjaxRequestTarget target, RealmTO realmTO);
236236

237+
protected abstract void onClickAudit(AjaxRequestTarget target, RealmTO realmTO);
238+
237239
protected abstract void onClickDelete(AjaxRequestTarget target, RealmTO realmTO);
238240

239241
protected static class RemoteRealmPanel extends RemoteObjectPanel {
@@ -306,6 +308,18 @@ public void onClick(final AjaxRequestTarget target, final RealmTO ignore) {
306308
}, ActionLink.ActionType.TEMPLATE, IdRepoEntitlement.REALM_UPDATE).hideLabel();
307309
}
308310

311+
if (securityCheck(Set.of(IdRepoEntitlement.AUDIT_LIST))) {
312+
actionPanel.add(new ActionLink<>(realmTO) {
313+
314+
private static final long serialVersionUID = 2802988981431379827L;
315+
316+
@Override
317+
public void onClick(final AjaxRequestTarget target, final RealmTO ignore) {
318+
onClickAudit(target, realmTO);
319+
}
320+
}, ActionLink.ActionType.VIEW_AUDIT_HISTORY, IdRepoEntitlement.AUDIT_LIST).hideLabel();
321+
}
322+
309323
if (securityCheck(Set.of(IdRepoEntitlement.REALM_DELETE))) {
310324
actionPanel.add(new ActionLink<>(realmTO) {
311325

client/idrepo/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ realmLabel=Realm
2222
dynRealmLabel=Dynamic Realm
2323
realms=Realms
2424
dynrealms=Dynamic Realms
25+
realm.auditHistory.title=Realm ${fullPath} history

client/idrepo/console/src/main/resources/org/apache/syncope/client/console/pages/Realms_fr_CA.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
# under the License.
1717
any.realm.new=Nouveau domaine
1818
any.realm.edit=Modifier domaine ${fullPath}
19-
inner.template.edit=Modifier modèle ${gauche} pour '${right.fullPath}''.
19+
inner.template.edit=Modifier mod\u00e8le ${gauche} pour '${right.fullPath}''.
2020
afterObj=Lien d'objet
2121
realmLabel=Domaine
2222
dynRealmLabel=Domaine dynamique
2323
realms=Domaines
2424
dynrealms=Domaines dynamiques
25+
realm.auditHistory.title=Realm ${fullPath} histoire

client/idrepo/console/src/main/resources/org/apache/syncope/client/console/pages/Realms_it.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ realmLabel=Realm
2222
dynRealmLabel=Realm Dinamico
2323
realms=Realm
2424
dynrealms=Realm Dinamici
25+
realm.auditHistory.title=Realm ${fullPath} storico

client/idrepo/console/src/main/resources/org/apache/syncope/client/console/pages/Realms_ja.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ realmLabel=\u30ec\u30eb\u30e0
2222
dynRealmLabel=\u52d5\u7684\u30ec\u30eb\u30e0
2323
realms=\u30ec\u30eb\u30e0
2424
dynrealms=\u52d5\u7684\u30ec\u30eb\u30e0
25+
realm.auditHistory.title=Realm ${fullPath} history

client/idrepo/console/src/main/resources/org/apache/syncope/client/console/pages/Realms_pt_BR.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ realmLabel=Realm
2222
dynRealmLabel=Dynamic Realm
2323
realms=Realms
2424
dynrealms=Dynamic Realms
25+
realm.auditHistory.title=Realm ${fullPath} history

client/idrepo/console/src/main/resources/org/apache/syncope/client/console/pages/Realms_ru.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ realmLabel=Realm
2323
dynRealmLabel=Dynamic Realm
2424
realms=Realms
2525
dynrealms=Dynamic Realms
26+
realm.auditHistory.title=Realm ${fullPath} history

core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAuditEventDAO.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ protected int setParameter(final List<Object> parameters, final Object parameter
5151
protected AuditEventCriteriaBuilder entityKey(final String entityKey) {
5252
if (entityKey != null) {
5353
query.append(andIfNeeded()).
54-
append("(before_value LIKE '%key%").append(entityKey).append("%' OR ").
55-
append("inputs LIKE '%key%").append(entityKey).append("%' OR ").
56-
append("output LIKE '%key%").append(entityKey).append("%' OR ").
57-
append("throwable LIKE '%key%").append(entityKey).append("%')");
54+
append("(before_value LIKE '%\"key\":\"").append(entityKey).append("\"%' OR ").
55+
append("inputs LIKE '%\"key\":\"").append(entityKey).append("\"%' OR ").
56+
append("output LIKE '%\"key\":\"").append(entityKey).append("\"%' OR ").
57+
append("throwable LIKE '%\"key\":\"").append(entityKey).append("\"%')");
5858
}
5959
return this;
6060
}

0 commit comments

Comments
 (0)