diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd index 85b28b97eb61..59175b1f7583 100644 --- a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd @@ -1,5 +1,5 @@ #******************************************************************************* -# Copyright (c) 2024 IBM Corporation and others. +# Copyright (c) 2024, 2025 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 # which accompanies this distribution, and is available at @@ -62,7 +62,11 @@ tested.features=mpTelemetry-2.0,\ pages-3.0,\ jsp-2.3,\ jsp-2.2,\ - el-3.0 + el-3.0,\ + appsecurity-6.0,\ + appsecurity-5.0,\ + appsecurity-4.0,\ + appsecurity-3.0 -buildpath: \ io.openliberty.jakarta.servlet.6.0;version=latest,\ diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java index 46eba07169c8..3f7c0316a336 100644 --- a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2024 IBM Corporation and others. + * Copyright (c) 2024, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.util.Collections; import java.util.concurrent.TimeUnit; import org.jboss.shrinkwrap.api.ShrinkWrap; @@ -32,7 +33,6 @@ import componenttest.annotation.Server; import componenttest.containers.SimpleLogConsumer; import componenttest.custom.junit.runner.FATRunner; -import componenttest.custom.junit.runner.RepeatTestFilter; import componenttest.topology.impl.LibertyServer; import io.openliberty.microprofile.telemetry.internal_fat.shared.TelemetryActions; @@ -44,9 +44,12 @@ public class LoggingServletTest { @Server("TelemetryLogsServer") public static LibertyServer server; + public static final String APP_NAME = "MpTelemetryLogApp"; + public static final String SERVER_XML_MSG_SOURCES = "msgSourceServer.xml"; public static final String SERVER_XML_TRACE_SOURCE = "traceSourceServer.xml"; public static final String SERVER_XML_FFDC_SOURCE = "FFDCSourceServer.xml"; + public static final String SERVER_XML_AUDIT_SOURCE = "auditSourceServer.xml"; private static final String[] EXPECTED_FAILURES = { "CWMOT5005W", "SRVE0315E", "SRVE0777E" }; @@ -193,6 +196,58 @@ public void testFFDCLogs() throws Exception { } } + /* + * Ensures that audit events generated by a Liberty application are bridged over to the OTLP container. + */ + @Test + public void testAuditEventLogs() throws Exception { + assertTrue("The server was not started successfully.", server.isStarted()); + + TestUtils.isContainerStarted("LogsExporter", container); + + RemoteFile messageLogFile = server.getDefaultLogFile(); + setConfig(SERVER_XML_AUDIT_SOURCE, messageLogFile, server); + + // Hit the application to trigger an audit event. + TestUtils.runApp(server, "logs"); + + //Allow time for the collector to receive and bridge logs. + TimeUnit.SECONDS.sleep(WAIT_TIMEOUT); + + final String logs = container.getLogs(); + + // Verify audit event attributes generated by an application's audit event. + assertTrue("Audit type message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.type: Str(liberty_audit)")); + assertTrue("The Audit Event can not be found in the body.", TestUtils.assertLogContains("testAuditEventLogs", logs, "Body: Str(SECURITY_AUTHN)")); + assertTrue("The Audit event name attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.event_name: Str(SECURITY_AUTHN)")); + assertTrue("The Audit observer name attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.observer.name: Str(SecurityService)")); + assertTrue("The Audit observer type URI attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.observer.type_uri: Str(service/server)")); + assertTrue("The Audit outcome attribute can not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.outcome: Str(success)")); + assertTrue("The Audit reason code attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.reason.reason_code: Str(200)")); + assertTrue("The Audit reason type attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.reason.reason_type: Str(HTTP)")); + assertTrue("The Audit target app name attribute can not be found.", TestUtils + .assertLogContains("testAuditEventLogs", logs, + "io.openliberty.audit.target.appname: Str(io.openliberty.microprofile.telemetry.logging.internal.container.fat.MpTelemetryLogApp.LogServlet)")); + assertTrue("The Audit target method attribute can not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.method: Str(GET)")); + assertTrue("The Audit target name attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.name: Str(/MpTelemetryLogApp/LogURL)")); + assertTrue("The Audit target realm attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.realm: Str(defaultRealm)")); + assertTrue("The Audit target type URI attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.type_uri: Str(service/application/web)")); + + // Verify common Logging attributes + assertTrue("SeverityNumber message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "SeverityNumber: Info2(10)")); + assertTrue("Sequence message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.sequence: Str")); + assertTrue("Thread ID message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "thread.id: Int")); + + } + @AfterClass public static void tearDown() throws Exception { //catch if a server is still running. @@ -201,10 +256,10 @@ public static void tearDown() throws Exception { } } - private static String setConfig(String fileName, RemoteFile logFile, LibertyServer server) throws Exception { + private static void setConfig(String fileName, RemoteFile logFile, LibertyServer server) throws Exception { server.setMarkToEndOfLog(logFile); server.setServerConfigurationFile(fileName); - return server.waitForStringInLogUsingMark("CWWKG0017I.*|CWWKG0018I.*"); + server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), new String[] {}); } } diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml new file mode 100644 index 000000000000..e5237df90487 --- /dev/null +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml @@ -0,0 +1,27 @@ + + + + audit-1.0 + mpTelemetry-2.0 + servlet-6.1 + appSecurity-6.0 + + + + + + + + + + + + + + + + + + diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/servers/TelemetryLogsServer/jvm.options b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/servers/TelemetryLogsServer/jvm.options index e69de29bb2d1..9ec5b94cf71a 100644 --- a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/servers/TelemetryLogsServer/jvm.options +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/servers/TelemetryLogsServer/jvm.options @@ -0,0 +1 @@ +-Dcom.ibm.ws.beta.edition=true \ No newline at end of file