1 /*
2 * The contents of this file are subject to the terms of the Common Development and
3 * Distribution License (the License). You may not use this file except in compliance with the
4 * License.
5 *
6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7 * specific language governing permission and limitations under the License.
8 *
9 * When distributing Covered Software, include this CDDL Header Notice in each file and include
10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11 * Header, with the fields enclosed by brackets [] replaced by your own identifying
12 * information: "Portions copyright [year] [name of copyright owner]".
13 *
14 * Copyright 2016 ForgeRock AS.
15 */
16
17 package org.forgerock.audit.handlers.json;
18
19 import com.fasterxml.jackson.annotation.JsonProperty;
20 import com.fasterxml.jackson.annotation.JsonPropertyDescription;
21 import org.forgerock.audit.events.handlers.FileBasedEventHandlerConfiguration;
22
23 /**
24 * Configuration for {@link JsonAuditEventHandler}.
25 */
26 public class JsonAuditEventHandlerConfiguration extends FileBasedEventHandlerConfiguration {
27
28 @JsonProperty(required = true)
29 @JsonPropertyDescription("audit.handlers.json.logDirectory")
30 private String logDirectory;
31
32 @JsonPropertyDescription("audit.handlers.json.elasticsearchCompatible")
33 private boolean elasticsearchCompatible;
34
35 @JsonPropertyDescription("audit.handlers.json.buffering")
36 private EventBufferingConfiguration buffering = new EventBufferingConfiguration();
37
38 /**
39 * Gets the directory where the JSON file is located.
40 *
41 * @return location of the JSON file
42 */
43 public String getLogDirectory() {
44 return logDirectory;
45 }
46
47 /**
48 * Sets the directory where the JSON file is located.
49 *
50 * @param directory location of the JSON file
51 */
52 public void setLogDirectory(final String directory) {
53 logDirectory = directory;
54 }
55
56 /**
57 * Determines if JSON format should be transformed to be compatible with ElasticSearch format restrictions.
58 *
59 * @return {@code true} for ElasticSearch JSON format compatibility enforcement and {@code false} otherwise
60 */
61 public boolean isElasticsearchCompatible() {
62 return elasticsearchCompatible;
63 }
64
65 /**
66 * Specifies if JSON format should be transformed to be compatible with ElasticSearch format restrictions.
67 *
68 * @param elasticsearchCompatible {@code true} for ElasticSearch JSON format compatibility enforcements and
69 * {@code false} otherwise
70 */
71 public void setElasticsearchCompatible(boolean elasticsearchCompatible) {
72 this.elasticsearchCompatible = elasticsearchCompatible;
73 }
74
75 /**
76 * Gets configuration of event buffering.
77 *
78 * @return configuration of event buffering
79 */
80 public EventBufferingConfiguration getBuffering() {
81 return buffering;
82 }
83
84 /**
85 * Sets configuration of event buffering.
86 *
87 * @param buffering configuration of event buffering
88 */
89 public void setBuffering(EventBufferingConfiguration buffering) {
90 this.buffering = buffering;
91 }
92
93 @Override
94 public boolean isUsableForQueries() {
95 return true;
96 }
97
98 /**
99 * Configuration of event buffering.
100 */
101 public static class EventBufferingConfiguration {
102
103 @JsonPropertyDescription("audit.handlers.json.buffering.maxSize")
104 private int maxSize;
105
106 @JsonPropertyDescription("audit.handlers.json.buffering.writeInterval")
107 private String writeInterval;
108
109 /**
110 * Gets the buffer capacity, which are the maximum number of events that can be buffered.
111 *
112 * @return buffer capacity
113 */
114 public int getMaxSize() {
115 return maxSize;
116 }
117
118 /**
119 * Sets the buffer capacity, which are the maximum number of events that can be buffered.
120 *
121 * @param maxSize buffer capacity
122 */
123 public void setMaxSize(int maxSize) {
124 this.maxSize = maxSize;
125 }
126
127 /**
128 * Gets delay after which the file-writer thread is scheduled to run after encountering an empty event buffer
129 * (units of 'ms' are recommended).
130 *
131 * @return Interval (e.g., "20 millis")
132 */
133 public String getWriteInterval() {
134 return writeInterval;
135 }
136
137 /**
138 * Sets delay after which the file-writer thread is scheduled to run after encountering an empty event buffer
139 * (units of 'ms' are recommended).
140 *
141 * @param writeInterval Interval (e.g., "20 millis")
142 */
143 public void setWriteInterval(String writeInterval) {
144 this.writeInterval = writeInterval;
145 }
146 }
147 }