forked from OpenIdentityPlatform/OpenAM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e3cad2
commit 0c8f9d7
Showing
7 changed files
with
247 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...n/java/org/forgerock/openam/audit/events/handlers/JsonStdoutAuditEventHandlerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* The contents of this file are subject to the terms of the Common Development and | ||
* Distribution License (the License). You may not use this file except in compliance with the | ||
* License. | ||
* | ||
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the | ||
* specific language governing permission and limitations under the License. | ||
* | ||
* When distributing Covered Software, include this CDDL Header Notice in each file and include | ||
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL | ||
* Header, with the fields enclosed by brackets [] replaced by your own identifying | ||
* information: "Portions copyright [year] [name of copyright owner]". | ||
* | ||
* Copyright 2023 3A Systems LLC | ||
*/ | ||
|
||
package org.forgerock.openam.audit.events.handlers; | ||
|
||
import org.forgerock.audit.AuditException; | ||
import org.forgerock.audit.events.handlers.AuditEventHandler; | ||
import org.forgerock.audit.handlers.json.JsonStdoutAuditEventHandler; | ||
import org.forgerock.audit.handlers.json.JsonStdoutAuditEventHandlerConfiguration; | ||
import org.forgerock.openam.audit.AuditEventHandlerFactory; | ||
import org.forgerock.openam.audit.configuration.AuditEventHandlerConfiguration; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static com.sun.identity.shared.datastruct.CollectionHelper.getBooleanMapAttr; | ||
|
||
public class JsonStdoutAuditEventHandlerFactory implements AuditEventHandlerFactory { | ||
|
||
@Override | ||
public AuditEventHandler create(AuditEventHandlerConfiguration configuration) throws AuditException { | ||
Map<String, Set<String>> attributes = configuration.getAttributes(); | ||
|
||
JsonStdoutAuditEventHandlerConfiguration handlerConfig = new JsonStdoutAuditEventHandlerConfiguration(); | ||
handlerConfig.setTopics(attributes.get("topics")); | ||
handlerConfig.setName(configuration.getHandlerName()); | ||
handlerConfig.setEnabled(getBooleanMapAttr(attributes, "enabled", false)); | ||
handlerConfig.setElasticsearchCompatible(getBooleanMapAttr(attributes, "elasticsearchCompatible", false)); | ||
return new JsonStdoutAuditEventHandler(handlerConfig, configuration.getEventTopicsMetaData()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
openam-audit/openam-audit-configuration/src/main/resources/JSONStdout.section.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# The contents of this file are subject to the terms of the Common Development and | ||
# Distribution License (the License). You may not use this file except in compliance with the | ||
# License. | ||
# | ||
# You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the | ||
# specific language governing permission and limitations under the License. | ||
# | ||
# When distributing Covered Software, include this CDDL Header Notice in each file and include | ||
# the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL | ||
# Header, with the fields enclosed by brackets [] replaced by your own identifying | ||
# information: "Portions copyright [year] [name of copyright owner]". | ||
# | ||
# Copyright 2016 ForgeRock AS. | ||
# Portions copyright 2023 3A Systems LLC | ||
# | ||
|
||
######################################################################################################################## | ||
# Common handler section properties | ||
######################################################################################################################## | ||
commonHandler=enabled | ||
commonHandler=topics | ||
|
||
######################################################################################################################## | ||
# Common handler plugin section properties | ||
######################################################################################################################## | ||
commonHandlerPlugin=handlerFactory | ||
|
||
######################################################################################################################## | ||
# JMS handler section properties | ||
######################################################################################################################## | ||
jsonStdoutConfig=elasticsearchCompatible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...va/org/forgerock/openam/audit/events/handlers/JsonStdoutAuditEventHandlerFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* The contents of this file are subject to the terms of the Common Development and | ||
* Distribution License (the License). You may not use this file except in compliance with the | ||
* License. | ||
* | ||
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the | ||
* specific language governing permission and limitations under the License. | ||
* | ||
* When distributing Covered Software, include this CDDL Header Notice in each file and include | ||
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL | ||
* Header, with the fields enclosed by brackets [] replaced by your own identifying | ||
* information: "Portions copyright [year] [name of copyright owner]". | ||
* | ||
* Copyright 2023 3A Systems LLC | ||
*/ | ||
package org.forgerock.openam.audit.events.handlers; | ||
|
||
import org.forgerock.audit.AuditException; | ||
import org.forgerock.audit.events.EventTopicsMetaData; | ||
import org.forgerock.audit.events.EventTopicsMetaDataBuilder; | ||
import org.forgerock.audit.events.handlers.AuditEventHandler; | ||
import org.forgerock.audit.handlers.json.JsonStdoutAuditEventHandler; | ||
import org.forgerock.openam.audit.AuditEventHandlerFactory; | ||
import org.forgerock.openam.audit.configuration.AuditEventHandlerConfiguration; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static java.util.Collections.singleton; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Test the JsonStdoutAuditEventHandlerFactoryTest class. | ||
* | ||
* @since 14.8.3 | ||
*/ | ||
public class JsonStdoutAuditEventHandlerFactoryTest { | ||
|
||
private AuditEventHandlerFactory factory; | ||
private EventTopicsMetaData eventTopicsMetaData; | ||
private Map<String, Set<String>> configAttributes; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
factory = new JsonStdoutAuditEventHandlerFactory(); | ||
eventTopicsMetaData = EventTopicsMetaDataBuilder.coreTopicSchemas().build(); | ||
|
||
configAttributes = new HashMap<>(); | ||
configAttributes.put("enabled", singleton("true")); | ||
configAttributes.put("topics", singleton("access")); | ||
configAttributes.put("elasticsearchCompatible", singleton("true")); | ||
} | ||
|
||
@Test | ||
void shouldCreateJsonStdoutEventHandler() throws AuditException { | ||
AuditEventHandlerConfiguration configuration = AuditEventHandlerConfiguration.builder() | ||
.withName("JSONStdout") | ||
.withAttributes(configAttributes) | ||
.withEventTopicsMetaData(eventTopicsMetaData).build(); | ||
|
||
AuditEventHandler handler = factory.create(configuration); | ||
|
||
assertThat(handler).isInstanceOf(JsonStdoutAuditEventHandler.class); | ||
assertThat(handler.getName()).isEqualTo("JSONStdout"); | ||
assertThat(handler.getHandledTopics()).containsExactly("access"); | ||
assertThat(handler.isEnabled()).isTrue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters