Skip to content

[SYNCOPE-1978] Search audit events by who (username)#1438

Open
ozimakov wants to merge 1 commit into
apache:masterfrom
ozimakov:SYNCOPE-1978
Open

[SYNCOPE-1978] Search audit events by who (username)#1438
ozimakov wants to merge 1 commit into
apache:masterfrom
ozimakov:SYNCOPE-1978

Conversation

@ozimakov

Copy link
Copy Markdown
Contributor

SYNCOPE-1978

What

Restores the ability to search audit events by the username that performed them. A new who query parameter on AuditQuery matches the AuditEvent.who column and supports:

  • exact match — ?who=jsmith
  • multiple values, OR-ed — ?who=jsmith&who=admin
  • * wildcards — ?who=svc-*

It composes (AND) with the existing audit search filters (entityKey, type, category, op, outcome, before/after).

Why

Syncope 3.0 allowed searching audit entries by username; 4.0 removed it. The capability is useful to retrieve all actions performed by a given user — in particular when that user has been deleted and the entity key is no longer available.

Implementation

The filter is threaded through AuditServiceImplAuditLogic → the AuditEventDAO interface and all of its implementations: JPA, Neo4j, Elasticsearch and OpenSearch. All values are bound as query parameters; wildcard handling escapes store metacharacters so that only * acts as a wildcard:

  • JPA: exact uses =, wildcard uses LIKE ? ESCAPE '#' (a backslash escape char is mishandled by MySQL/MariaDB and Oracle has no default escape, so # is used for portability);
  • Neo4j: exact uses =, wildcard uses =~ with regex metacharacters escaped;
  • Elasticsearch / OpenSearch: a wildcard query per value, OR-ed via bool/should, escaping \ and ?.

Tests

New integration tests in AuditITCase cover exact match, multiple values (OR) and wildcard, composed with the other filters. Manually verified against the standalone (H2) distribution.

Restore the ability to search audit events by the username that performed
them. A new "who" query parameter on AuditQuery matches the AuditEvent.who
column and supports exact match, multiple values (OR) and "*" wildcards,
composing with the existing audit search filters.

The filter is threaded through AuditServiceImpl, AuditLogic and the
AuditEventDAO interface and all of its implementations (JPA, Neo4j,
Elasticsearch, OpenSearch). Values are bound as query parameters; wildcard
handling escapes LIKE/regex metacharacters so that only "*" acts as a
wildcard, and the JPA predicate uses ESCAPE '#' for cross-database
portability. Covered by new integration tests in AuditITCase.

@ilgrosso ilgrosso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is proposing to add the capability to search audit events by who, e.g. by the administrator that was logged as the requester for the action that was logged as audit entry.

I believe this is a nice addition but it will require a different issue on JIRA.

This because SYNCOPE-1978 is instead asking to restore the possibility to match audit events by username, e.g. to look for users whose payload was logged for the audit entry - as opposite as the current capability to look for such users only by their key.

}

public AuditEventCriteriaBuilder who(final Set<String> who, final List<Object> parameters) {
if (who != null && !who.isEmpty()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with Spring's CollectionUtils#isEmpty

if (who != null && !who.isEmpty()) {
query.append(andIfNeeded()).append("(");
boolean first = true;
for (String value : who) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this loop be replaced by stream with map and Collectors#joining?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants