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 package org.forgerock.audit.handlers.splunk;
17
18 import org.forgerock.audit.events.handlers.EventHandlerConfiguration;
19
20 import com.fasterxml.jackson.annotation.JsonPropertyDescription;
21
22 /**
23 * Configuration for the splunk audit event handler.
24 */
25 public final class SplunkAuditEventHandlerConfiguration extends EventHandlerConfiguration {
26
27 @JsonPropertyDescription("audit.handlers.splunk.connection")
28 private ConnectionConfiguration connection = new ConnectionConfiguration();
29
30 @JsonPropertyDescription("audit.handlers.splunk.buffering")
31 private BufferingConfiguration buffering = new BufferingConfiguration();
32
33 @JsonPropertyDescription("audit.handlers.splunk.authzToken")
34 private String authzToken;
35
36 /**
37 * Gets the configuration for buffering.
38 *
39 * @return the buffering configuration
40 */
41 public BufferingConfiguration getBuffering() {
42 return buffering;
43 }
44
45 /**
46 * Sets the configuration for buffering.
47 *
48 * @param buffering
49 * the buffering configuration
50 */
51 public void setBuffering(final BufferingConfiguration buffering) {
52 this.buffering = buffering;
53 }
54
55 /**
56 * Gets configuration of connection to Splunk.
57 *
58 * @return configuration of connection to Splunk
59 */
60 public ConnectionConfiguration getConnection() {
61 return connection;
62 }
63
64 /**
65 * Sets configuration of connection to Splunk.
66 *
67 * @param connection
68 * configuration of connection to Splunk
69 */
70 public void setConnection(final ConnectionConfiguration connection) {
71 this.connection = connection;
72 }
73
74 /**
75 * Gets the Splunk authorization token required for making HTTP event collector calls.
76 *
77 * @return the Splunk authorization token
78 */
79 public String getAuthzToken() {
80 return authzToken;
81 }
82
83 /**
84 * Sets the Splunk authorization token required for making HTTP event collector calls.
85 *
86 * @param authzToken
87 * the Splunk authorization token
88 */
89 public void setAuthzToken(final String authzToken) {
90 this.authzToken = authzToken;
91 }
92
93 @Override
94 public boolean isUsableForQueries() {
95 return false;
96 }
97
98 /**
99 * Configuration of connection to Splunk.
100 */
101 public final static class ConnectionConfiguration {
102
103 // Splunk's default host in a development environment.
104 private static final String DEFAULT_HOST = "localhost";
105
106 // Splunk's default HTTP event collector port in a development environment.
107 private static final int DEFAULT_PORT = 8088;
108
109 @JsonPropertyDescription("audit.handlers.splunk.connection.useSSL")
110 private boolean useSSL;
111
112 @JsonPropertyDescription("audit.handlers.splunk.connection.host")
113 private String host;
114
115 @JsonPropertyDescription("audit.handlers.splunk.connection.port")
116 private int port;
117
118 /**
119 * Indicates if the connection uses SSL.
120 *
121 * @return {@code true} when the connection uses SSL.
122 */
123 public boolean isUseSSL() {
124 return useSSL;
125 }
126
127 /**
128 * Sets the use of a SSL connection.
129 *
130 * @param useSSL
131 * {@code true} when the connection uses SSL.
132 */
133 public void setUseSSL(final boolean useSSL) {
134 this.useSSL = useSSL;
135 }
136
137 /**
138 * Gets the {@code host} for the connection (default {@code localhost}).
139 *
140 * @return The {@code host} for the connection.
141 */
142 public String getHost() {
143 return host != null && !host.isEmpty() ? host : DEFAULT_HOST;
144 }
145
146 /**
147 * Sets the {@code host} for the connection.
148 *
149 * @param host
150 * The {@code host} for the connection.
151 */
152 public void setHost(final String host) {
153 this.host = host;
154 }
155
156 /**
157 * Gets the {@code port} for the connection (default {@code 8088}).
158 *
159 * @return The {@code port} for the connection.
160 */
161 public int getPort() {
162 return port > 0 ? port : DEFAULT_PORT;
163 }
164
165 /**
166 * Sets the {@code port} for the connection.
167 *
168 * @param port
169 * The {@code port} for the connection.
170 */
171 public void setPort(final int port) {
172 this.port = port;
173 }
174
175 }
176
177 /**
178 * Configuration of event buffering.
179 */
180 public final static class BufferingConfiguration {
181
182 @JsonPropertyDescription("audit.handlers.splunk.buffering.maxSize")
183 private int maxSize;
184
185 @JsonPropertyDescription("audit.handlers.splunk.buffering.writeInterval")
186 private String writeInterval;
187
188 @JsonPropertyDescription("audit.handlers.splunk.buffering.maxBatchedEvents")
189 private int maxBatchedEvents;
190
191 /**
192 * Gets the buffer capacity, which are the maximum number of events that can be buffered.
193 *
194 * @return buffer capacity
195 */
196 public int getMaxSize() {
197 return maxSize;
198 }
199
200 /**
201 * Sets the buffer capacity, which are the maximum number of events that can be buffered.
202 *
203 * @param maxSize
204 * buffer capacity
205 */
206 public void setMaxSize(final int maxSize) {
207 this.maxSize = maxSize;
208 }
209
210 /**
211 * Gets the interval for reading events from the buffer to transmit to splunk.
212 *
213 * @return Interval (e.g., "20 millis")
214 */
215 public String getWriteInterval() {
216 return writeInterval;
217 }
218
219 /**
220 * Sets the interval for reading events from the buffer to transmit to splunk.
221 *
222 * @param writeInterval
223 * Interval (e.g., "20 millis")
224 */
225 public void setWriteInterval(final String writeInterval) {
226 this.writeInterval = writeInterval;
227 }
228
229 /**
230 * Gets the maximum number of events to read from the buffer on each {@link #getWriteInterval() interval}.
231 *
232 * @return Batch size
233 */
234 public int getMaxBatchedEvents() {
235 return maxBatchedEvents;
236 }
237
238 /**
239 * Sets the maximum number of events to read from the buffer on each {@link #getWriteInterval() interval}.
240 *
241 * @param maxBatchedEvents
242 * Batch size
243 */
244 public void setMaxBatchedEvents(final int maxBatchedEvents) {
245 this.maxBatchedEvents = maxBatchedEvents;
246 }
247 }
248
249 }