github-advanced-security[bot] commented on code in PR #641: URL: https://github.com/apache/syncope/pull/641#discussion_r1517841192
########## ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java: ########## @@ -227,26 +227,25 @@ protected void customizeDocument(final Map<String, Object> builder, final Realm realm) { } - public Map<String, Object> document( - final long instant, - final JsonNode message, - final String domain) throws IOException { - + public Map<String, Object> document(final AuditEvent auditEvent) throws IOException { Map<String, Object> builder = new HashMap<>(); + builder.put("id", auditEvent.getKey()); + builder.put("opEvent", auditEvent.getOpEvent()); + builder.put("who", auditEvent.getWho()); + builder.put("when", auditEvent.getWhen()); + builder.put("before", auditEvent.getBefore()); + builder.put("inputs", auditEvent.getInputs()); + builder.put("output", auditEvent.getOutput()); + builder.put("throwable", auditEvent.getThrowable()); - builder.put("instant", instant); - builder.put("message", message); - - customizeDocument(builder, instant, message, domain); + customizeDocument(builder, auditEvent); return builder; } protected void customizeDocument( final Map<String, Object> builder, - final long instant, - final JsonNode message, - final String domain) + final AuditEvent auditEvent) Review Comment: ## Useless parameter The parameter 'auditEvent' is never used. [Show more details](https://github.com/apache/syncope/security/code-scanning/1534) ########## core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/AuditEventProcessor.java: ########## @@ -16,31 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.syncope.core.logic.audit; +package org.apache.syncope.core.provisioning.api; -import java.util.Optional; import java.util.Set; -import org.apache.logging.log4j.core.Appender; -import org.apache.logging.log4j.core.appender.rewrite.RewriteAppender; -import org.apache.syncope.common.lib.types.AuditLoggerName; +import org.apache.syncope.common.lib.types.OpEvent; +import org.apache.syncope.core.persistence.api.entity.AuditEvent; -/** - * Basic interface to implement to define a custom audit appender - * - * @see DefaultAuditAppender - * @see DefaultRewriteAuditAppender - */ -public interface AuditAppender { +public interface AuditEventProcessor { - default Set<AuditLoggerName> getEvents() { + default Set<OpEvent> getEvents(String domain) { Review Comment: ## Useless parameter The parameter 'domain' is never used. [Show more details](https://github.com/apache/syncope/security/code-scanning/1531) ########## common/idrepo/lib/src/test/java/org/apache/syncope/common/lib/types/OpEventTest.java: ########## @@ -22,15 +22,14 @@ import org.junit.jupiter.api.Test; -class AuditLoggerNameTest { +class OpEventTest { Review Comment: ## Unused classes and interfaces Unused class: OpEventTest is not referenced within this codebase. If not used as an external API it should be removed. [Show more details](https://github.com/apache/syncope/security/code-scanning/1538) ########## client/idrepo/console/src/main/java/org/apache/syncope/client/console/events/EventCategory.java: ########## @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.events; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.syncope.common.lib.BaseBean; +import org.apache.syncope.common.lib.types.OpEvent; + +public class EventCategory implements BaseBean { + + private static final long serialVersionUID = -4340060002701633401L; + + public static EventCategory from(final OpEvent opEvent) { + EventCategory eventCategory = new EventCategory(opEvent.getType()); + eventCategory.setCategory(opEvent.getCategory()); + eventCategory.setSubcategory(opEvent.getSubcategory()); + eventCategory.getOps().add(opEvent.getOp()); + return eventCategory; + } + + private OpEvent.CategoryType type; + + private String category; + + private String subcategory; + + private final List<String> ops = new ArrayList<>(); + + /** + * Constructor for Type.REST event category. + */ + public EventCategory() { + this(OpEvent.CategoryType.LOGIC); + } + + /** + * Constructor for the given Type event category. + * + * @param type event category type + */ + public EventCategory(final OpEvent.CategoryType type) { + super(); + this.type = type; + } + + public OpEvent.CategoryType getType() { + return type; + } + + public void setType(final OpEvent.CategoryType type) { + this.type = Optional.ofNullable(type).orElse(OpEvent.CategoryType.CUSTOM); + } + + public String getCategory() { + return category; + } + + public void setCategory(final String category) { + this.category = category; + } + + public String getSubcategory() { + return subcategory; + } + + public void setSubcategory(final String subcategory) { + this.subcategory = subcategory; + } + + public List<String> getOps() { Review Comment: ## Exposing internal representation getOps exposes the internal representation stored in field ops. The value may be modified [after this call to getOps](1). getOps exposes the internal representation stored in field ops. The value may be modified [after this call to getOps](2). getOps exposes the internal representation stored in field ops. The value may be modified [after this call to getOps](3). getOps exposes the internal representation stored in field ops. The value may be modified [after this call to getOps](4). getOps exposes the internal representation stored in field ops. The value may be modified [after this call to getOps](5). getOps exposes the internal representation stored in field ops. The value may be modified [after this call to getOps](6). [Show more details](https://github.com/apache/syncope/security/code-scanning/1540) ########## ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchUtils.java: ########## @@ -227,26 +227,25 @@ protected void customizeDocument(final Map<String, Object> builder, final Realm realm) { } - public Map<String, Object> document( - final long instant, - final JsonNode message, - final String domain) throws IOException { - + public Map<String, Object> document(final AuditEvent auditEvent) throws IOException { Map<String, Object> builder = new HashMap<>(); + builder.put("id", auditEvent.getKey()); + builder.put("opEvent", auditEvent.getOpEvent()); + builder.put("who", auditEvent.getWho()); + builder.put("when", auditEvent.getWhen()); + builder.put("before", auditEvent.getBefore()); + builder.put("inputs", auditEvent.getInputs()); + builder.put("output", auditEvent.getOutput()); + builder.put("throwable", auditEvent.getThrowable()); - builder.put("instant", instant); - builder.put("message", message); - - customizeDocument(builder, instant, message, domain); + customizeDocument(builder, auditEvent); return builder; } protected void customizeDocument( final Map<String, Object> builder, - final long instant, - final JsonNode message, - final String domain) + final AuditEvent auditEvent) Review Comment: ## Useless parameter The parameter 'auditEvent' is never used. [Show more details](https://github.com/apache/syncope/security/code-scanning/1536) ########## client/idrepo/console/src/main/java/org/apache/syncope/client/console/audit/AuditHistoryDetails.java: ########## @@ -176,31 +173,33 @@ this.currentEntity = currentEntity; this.type = type; this.category = category; - this.events = events; + this.op = op; this.reference = (Class<T>) currentEntity.getClass(); this.restClient = restClient; setOutputMarkupId(true); - IChoiceRenderer<AuditEntry> choiceRenderer = new IChoiceRenderer<>() { + IChoiceRenderer<AuditEventTO> choiceRenderer = new IChoiceRenderer<>() { private static final long serialVersionUID = -3724971416312135885L; @Override - public String getDisplayValue(final AuditEntry value) { - return SyncopeConsoleSession.get().getDateFormat().format(value.getDate()); + public String getDisplayValue(final AuditEventTO value) { + return SyncopeConsoleSession.get().getDateFormat().format(value.getWhen()); } @Override - public String getIdValue(final AuditEntry value, final int i) { - return Long.toString(value.getDate().toInstant().toEpochMilli()); + public String getIdValue(final AuditEventTO value, final int i) { + return Long.toString(value.getWhen().toInstant().toEpochMilli()); } @Override - public AuditEntry getObject(final String id, final IModel<? extends List<? extends AuditEntry>> choices) { + public AuditEventTO getObject( + final String id, final IModel<? extends List<? extends AuditEventTO>> choices) { + return choices.getObject().stream(). filter(c -> StringUtils.isNotBlank(id) - && Long.parseLong(id) == c.getDate().toInstant().toEpochMilli()). + && Long.parseLong(id) == c.getWhen().toInstant().toEpochMilli()). Review Comment: ## Missing catch of NumberFormatException Potential uncaught 'java.lang.NumberFormatException'. [Show more details](https://github.com/apache/syncope/security/code-scanning/1537) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@syncope.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org